Author Topic: Understanding TM's FindItem routines and applying them  (Read 5399 times)

0 Members and 1 Guest are viewing this topic.

Offline NObamaTopic starter

  • Everything I need to know, I learned from Miffy's Item Finder.
  • Elite
  • *
  • *
  • Posts: 3454
  • Activity:
    0%
  • Reputation Power: 43
  • NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.
  • Respect: +161
  • Referrals: 2
    • View Profile
Understanding TM's FindItem routines and applying them
« on: October 14, 2010, 07:36:42 PM »
0
Okay, this:

Code: [Select]
dofile("tm_subs_collection8.lua")

temp = {}
count = 0
count, temp = TM_FindItemsByID(3709)
if count > 0 then
print(count)
end

Finds every small wooden box locked down next to me.  There are 20 of them.  If I then wanted to open each one, would I need to build an array assigning all of them to 1 thru 20, then proceed to UO.Macro(17,0) them one at a time?

I know TM built an [ignore] option in, but reading his documentation doesn't make syntax immediately clear.  Theoretically, i should be able to open and ignore each one in turn, then proceed to the next.

--            TM_FindItem(ids, locations, containers, dist, ignore) -- locates multiple IDS/TYPES on either ground or container, and at specific distances
--                                                                     return count(sum of items), stacks(sum of stacks), matches(table of all matching items)
--                                                                     ignore - table of items previously ignored

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Understanding TM's FindItem routines and applying them
« Reply #1 on: October 14, 2010, 07:55:34 PM »
0
I'll do a bit of sample code tonight for ya.  Present on vacation, so I can't do it right now
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline NObamaTopic starter

  • Everything I need to know, I learned from Miffy's Item Finder.
  • Elite
  • *
  • *
  • Posts: 3454
  • Activity:
    0%
  • Reputation Power: 43
  • NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.
  • Respect: +161
  • Referrals: 2
    • View Profile
Re: Understanding TM's FindItem routines and applying them
« Reply #2 on: October 14, 2010, 08:37:47 PM »
0
Shucks, not trying to interrupt your vacation!  Just trying to stem my despair over the loss of EUO...halloween scripts, FAF, miffy's item finder...gone, all gone...

*sobs*

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Understanding TM's FindItem routines and applying them
« Reply #3 on: October 14, 2010, 10:01:13 PM »
0
Here's a useful example:  FINDITEM INFO!

Code: [Select]
dofile("tm_subs_collection8.lua")
---------------------------------------------------------------
function CheckHotKey()
  if getkey("f1") and getkey('alt') then
    return true
  end
  return false
end
---------------------------------------------------------------
targetkey = false
repeat
  if CheckHotKey() then
    UO.TargCurs = true
    UO.LTargetKind = 1
    while UO.TargCurs == true do end
    print(UO.LTargetID)
    count, temp = TM_FindItemsByID(UO.LTargetID)
    if count > 0 then
      print("--------------------------------")
      print(string.format("FINDID = %d", temp[1].findid))
      print(string.format("findtype = %d", temp[1].findtype))
      print(string.format("findkind = %d", temp[1].findkind))
      print(string.format("contid = %d", temp[1].findid))
      print(string.format("findx = %d", temp[1].findx))
      print(string.format("findy = %d", temp[1].findy))
      print(string.format("findz = %d", temp[1].findz))
      print(string.format("findstack = %d", temp[1].findstack))
      print(string.format("findrep = %d", temp[1].findrep))
      print(string.format("findcol = %d", temp[1].findcol))
      print(string.format("name = %s", temp[1].name))
      print(string.format("property = %s", temp[1].property))
    end
  end   
until false

This demonstrates how to use getkey correctly (in this case ALT-F1 brings up the target cursor), plus a quick look at the return values of my quick TM_FindItemsByID.

Notice this syntax:

Quote
print(string.format("findkind = %d", temp[1].findkind))

My finditem subs return tables of objects, so "temp" CAN be more than one item.  However, since TM_FindItemsByID only returns one item, you can always reference the first value in the table of objects by referencing it with temp[1].  Remember that in Lua, arrays are really just tables. 

If you were to run the TM_FindItem sub, you can definitely get more than one item.  For that, you can iterate using a "for" statement.
« Last Edit: October 14, 2010, 10:06:31 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Understanding TM's FindItem routines and applying them
« Reply #4 on: October 14, 2010, 10:29:19 PM »
0
Here's an MIB counter with a test to see how many ancients there are (2 minutes to write/test)

Code: [Select]
dofile("tm_subs_collection8.lua")
ancient = 0
count, stack, items = TM_FindItem({5357},"gc", "*", UO.BackpackID) -- search for 5357 on ground (dist=any) or backpack
if count > 0 then
  print(string.format("MIBs Found: %d",count))
  for x,k in ipairs(items) do
    if k.findcol ~= 0 then
      ancient = ancient + 1
    end
  end
  print(string.format("%d are ancient",ancient))
end

You can also use old EUO base-26 FINDTYPE format:

Code: [Select]
dofile("tm_subs_collection8.lua")
ancient = 0
count, stack, items = TM_FindItem("rvh","cg", "*", UO.BackpackID) -- search for rvh on ground (dist=any) or backpack
if count > 0 then
  print(string.format("MIBs Found: %d",count))
  for x,k in ipairs(items) do
    if k.findcol ~= 0 then
      ancient = ancient + 1
    end
  end
  print(string.format("%d are ancient",ancient))
