ScriptUO
Scripting Resources & Utilities => OEUO => OpenEUO Scripting Chat => Topic started by: NObama on October 14, 2010, 07:36:42 PM
-
Okay, this:
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
-
I'll do a bit of sample code tonight for ya. Present on vacation, so I can't do it right now
-
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*
-
Here's a useful example: FINDITEM INFO!
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:
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.
-
Here's an MIB counter with a test to see how many ancients there are (2 minutes to write/test)
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:
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)
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)
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
-
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.
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.
-
LIGHTBULB! I SEE A LIGHTBULB!
It is small and dim, but it is shining.
-
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.
-
Well, it's just a table. So address it like an array and set it to nil. I.e.
Ignores[findid] =nil
-
*gets under the desk and doesn't come out*
This is way over my head... i need mommy ;)
-
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.