useItem help

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
xrozhija
Posts: 51
Joined: Sat Apr 25, 2009 2:08 am

useItem help

#1 Post by xrozhija » Tue Nov 20, 2012 1:13 am

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: useItem help

#2 Post by rock5 » Tue Nov 20, 2012 1:19 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: useItem help

#3 Post by lisa » Tue Nov 20, 2012 1:24 am

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
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

xrozhija
Posts: 51
Joined: Sat Apr 25, 2009 2:08 am

Re: useItem help

#4 Post by xrozhija » Tue Nov 20, 2012 1:30 am

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)

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: useItem help

#5 Post by lisa » Tue Nov 20, 2012 2:33 am

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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

xrozhija
Posts: 51
Joined: Sat Apr 25, 2009 2:08 am

Re: useItem help

#6 Post by xrozhija » Tue Nov 20, 2012 3:12 am

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)

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: useItem help

#7 Post by lisa » Tue Nov 20, 2012 4:11 am

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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

vo2male
Posts: 122
Joined: Mon Aug 27, 2012 6:41 am

Re: useItem help

#8 Post by vo2male » Thu Nov 22, 2012 10:41 am

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: useItem help

#9 Post by lisa » Thu Nov 22, 2012 6:54 pm

usually you would have

Code: Select all

while **** do
******
end

Code: Select all

repeat 
*******
until ******

Code: Select all

if ****** then
*****
end
What you have is

Code: Select all

if ***** do
****
until ******
end
So yeah that will always do a compile error.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

vo2male
Posts: 122
Joined: Mon Aug 27, 2012 6:41 am

Re: useItem help

#10 Post by vo2male » Thu Nov 22, 2012 7:37 pm

lisa wrote:usually you would have

Code: Select all

while **** do
******
end

Code: Select all

repeat 
*******
until ******

Code: Select all

if ****** then
*****
end
What you have is

Code: Select all

if ***** do
****
until ******
end
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!

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: useItem help

#11 Post by beanybabe » Thu Jul 23, 2015 11:58 am

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>

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: useItem help

#12 Post by rock5 » Thu Jul 23, 2015 12:13 pm

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: useItem help

#13 Post by beanybabe » Thu Jul 23, 2015 6:33 pm

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: useItem help

#14 Post by lisa » Thu Jul 23, 2015 8:26 pm

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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: useItem help

#15 Post by beanybabe » Fri Jul 24, 2015 9:35 am

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

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: useItem help

#16 Post by beanybabe » Fri Jul 24, 2015 9:50 am

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>

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: useItem help

#17 Post by beanybabe » Fri Nov 27, 2015 1:25 pm

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: useItem help

#18 Post by lisa » Fri Nov 27, 2015 5:14 pm

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
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: useItem help

#19 Post by beanybabe » Fri Dec 04, 2015 5:19 am

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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests