Page 1 of 1
useItem help
Posted: Tue Nov 20, 2012 1:13 am
by xrozhija
I need a bit of help with the useItem funcion, as I cant seem to make it use a stack of items, it only uses one, and then goes on with the waypoints.
I have searched the forum, and cant seem to find the answer to how to make it use up the stack, and then go on with the waypoints as usual.
Code: Select all
<!-- # 9 --><waypoint x="-22000" z="3708" y="-179">
if inventory:itemTotalCount("Item_Name") >0 then
inventory:useItem("Item_Name")
yrest(100)
end </waypoint>
I have also tried putting in various bits of "if" and "else" code, but none seem to work.
Hope theres someone who can help me with this, So I dont have to manually click to open bags all the time.
Re: useItem help
Posted: Tue Nov 20, 2012 1:19 am
by rock5
useItem uses 1 item. If you want to use more than 1 then you have to do useItem more than once. I'm assuming you want to use all items, not just one stack.
Code: Select all
<!-- # 9 --><waypoint x="-22000" z="3708" y="-179">
while inventory:itemTotalCount("Item_Name") >0 do
inventory:useItem("Item_Name")
end </waypoint>
That should use them all up until there are none left. I don't think you need the yrest.
Re: useItem help
Posted: Tue Nov 20, 2012 1:24 am
by lisa
well it uses 1 item because that is how it is designed, if you want to use the same item more than once then just do a loot.
Code: Select all
if inventory:itemTotalCount("Item_Name") >0 then
repeat
inventory:useItem("Item_Name")
yrest(100)
inventory:update()
until inventory:itemTotalCount("Item_Name") == 0
end
Rock got in before me lol
Re: useItem help
Posted: Tue Nov 20, 2012 1:30 am
by xrozhija
Thank you so much, both, for your quick reply.
Any chance you could post the code to sell at vendor as well? (can't seem to remember it atm)
Re: useItem help
Posted: Tue Nov 20, 2012 2:33 am
by lisa
it's pretty obvious what you want is this
Code: Select all
for k = 1,73 do
player:target_NPC("Melody Woram")
ChoiceOptionByName("want")
store:buyItem(208042,99)
RoMScript("CloseWindows()");
yrest(500)
for i = 1, 99 do inventory:useItem(208042) end
player:merchant("Melody Woram")
end
it will buy, open and then sell the items.
Re: useItem help
Posted: Tue Nov 20, 2012 3:12 am
by xrozhija
Thanks lisa, good guess at what i am trying to achieve

tho it could be for other items as well, like the material packages you get from the farms in guild castle. (I personally always vendor those mats as i cant be bothered to donate)
Re: useItem help
Posted: Tue Nov 20, 2012 4:11 am
by lisa
xrozhija wrote:Thanks lisa, good guess at what i am trying to achieve

tho it could be for other items as well, like the material packages you get from the farms in guild castle. (I personally always vendor those mats as i cant be bothered to donate)
I posted a userfunction a loooooong time ago which donates resources to guild.
Re: useItem help
Posted: Thu Nov 22, 2012 10:41 am
by vo2male
lisa wrote:
Code: Select all
if inventory:itemTotalCount("Item_Name") >0 then
repeat
inventory:useItem("Item_Name")
yrest(100)
inventory:update()
until inventory:itemTotalCount("Item_Name") == 0
end
Rock got in before me lol
Im trying to use this to exchange Barrier IV to Dias in our server. what i made is this.
<!-- # 1 --><waypoint x="2729" z="949" y="66">
if inventory:itemTotalCount("Barrier IV") >0 do
player:target_NPC("Owenstein")
sendMacro("ChoiceOption(1);")
sendMacro("ChoiceOption(1);")
sendMacro("ChoiceOption(1);")
yrest(100)
inventory:update()
until inventory:itemTotalCount("Barrier IV") == 0
end
but im having this error.. any thoughts about it?
Code: Select all
5:48pm - scripts\rom/bot.lua:792: Failed to compile and run Lua code for waypoin
t #1
Re: useItem help
Posted: Thu Nov 22, 2012 6:54 pm
by lisa
usually you would have
What you have is
So yeah that will always do a compile error.
Re: useItem help
Posted: Thu Nov 22, 2012 7:37 pm
by vo2male
lisa wrote:usually you would have
What you have is
So yeah that will always do a compile error.
Thanks! Finally got this to work. Cause what my previous WP does, it targets the NPC then after the dialogue runs around and targets again the NPC making an endless loop of obvious botting ^_^
Cheers!
Re: useItem help
Posted: Thu Jul 23, 2015 11:58 am
by beanybabe
I tried this and another example I found but both will open 1 bag then stop. Is there a way to get it to open the rest ?
if inventory:itemTotalCount("Item_Name") >0 then
repeat
inventory:useItem("Item_Name")
yrest(100)
inventory:update()
until inventory:itemTotalCount("Item_Name") == 0
end
I tried this with the upper bit or bottom bit commented out neither works
Code: Select all
<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onload>
if inventory:itemTotalCount("Sea Crystal Sand Material Package") >0 then
-- repeat
-- print( "total item = ", itemTotalCount("Sea Crystal Sand Material Package"))
-- inventory:useItem("Sea Crystal Sand Material Package")
-- yrest(100)
-- inventory:update()
-- until inventory:itemTotalCount("Sea Crystal Sand Material Package") == 0
while inventory:findItem("Sea Crystal Sand Material Package") do
if inventory:itemTotalCount(0) == 0 then break end
i=inventory:findItem("Sea Crystal Sand Material Package")
while i.ItemCount > 0 and inventory:itemTotalCount(0) > 0 do
i=inventory:findItem("Sea Crystal Sand Material Package")
i:use()
print( "total item = ", itemTotalCount("Sea Crystal Sand Material Package"))
end
end
end
</onload>
</waypoints>
Re: useItem help
Posted: Thu Jul 23, 2015 12:13 pm
by rock5
Are you talking about using 1 stack of items? What might be happening is when you use 1 in the stack, the stack becomes busy and so when you go to open another it doesn't find any available. Try adding a longer wait after each use.
Re: useItem help
Posted: Thu Jul 23, 2015 6:33 pm
by beanybabe
Both of those were code you had listed as using. I buy 5 bags from the vendor and it seems to open 1 then just skips the rest I put the prints in to try to see what was up.
Sometimes I get error on itemTotalCount() if it has a quoted text value. I seen you mention it only takes the id numbers. But I cannot find a id number for the
"Sea Crystal Sand Material Package" I am still looking for some code that looks up the id number.
I am not good at arrays so I have been making separate wp for each mat till I figure them out.
Re: useItem help
Posted: Thu Jul 23, 2015 8:26 pm
by lisa
Rock has an addon for getting Ids in game, I have just used this userfunction for a very long time.
Code: Select all
function lisa_printinventory()
local bags = {}
inventory:update()
for slot = 61, 240 do
item = inventory.BagSlot[slot]
if item.Available and item.Name ~= "<EMPTY>" then
table.insert(bags, {Name = item.Name, Id = item.Id, Rlevel = item.RequiredLvl, stats = item.Stats})
end;
end;
table.print(bags)
end
as for using bag items, yeah you need a good rest in between uses.
This is just an example of opening starter bags.
Code: Select all
inventory:useItem(201843)
yrest(5000)
inventory:useItem(201844)
yrest(6000)
inventory:useItem(203571)
yrest(7000)
The more items in the bags the longer you need to wait.
Re: useItem help
Posted: Fri Jul 24, 2015 9:35 am
by beanybabe
Thanks lisa. I tried that and it got errors the <empty> was invalid therefor removed <> and just put in empty resulting in every id even empty bag spots. So I changed the code to key off Id instead of item now it list only items in the bag.
table: 0620B050
stats: table: 03C518B8
Name: Sea Crystal Sand Material Package
Rlevel: 1
Id: 208046
Code: Select all
function lisa_printinventory()
local bags = {}
inventory:update()
for slot = 61, 240 do
item = inventory.BagSlot[slot]
if item.Available and item.Id ~= 0 then
table.insert(bags, {Name = item.Name, Id = item.Id, Rlevel = item.RequiredLvl, stats = item.Stats})
end;
end;
table.print(bags)
end
Re: useItem help
Posted: Fri Jul 24, 2015 9:50 am
by beanybabe
Here is what I finally got working. Now i just need an easy way to get the id for all the other mats ill try to find rocks function. This gets me back going for now.
I think it may have worked with the text as I originally tried. I was continually getting an error about global variable. I missed putting inventory: as a prefix to one of the varables. [string "..."]:5: attempt to call global 'itemTotalCount'
Code: Select all
<onload>
local item = 208046 --Sea Crystal Sand Material Package
if inventory:itemTotalCount(item) >0 then
RoMScript("CloseAllWindows()") -- have to close vendors so it does not try to sell when you open bags.
repeat
print( "total item = ", inventory:itemTotalCount(item)) -- this is the line I had left out inventory :
inventory:useItem(item)
yrest(1100)
inventory:update()
until inventory:itemTotalCount(item) == 0
end
</onload>
</waypoints>
Re: useItem help
Posted: Fri Nov 27, 2015 1:25 pm
by beanybabe
Is there some way to do something like this ?
local item = ({242128,242129,242127,208046,208066,208056})
inventory:useItem(item)
I have list of many items that need to be used and prefer the code to be simple.
Re: useItem help
Posted: Fri Nov 27, 2015 5:14 pm
by lisa
local item = ({242128,242129,242127,208046,208066,208056})
inventory:useItem(item)
Code: Select all
local item = {242128,242129,242127,208046,208066,208056}
for k,v in pairs(item) do
inventory:useItem(v)
end
Re: useItem help
Posted: Fri Dec 04, 2015 5:19 am
by beanybabe
Thanks lisa; If this works it will save lots and lots of code for each vendor and item but it was horrible to fix if vendors got updated. Next I need to revise what it does after it opens the current code is also large and mostly repeating. I hope to get this down to a simple menu of items. It would be easy for you but I am trying to learn how to do it. Arrays and strings are still hard for me some day it may light the bulb and become easy.
I was up to revision 5 of this and crashed and lost them all luckily I still had revision 1. It is interesting how revision 1 now works well. The patches to the bot the last few months seem to cure what was making it crash.