Wikia

WoWWiki

Watchlist Recent changes

A Wikia Contributor

aka 38.107.179.218


(Redirected from Krellmax) |
3
User talk:Krellmax

Hi! I'm a Mod author and Wiki fanatic. So naturally, this place is perfect for me!

I'm going to make this my dumping ground for my often-used script functions. One day I may make this into a library, but until then, I hope they help somebody. Be sure to namespace them if you use any of them (e.g. MYMOD_foo).

Note:

SHOWERRORS is a boolean to turn on or off (possibly) annoying error messages.
MODNAME is the name of the mod (e.g. "FriendNotifierPlus").

Contents

Chat Functions Edit

 function ChatMessage(msg)

   if (msg == nil) then
     msg = 'nil';
   end

   if (DEFAULT_CHAT_FRAME) then
     DEFAULT_CHAT_FRAME:AddMessage(msg);
   elseif (SHOWERRORS) then
     message(MODNAME .. " is unable to display a message in your general chat window (DEFAULT_CHAT_FRAME)!\n" .. msg);
   end

 end
 function CombatMessage(msg)

   if (msg == nil) then
     msg = 'nil';
   end

   if (ChatFrame2) then
     ChatFrame2:AddMessage(msg);
   elseif (SHOWERRORS) then 
     message(MODNAME .. " is unable to display a message in your combat chat window (ChatFrame2)!\n" .. msg);
   end
    
 end
 function WindowMessage(window, msg)
 
   local chatFrame = GetChatFrameByName(window);
   if (chatFrame) then
     chatFrame:AddMessage(msg);
   elseif (SHOWERRORS) then 
     message(MODNAME .. " is unable to display a message in window '" .. window .. "'!\n" .. msg);
   end
 
 end

Edit

 function BannerMessage(msg, timeout)
 
   if (msg == nil) then
     msg = 'nil';
   end
 
   if (timeout == nil) then
     timeout = 2.0; -- message will fade after this many seconds
   end
   
   if (UIErrorsFrame) then
     local r = 1.0;  -- red
     local g = 1.0;  -- green
     local b = 1.0;  -- blue
     local alpha = 1.0; -- transparency
     UIErrorsFrame:AddMessage(msg,r,g,b,alpha,timeout);
   elseif (SHOWERRORS) then 
     message(MODNAME .. " is unable to show a message in your banner display area!\n" .. msg); end
   end
   
 end

Print Functions Edit

 function Print(msg)
 
   ChatMessage(MODNAME .. ": " .. msg);
   
 end  
 function Debug(msg)
 
   if (DEBUG) then
     ChatMessage(MODNAME .. " DEBUG: " .. msg);
   end 
   
 end

Boolean String Functions Edit

 function BoolToStr(bool)
 
   if (bool) then
     return "true";
   else
     return "false";
   end
 
 end  
 function BoolToYesNoStr(bool)
 
   if (bool) then
     return "yes";
   else
     return "no";
   end
 
 end
 function BoolToOnOffStr(bool)
 
   if (bool) then
     return "on";
   else
     return "off";
   end
 
 end
 function BoolToEnabledDisabledStr(bool)
 
   if (bool) then
     return "enabled";
   else
     return "disabled";
   end
 
 end

Chat Windows (aka Chat Frames) Edit

 function GetChatFrameByName(name)
 
   if (name == "General") then
     return DEFAULT_CHAT_FRAME;
   end
 
   if (name == "Combat Log") then
     return ChatFrame2;
   end
 
   for i=1,NUM_CHAT_WINDOWS do
     local windowName = GetChatWindowInfo(i);
     if (windowName == name) then
       return getglobal("ChatFrame" .. i)
     end
   end
   
   return nil;
   
 end

Chat Channels Edit

WARNING! This function does not yet work, it's a work-in-progress!

 function ChannelExists(channel)
 
   -- Experimental - not sure if this really works!
   local id, name = GetChannelName(channel);
   return (id ~= 0 or name ~= nil);
 
 end

Player Functions Edit

 function GetPlayerName()
 
   local playerName = UnitName("player");
   
   if ((not playerName) or (playerName == UNKNOWNOBJECT)) then
     playerName = "UNKNOWN";
   end
 
   return playerName;
 
 end
 function IsPlayerManaClass()
 
   local manaClass = true;
   
   local localizedClass, englishClass = UnitClass("player");
   
   if (englishClass == "DRUID") then
     -- Check for Druid in shapeshifted form...
     local numberOfShapes = GetNumShapeshiftForms();
     for i=1,numberOfShapes do
       icon, name, active = GetShapeshiftFormInfo(i);
       if (active == 1) then
         manaClass = false;
         break;
       end
     end
   elseif ((englishClass == "WARRIOR") or (englishClass == "ROGUE")) then
     manaClass = false;
   end
   
   return manaClass;
 
 end

Not sure how this is used, I copied it from somewhere. When I figure it out, I'll update it.

 function IsInCombat(eventType)
 
   local unit;
 
   if (string.lower(eventType) == "pethealth") then
     unit = "pet";
   else
     unit = "player";
   end
 
   if (UnitAffectingCombat(unit) == 1) then
     return true;
   else
     return false;
   end
   
 end

Realm Functions Edit

 function GetRealmName()
 
   local realmName = GetCVar("RealmName");
   
   if (realmName == nil) then
     realmName = "UNKNOWN";
   end
   
   return realmName;
   
 end

Trinket Functions Edit

 function TrinketIsReady(name)
 
   local trinketSlot = KGetTrinketSlotByName(name);
 
   if (trinketSlot == nil) then
     if (SHOWERRORS) then message("Trinket not found!"); end
     return false;
   end
 
   if (GetInventoryItemCooldown("player", trinketSlot) == 0) then
     return true;
   else
     return false;
   end 
 
 end
 function UseTrinket(name)
 
   local trinketSlot = KGetTrinketSlotByName(name);
 
   UseInventoryItem(trinketSlot);
 
 end
 function GetTrinketSlotByName(name)
 
   local trinket0 =  GetInventoryItemLink("player", GetInventorySlotInfo("Trinket0Slot"))
   local trinket1 =  GetInventoryItemLink("player", GetInventorySlotInfo("Trinket1Slot"))
 
   if (trinket0 == nil) then trinket0 = "empty" end
   if (trinket1 == nil) then trinket1 = "empty" end
 
   local trinketSlot;
 
   if (string.find(trinket0, name) ~= nil) then
     trinketSlot = GetInventorySlotInfo("Trinket0Slot");
   elseif (string.find(trinket1, name) ~= nil) then
     trinketSlot = GetInventorySlotInfo("Trinket1Slot");
   else
     trinketSlot = nil;
   end
 
   return trinketSlot;
 
 end



Krellmax

Around Wikia's network

Random Wiki