Well, i have made this extremely useless AddOn for one of my friends.
but it needs to have a list randomly sorted on each call.
let me explain.
This friend of mine has until now 6 different Epic Mounts, and he wanted me to make him an addon which randomly mounts him to one those mounts and unmounts him if mounted.
The basic funtionality is working (mounting/unmounting) but for the randomness i need some support, I'll post the source here and i bet most of you is going to hate my style and that sloppy coding technique of me, but i would be glad if u can just ignore it and give me a hint on hoe to sort
"MountList" randomly.
local currentBuffTexture;
local regularMount;
local numSlots;
MountList={
"Schwarzer Kriegstiger",
"Schwarzer Kriegswidder",
"Schwarzea Schlachtrosszaumzeug",
"Schwarzer Schlachtenschreiter",
"Stormpike-Streitross",
--"Fliegendes Schaf",
}
--neues Mount einfach Fliegendes Schaf mit den korrekten Namen des Mounts ersetzen.
function randmount_unmount()
nothing = 0;
regularMount = "_mount_";
for i=0,15,1 do
currentBuffTexture = GetPlayerBuffTexture(i);
if (currentBuffTexture and (string.find(string.lower(currentBuffTexture), regularMount))) then
CancelPlayerBuff(i);
else
for j=0, NUM_BAG_FRAMES, 1 do
numSlots = GetContainerNumSlots(j);
for k=0,numSlots, 1 do
if (GetContainerItemLink(j,k) ~= nil) then
link = GetContainerItemLink(j,k);
for l, m in MountList do
if (m == randmount_GetItemNameFromLink(link)) then
UseContainerItem(j,k);
return j;
end
end
end
end
end
end
end
end
function randmount_GetItemNameFromLink(link)
local name;
if( not link ) then
return nil;
end
for name in string.gfind(link, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%[(.-)%]|h|r") do
return name;
end
return nil;
end
function randmount_onload()
SLASH_RANDMOUNT1="/rm";
SLASH_RANDMOUNT2="/randmount";
SlashCmdList["RANDMOUNT"]=function(msg)
if (string.lower(msg)=="do") then
randmount_unmount();
elseif (string.lower(msg)=="list") then
DEFAULT_CHAT_FRAME:AddMessage("Mounts currently in List:", 1, 1, 1);
for l, m in MountList do
DEFAULT_CHAT_FRAME:AddMessage(m, 0, 1, 0);
end
else
DEFAULT_CHAT_FRAME:AddMessage("Usage: '/rm do' in a macro to make u mount or unmount a random mount from the '/rm list'", 0, 1, 0);
end
end
end
function MountMe:MountUp()
local m = MountMe:GetRandomMount();
if (m) then UseContainerItem(m[1],m[2]) end
end
function MountMe:GetRandomMount()
local mounts = MountMe:GetMountList();
if (mounts) then return mounts[math.random(table.getn(mounts))] end
end
function MountMe:GetMountList()
-- Scans bags, returns a table with all the mount's bag/slot pairs
end
I demand you name it MountMe! Also if you use itemlinks instead of tekt names it'll be much easier to localize :) Pally/Warlock mounts are a tad diff to handle too... hrm... Anywho please share what you come up with, I'll likely Ace & localize it if you don't :)
to be honest i Beg one of u to clean that crap of copied code up and ace it.
I'll need to look into ur code to get the idea of how u do it but i'll assume it'll work out somehow.
I'd be happy to try to write up an Ace version, I'm working on Aceing EZDismount currently. Would be handy if someone had a list of the mount itemlinks and speeds so I didn't have to go looking em all up on alla ^^
ok randomness implemented, well it worked for me (i only possess 2 mounts and i chose one of them randomly so I assume it works)
Ur Idea with the itemlinks is godd, but it's rather hard to get legal links for very rare mounts (deathcharger, Razzashi Raptor, etc.)
and u cannot cope Spellmounts (Charger, Dreadsteed) with those so i decided to stay with a list
I haven't tested Paladin and Warlock yet.
One Big Problem i have what about the German Umlaute äöü and the ß there are those substittutions \123\321 u know what I am talking about, well what about the striped name from the link?
I'm kinda unable to figure out how to handle this problem
local currentBuffTexture;
local regularMount;
local numSlots;
MountList={
"Schwarzer Kriegstiger",
"Schwarzer Kriegswidder",
"Schwarzes Schlachtrosszaumzeug",
"Schwarzer Schlachtenschreiter",
"Stormpike-Streitross",
"Reins of the Swift Frostsaber",
"Reins of the Striped Frostsaber",
"Summon Dreadsteed",
"Summon Charger",
--"Fliegendes Schaf",
}
--neues Mount einfach Fliegendes Schaf mit den korrekten Namen des Mounts ersetzen.
function randmount_unmount()
nothing = 0;
regularMount = "_mount_";
for i=0,15,1 do
currentBuffTexture = GetPlayerBuffTexture(i);
if (currentBuffTexture and (string.find(string.lower(currentBuffTexture), regularMount))) then
CancelPlayerBuff(i);
else
for j=0, NUM_BAG_FRAMES, 1 do
numSlots = GetContainerNumSlots(j);
for k=0,numSlots, 1 do
if (GetContainerItemLink(j,k) ~= nil) then
link = GetContainerItemLink(j,k);
temp_random = randmount_randomize()
if (temp_random == randmount_GetItemNameFromLink(link)) then
UseContainerItem(j,k);
return j;
elseif (string.find(temp_random, "Summon")) then
if (UnitClass("player") == "Hexenmeister") then
CastSpellByName('Summon Dreadsteed(Summon)');
elseif (UnitClass("player") == "Paladin") then
CastSpellByName('Summon Charger(Summon)');
return j;
end
end
end
end
end
end
end
end
function randmount_randomize()
return MountList[math.random(table.getn(MountList))]
end
function randmount_GetItemNameFromLink(link)
local name;
if( not link ) then
return nil;
end
for name in string.gfind(link, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%[(.-)%]|h|r") do
return name;
end
return nil;
end
function randmount_onload()
SLASH_RANDMOUNT1="/rm";
SLASH_RANDMOUNT2="/randmount";
SlashCmdList["RANDMOUNT"]=function(msg)
if (string.lower(msg)=="do") then
randmount_unmount();
elseif (string.lower(msg)=="list") then
DEFAULT_CHAT_FRAME:AddMessage("Mounts currently in List:", 1, 1, 1);
for l, m in MountList do
DEFAULT_CHAT_FRAME:AddMessage(m, 0, 1, 0);
end
else
DEFAULT_CHAT_FRAME:AddMessage("Usage: '/rm do' in a macro to make u mount or unmount a random mount from the '/rm list'", 0, 1, 0);
end
end
end
ok randomness implemented, well it worked for me (i only possess 2 mounts and i chose one of them randomly so I assume it works)
Ur Idea with the itemlinks is godd, but it's rather hard to get legal links for very rare mounts (deathcharger, Razzashi Raptor, etc.)
and u cannot cope Spellmounts (Charger, Dreadsteed) with those so i decided to stay with a list
Lesser known fact, if you know where to look *coughURLcough* you can find the itemID for any item listed on alla, and I think the same goes for Thott tho I havn't checked.
Handling the spell mounts will be a tad more difficult, yes. One also needs to take into consideration those of us who are not yet 60, we might have multimenuts as well. Ideally the mod should also handle the travel forms of various classes.
I'm all for making a mount mod here shortly, as soon as I get my dismount mod Ace'd. However it is our 5th aniv so I shouldn't be spending the weekend coding :P
Just the fact that someone has 6 mounts to call upon disgusts me. Actually, I'm jealous as hell that someone could afford such a feat, so I lash out with anger instead of admitting my own suck-ness as a gold farmer. LOL :lol:
That is amazing! And the fact that an addon has been written for this situation is equally amazing! Great job! :lol:
Thank you Kayde, but having 6 mounts is not that much of a problem, because what else you have to do?
My friend plays a Gnome Warlock Tailor/Enchanter, he possesses all (except +5dmg on one-handed weapons) enchanting formulas and almost all tailoring recipes.
So he decided to play to rank 11 and buy all PvP Mounts (4 in numbers) he has of course max reputation with all alliance fractions including Stormpike and League of Arathor, so we have an Epic Warlock Mount 4 PvP Mounts and a Stormpike Battle Charger. And now I really think boredom is on hand.
With the ItemID's I'm kinda tanny cuz of the fact I got my butt kicked everytime I try to post a legendary item with KC_Items. I know that It's very different in this case.
I'm just me and I'm a lazy bum :-D
So if anyone of you wants to take this little project of mine to ACE he has my permission, but know It's not all my ideas, it's partly copied from other mounting AddOns (EzDismount, Dismount and Simplemount)
so beware the copyleft/copyright
Lazy, I hear ya... why you think AceOff's taking so long ^^ I blame my new printer/scanner/fax toy :P
And yea, AceOff is basically EZDismount, I'd stolen it's code, stirpped it down, and dropped it in my personal ConglomoMod sometimes back. Now I'm pulling it out and whipping it's Ace.... slowly... whenever I feel like coding... oh shiney! *runs off*
while talking about,
what about the Problem with the german Umlauts i have?
As u can see i put something into the code to enable random mount summoning for WLs and Palas, in english i don't see much of a problem, but in german the spells are:
"Schreckensross beschwören" and "Streitross beschwören" (well at last i think it's the right name of the mount)
so so i need to encode the ö in the list? And what about the string.find() on that?
With this i am in desperate need of help.
This part of the code is not just stupid it's also not working, i know but the origin of the problem is above
elseif (string.find(temp_random, "Summon")) then
if (UnitClass("player") == "Hexenmeister") then
CastSpellByName('Summon Dreadsteed(Summon)');
elseif (UnitClass("player") == "Paladin") then
CastSpellByName('Summon Charger(Summon)');
For personal use this would work fine. But to actually publish this mod you would need a table with a listing of every mount in the game which would be quite large. The alternative is to scan the tooltips of each inventory item instead of just the name.
You would simply need to translate a single line for each language (2 if you also want the AQ mounts)
function SlotIsMount(bag, slot)
GameTooltip:ClearLines()
GameTooltip:SetBagItem(bag, slot)
local text
for i = 1, 30 do
text = getglobal("GameTooltipTextLeft" .. i):GetText()
if text and string.find(text, "Use: Summons and dismisses a rideable ") then
return true
elseif text and string.find(text, "Use: Emits a high frequency sound, forcing a silithid tank") then
return true
end
end
end
Alt, look at MountMe, the list of mounts isn't as larges as you'd think, if you do it right :) Tooltip scanning can be expensive too... and all those getglobal calls.. .bleh.
Look at how I do this in mountme/PeriodicTable, it's quite simple really. As for tooltip scanning, check out my GratuityLib, it makes tip scanning a lot simpler.
I never really thought about how taxing getglobal was. Would it be faster to put all the globals you are going to scan in a table that would be built within an OnLoad function?
I was thinking more of another addon I have written and it calls getglobal 30 times OnUpdate. Would it be faster to define all 30 of those to a table and simply retrieve 30 table values?
While we are talking about efficiency I was wondering if it was faster to run a check or a simple function. Mainly I was wondering about the Show() and Hide() functions. To keep a frame hidden would it be faster to check IsVisible() or to simply Hide() it regardless?
Yea, you should keep getglabal calls to a minimum. Storing to a local variable often works well (that's what Gratuity does).
As for testing performance, you just need to test it yourself in game.
local mem,time = gcinfo(), GetTime()
for i=1,10000 do -- you can change 10000 to whatever works best for you
-- your test code goes here
end
print(gcinfo() - mem, GetTime() - time)
compare numbers between your two functions, the smaller one is, of course, better :)
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
but it needs to have a list randomly sorted on each call.
let me explain.
This friend of mine has until now 6 different Epic Mounts, and he wanted me to make him an addon which randomly mounts him to one those mounts and unmounts him if mounted.
The basic funtionality is working (mounting/unmounting) but for the randomness i need some support, I'll post the source here and i bet most of you is going to hate my style and that sloppy coding technique of me, but i would be glad if u can just ignore it and give me a hint on hoe to sort
"MountList" randomly.
Thanks in advance
I demand you name it MountMe! Also if you use itemlinks instead of tekt names it'll be much easier to localize :) Pally/Warlock mounts are a tad diff to handle too... hrm... Anywho please share what you come up with, I'll likely Ace & localize it if you don't :)
I'll need to look into ur code to get the idea of how u do it but i'll assume it'll work out somehow.
I'd be happy to try to write up an Ace version, I'm working on Aceing EZDismount currently. Would be handy if someone had a list of the mount itemlinks and speeds so I didn't have to go looking em all up on alla ^^
Ur Idea with the itemlinks is godd, but it's rather hard to get legal links for very rare mounts (deathcharger, Razzashi Raptor, etc.)
and u cannot cope Spellmounts (Charger, Dreadsteed) with those so i decided to stay with a list
I haven't tested Paladin and Warlock yet.
One Big Problem i have what about the German Umlaute äöü and the ß there are those substittutions \123\321 u know what I am talking about, well what about the striped name from the link?
I'm kinda unable to figure out how to handle this problem
Lesser known fact, if you know where to look *coughURLcough* you can find the itemID for any item listed on alla, and I think the same goes for Thott tho I havn't checked.
Handling the spell mounts will be a tad more difficult, yes. One also needs to take into consideration those of us who are not yet 60, we might have multimenuts as well. Ideally the mod should also handle the travel forms of various classes.
I'm all for making a mount mod here shortly, as soon as I get my dismount mod Ace'd. However it is our 5th aniv so I shouldn't be spending the weekend coding :P
That is amazing! And the fact that an addon has been written for this situation is equally amazing! Great job! :lol:
My friend plays a Gnome Warlock Tailor/Enchanter, he possesses all (except +5dmg on one-handed weapons) enchanting formulas and almost all tailoring recipes.
So he decided to play to rank 11 and buy all PvP Mounts (4 in numbers) he has of course max reputation with all alliance fractions including Stormpike and League of Arathor, so we have an Epic Warlock Mount 4 PvP Mounts and a Stormpike Battle Charger. And now I really think boredom is on hand.
With the ItemID's I'm kinda tanny cuz of the fact I got my butt kicked everytime I try to post a legendary item with KC_Items. I know that It's very different in this case.
I'm just me and I'm a lazy bum :-D
So if anyone of you wants to take this little project of mine to ACE he has my permission, but know It's not all my ideas, it's partly copied from other mounting AddOns (EzDismount, Dismount and Simplemount)
so beware the copyleft/copyright
And yea, AceOff is basically EZDismount, I'd stolen it's code, stirpped it down, and dropped it in my personal ConglomoMod sometimes back. Now I'm pulling it out and whipping it's Ace.... slowly... whenever I feel like coding... oh shiney! *runs off*
what about the Problem with the german Umlauts i have?
As u can see i put something into the code to enable random mount summoning for WLs and Palas, in english i don't see much of a problem, but in german the spells are:
"Schreckensross beschwören" and "Streitross beschwören" (well at last i think it's the right name of the mount)
so so i need to encode the ö in the list? And what about the string.find() on that?
With this i am in desperate need of help.
This part of the code is not just stupid it's also not working, i know but the origin of the problem is above
Linky: http://www.allegro-c.de/unicode/zcodes.htm
Found the link in WoWWiki's post about CastSpellByName():
http://www.wowwiki.com/API_CastSpellByName
You would simply need to translate a single line for each language (2 if you also want the AQ mounts)
Look at how I do this in mountme/PeriodicTable, it's quite simple really. As for tooltip scanning, check out my GratuityLib, it makes tip scanning a lot simpler.
I was thinking more of another addon I have written and it calls getglobal 30 times OnUpdate. Would it be faster to define all 30 of those to a table and simply retrieve 30 table values?
While we are talking about efficiency I was wondering if it was faster to run a check or a simple function. Mainly I was wondering about the Show() and Hide() functions. To keep a frame hidden would it be faster to check IsVisible() or to simply Hide() it regardless?
Althaya
As for testing performance, you just need to test it yourself in game.
local mem,time = gcinfo(), GetTime()
for i=1,10000 do -- you can change 10000 to whatever works best for you
-- your test code goes here
end
print(gcinfo() - mem, GetTime() - time)
compare numbers between your two functions, the smaller one is, of course, better :)