User:Smelladin/LUA snippets

I'll put LUA and macro snippets that I may or may not incorporate in articles here :)

=Macros=

Summon a random small pet/critter
/run CallCompanion("CRITTER",math.random(1, GetNumCompanions("CRITTER"));

Summon a random mount
/run CallCompanion("MOUNT",math.random(1, GetNumCompanions("MOUNT")); Note: This macro doesn't care about mount type, it will attempt to summon any random mount in your collection, be it 60%/100% ground mount, or 60%/280% flying mount.

Guild recruitment
/run id,name=GetChannelName("Trade - City");SendChatMessage("Your message here!", "CHANNEL", nil, id); Sends a guild recruitment message to trade IF it's available.

Netherwing friend
/run n,s,m,y,v=GetWatchedFactionInfo;x=GetItemCount("Netherwing Egg"); /run DEFAULT_CHAT_FRAME:AddMessage("You have:\n"..x.."x Netherwing Egg(s) ("..(x*250).." rep). "..floor(((y-v)/250)+.5).." eggs to next lvl ("..y-v.." more rep).") If Netherwing is the watched faction (it must be, or this macro will show faulty information), prints out how many eggs you have, how many reputation points they give, how many you need to hand in to reach the next reputation level, and finally, how much reputation you need to reach the next level. (233 characters).

Drums of War
&#35;showtooltip item:29528

/run iN,iL=GetItemInfo(29528);iC=GetItemCount(29528, nil, true);msg=">"..iL.."! T-30s! ("..iC.." charge(s) left)<";DEFAULT_CHAT_FRAME:AddMessage(msg);SendChatMessage(msg,"PARTY");

/use Drums of War

/in 30 /p >Drums faded!<

Feel free to edit the three itemIds to use for other drums (highlighted in Bold text above). Output:

> [Drums of War] ! T-30s! (44 charge(s) left)<

[Party][Shæmmi]: > [Drums of War] ! T-30s! (44 charge(s) left)<

(30 seconds later):

[Party][Shæmmi]: >Drums Faded!<

=LUA snippets=

XP Gains
This will show a message on each XP gain (mobs/quests), containing how much XP you earned, and how many equal gains you need until next level. Got the idea from Fizzwidget FactionFriend, which has similar functionality, only with Reputation Points instead of XP.

Put this in the OnLoad function of your script: this:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN");

Put this in the event handler that handles CHAT_MSG_COMBAT_XP_GAIN:

local xpgained = arg1:match("(%d+) experience"); local xptolvl = UnitXPMax("player") - UnitXP("player"); DEFAULT_CHAT_FRAME:AddMessage(xpgained.." XP gained, "..floor(xptolvl/xpgained).." equal gains to next level.");

Achievement notification for party
When I play, I often play in a party with friends, who're not at the same location as myself. This script will send an 'Achievement Earned' message to your party, similar to the automatic guild notification.

Put this in the OnLoad function of your script: this:RegisterEvent("ACHIEVEMENT_EARNED");

Put this in the event handler that handles ACHIEVEMENT_EARNED: achid = arg1; achlink = GetAchievementLink(achid); msg = UnitName("player").." just earned the achievement " .. achlink .. "!"; SendChatMessage(msg, "PARTY");