This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Classic Theme
Thottbot Theme
Macro - checking for items
Post Reply
Return to board index
Post by
Ocmer
Just started to make/learn some small macro's and I was wondering if you
can let a macro look in your bags if you have a specific item in it.
I want to make a macro that when I use it I will consume a "conjured mana strudel" and if
I don't have any mana strudels in one of my bags, I will just consume a "Honeymint Tea".
Anyone have an idea if this is possible?
Thanks, Ocmer
Post by
173035
This post was from a user who has deleted their account.
Post by
HighFive
Technically you can check whether you have a certain item, but you cannot make casting decisions based on it.
Look into Buffet. It will check your bags for the most convenient consumables and set up macros to use them.
Post by
Ocmer
A to bad, think ill look into buffet or the mod macro ^^
thnx for the reply :)
Post by
RedwoodElf
maybe try
/use Conjured Mana Strudel
/stopmacro
/use Honeymint Tea
(Is 'eating' a valid boolean? looks like not. Drattit.)
If you always put your Mana Strudel in the same bag slot, you could have the macro try that slot first, and if there's nothing there, use the honeymint tea instead.
Post by
RedwoodElf
Not sure if this would work, since I don't know the exact dynamics, and it may be too long, but you could give it a shot:
/run FMS = 0 end
/script for b = 0, 4 do for s = 1, GetContainerNumSlots(b) do local name = GetContainerItemLink(b,s) if name and string.find(name,"Strudel") and FMS=0 then FMS=1 UseContainerItem(b,s) end end end
/stopmacro
/use Honeymint Tea
I set a global variable FMS (Found Mana Strudel) to zero, then run though the bags looking for "Strudel" in the item name...if it finds one, it uses it and sets FMS to 1. Once it gets done searching the bags, I try to stop the macro if FMS has been set to 1. If that works, then it won't get to the Honeymint Tea use command.
I couldn't find a "stop macro" command in the Lua API guides, and I don't know if global variables can be used outside a /run or /script command. If someone knows a stopmacro command, you could insert
"if FMS=1 then <Stop Macro Command>" before the last "end" in the script.
Post by
pelf
Bracket conditionals can't execute Lua code, and even if they could, it would be FMS==1, not FMS=1.
I don't think that macro scripts can interact with the rest of the macro in any way, so you might have trouble getting it to stop based on some condition in the script itself.
Post by
RedwoodElf
Hmn...then what about
/script local F=0 for b = 0, 4 do for s = 1, GetContainerNumSlots(b) do local name = GetContainerItemLink(b,s) if name and string.find(name,"Strudel") and F==0 then F=1 UseContainerItem(b,s) end end if F==0 then <COMMAND TO USE ITEM BY NAME "HONEYMINT TEA"> end end
That would do it, but I haven't found the command to use an item by name. Since F is now a local variable, it can be shorter cause it wont interfere with anything else.
(Easier to read version)
/script
local F=0
for b = 0, 4 do
..for s = 1, GetContainerNumSlots(b) do
....local name = GetContainerItemLink(b,s)
....if name and string.find(name,"Strudel") and F==0 then
........F=1
........UseContainerItem(b,s)
....end
..end
..if F==0 then
....<COMMAND TO USE ITEM BY NAME "HONEYMINT TEA">
..end
end
Post by
pelf
Yeah I didn't know what the use item by name thing was. You could use the \ tag instead of indenting with periods :).
Post by
HighFive
UseContainerItem is protected except in a few situations and using an item is not one of them.
I think I've got an idea, brb.
Well, I got this:/run local a,b,c,f="Conjured Mana Strudel","Honeymint Tea",GetItemCount,"food" EditMacro(GetMacroIndexByName(f),f,1,strsub(GetMacroBody(f),1,178).."\n/use "..(c(a)>0 and a or b))It's a little hacky, but I think it works.
edit: missed a bracket
Post by
RedwoodElf
Well it can equip items (or sell them if you're in a merchant window), but not actually use them (so it won't activate a potion or eat food, for example) so we'd have to find a way to actually eat food...hmn...
Post by
pelf
lol @ what you did HighFive. I hope you feel dirty.
Slick, but dirty.
EDIT
: You don't have anything executing the macro you edited.
Post by
HighFive
The macro basically edits itself on every use. It should add a "/use Conjured Mana Strudel" or "/use Honeymint Tea" line depending on whether you have any strudels or not.
I forgot to mention that the macro's name should be "food" or you'd have to... just use "food", please.
Post by
pelf
Right, but it's never executed. So you'd have to press this macro, then the other one. It appears RunMacro is protected. Mmm.
..
Durr, I can't read. I see it now. Yeah, just use "food" :).
Post by
Ocmer
Woa thnx ;D
I've tried to understand that piece of code but wth there more functions
for wow than i thought lol. I've no idea what it all those functions
exactly does all that but at least it works like how I wanted,
so thnx all :)
-- read over the code again;
a,b,c,f="Conjured Mana Strudel","Honeymint Tea",GetItemCount,"food"
means actually:
a = "Conjured Mana Strudel"
b = "Honeymint Tea"
c = GetItemCount
f = "food"
but then just in one line and way shorter?
--
Post by
pelf
Yep. You got it.
Post by
HighFive
/run local a,b,f,m="Conjured Mana Strudel","Honeymint Tea","food" m=GetMacroBody(f)EditMacro(f,f,1,strsub(m,1,strfind(m,"\n")).."/use "..(GetItemCount(a)>0 and a or b))
/use Conjured Mana StrudelSlightly improved.
And before someone asks, EditMacro gets blocked in combat.
edit: I am an idiot.
Post by
Ocmer
And before someone asks, EditMacro gets blocked in combat.
Yup found out already ^^
and thnx again for the help all :)
Post by
232916
This post was from a user who has deleted their account.
Post by
HighFive
As an added thing I found when using the EditMacro function is that you might find issues if you have the macro selected in the macro dialog when you close it - I haven't fully investigated it - but it might just be that it doesn't refresh it when you reopen the dialog and so you see the old text in there - but I was finding that the EditMacro was failing to update the macro.EditMacro works fine, it seems that the text in the macro frame however won't update until you reopen it... That frustrated me for about 30 minutes.I'll have to play around with this (after maintenance and waiting for 3.1 to download...) but does it execute the /use on first click? I'm guessing it takes 1 click to set it up and then it'll update itself appropriately after that?Yes, it actually executes the /use on the first click. So I assume it'll use the new kind of food every time it's changed.
It seems the macro text is parsed line by line. As one is executed the rest of the macro is parsed from the final character's position on. Does that make sense?
(It explains a weird bug I had with it. I had it set up as "strsub(GetMacroBody(f),1,176))" instead of "178". The final 2 characters of the script got eaten and instead of "/use Honeymint Tea", just "e Honeymint Tea" got through.)
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.