end

This one makes no sense, but it shows you can have multiple arguments for what you want to search for: (MIBs and GOLD)

Code: [Select]
dofile("tm_subs_collection8.lua")   --5357
ancient = 0
count, stack, items = TM_FindItem("rvh_pof","gc", "*", UO.BackpackID) -- search for rvh or pof on ground (dist=any) or backpack
if count > 0 then
  print(string.format("MIBs Found: %d",count))
  for x,k in ipairs(items) do
    if k.findcol ~= 0 then
      ancient = ancient + 1
    end
  end
  print(string.format("%d are ancient",ancient))
end

And here it is with standard OEUO numbers (notice they are enclosed in a table)

Code: [Select]
dofile("tm_subs_collection8.lua")   --5357
ancient = 0
count, stack, items = TM_FindItem({5357,3821},"cg", "*", UO.BackpackID) -- search for 5357,3821 on ground (dist=any) or backpack
if count > 0 then
  print(string.format("MIBs Found: %d",count))
  for x,k in ipairs(items) do
    if k.findcol ~= 0 then
      ancient = ancient + 1
    end
  end
  print(string.format("%d are ancient",ancient))
end

So, how would you make check to see if these are REALLY MIBs?  Since property is automatically returned, I'm sure you can figure it out.  Still stuck?  Check out string.match at Lua.org:

http://www.lua.org/manual/5.1/manual.html#pdf-string.match
« Last Edit: October 14, 2010, 10:44:57 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Understanding TM's FindItem routines and applying them
« Reply #5 on: October 14, 2010, 11:45:24 PM »
0
Here's an example using Ignoreitem.  All I'm doing here is finding all the MIBs in my pack, ignoring the first one in the list and then re-running Finditem until everything is ignored.  Note I've added the ignore table to the last argument of the TM_FindItem sub.

Code: [Select]
dofile("tm_subs_collection8.lua")   --5357
ancient = 0
count = 99
ignored = {}

while count ~= 0 do
  count, stack, items = TM_FindItem({5357},"c", "*", UO.BackpackID, ignored) -- search for rvh in backpack
  if count > 0 then
    print(string.format("MIBs Found: %d",count))
    ignored = TM_IgnoreItem(ignored, items[1].findid) -- ignore the FINDID of the first one in the list - see that the list is being replaced by the return list...
  end
end

Notice how much this looks like EUO?  That's the way I've tried to code my stuff to make it easier for peeps to transition.  But you should always keep a Lua reference handy until you get used to the difference in syntax.

Also, this makes it possible for you to switch in and out ignore lists allowing you to maintain lists of differing items.
« Last Edit: October 14, 2010, 11:59:03 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline NObamaTopic starter

  • Everything I need to know, I learned from Miffy's Item Finder.
  • Elite
  • *
  • *
  • Posts: 3454
  • Activity:
    0%
  • Reputation Power: 43
  • NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.
  • Respect: +161
  • Referrals: 2
    • View Profile
Re: Understanding TM's FindItem routines and applying them
« Reply #6 on: October 15, 2010, 06:19:07 AM »
0
LIGHTBULB!  I SEE A LIGHTBULB!

It is small and dim, but it is shining.

Offline Tidus

  • Lazy
  • Administrator
  • *
  • *
  • Posts: 1291
  • Activity:
    0%
  • Reputation Power: 15
  • Tidus is working their way up.Tidus is working their way up.Tidus is working their way up.
  • Gender: Male
  • Mind Blown
  • Respect: +151
  • Referrals: 2
    • View Profile
    • Ultimate Apparel
Re: Understanding TM's FindItem routines and applying them
« Reply #7 on: October 15, 2010, 10:54:48 AM »
0
My thing is trying to bring back a monster it found and making it attack it.  I want to specifically attack a lizarman,  how do i go about bring that back to make it the ltargetid and make it so that i can set it up to be killed.....

My lightbult saw flashed and went out.  Need a new one.
For those who have fought for it, freedom has a taste the protected will never know ~ Anonymous, Vietnam, 1968

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Understanding TM's FindItem routines and applying them
« Reply #8 on: October 15, 2010, 11:10:26 AM »
0
Well, it's just a table. So address it like an array and set it to nil. I.e.

Ignores[findid] =nil
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Tidus

  • Lazy
  • Administrator
  • *
  • *
  • Posts: 1291
  • Activity:
    0%
  • Reputation Power: 15
  • Tidus is working their way up.Tidus is working their way up.Tidus is working their way up.
  • Gender: Male
  • Mind Blown
  • Respect: +151
  • Referrals: 2
    • View Profile
    • Ultimate Apparel
Re: Understanding TM's FindItem routines and applying them
« Reply #9 on: October 15, 2010, 11:16:01 AM »
0
*gets under the desk and doesn't come out*

This is way over my head...  i need mommy ;)
For those who have fought for it, freedom has a taste the protected will never know ~ Anonymous, Vietnam, 1968

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Understanding TM's FindItem routines and applying them
« Reply #10 on: October 15, 2010, 11:23:12 AM »
0
Unfortunately, there's no getting around the fact that you need to start understanding Lua syntax.  Tables are a MUST to understand because they are so central to how the languages organize everything.  Just look at other code and ask questions.
« Last Edit: October 15, 2010, 11:25:42 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: