ScriptUO

Scripting Resources & Utilities => OpenEUO Scripts => OEUO => Scripting tools => Topic started by: TrailMyx on August 30, 2010, 10:32:42 AM

Title: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on August 30, 2010, 10:32:42 AM
Code: [Select]
---------------------------------------------------------------
-- Script Name: TrailMyx's Subroutine Collection
-- Author: TrailMyx
-- Version: v8
-- Shard OSI / FS: unk
-- Revision Date: 9/29/2010
-- Purpose: Collection of routines to help the scripter automate UO
--
--          TM_SecondTimer
--            local timer = TM_SecondTimer:New{duration = 5} -- creates a 5 SECOND non-blocking countdown timer (automatically starts)
--            timer:Start(10) -- restarts existing timer with new time
--            timer:Check() -- returns true if time has expired, false otherwise
--
--          TM_msTimer
--            local timer = TM_msTimer:New{duration = 50} -- creates a 50 MILLISECOND non-blocking countdown timer (automatically starts)
--            timer:Start(500) -- restarts existing timer with new time
--            timer:Check() -- returns true if time has expired, false otherwise

--          TM_IDtoEUO(id) -- converts an OEUO numerical ID value to the classic EUO base-26 text value
--          TM_EUOtoID(str_in) -- converts the classic EUO base-26 item id into an OEUO-compatible numerical ID value
--
--          TM_ItemInfo -- includes all necessary item information as returned by UO.GetItem
--            TM_FindItemsByID(id) -- locates items by ID (either EUO or OEUO format)  Returns count and table of items
--            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
--
--          TM_GumpWait(c1, c2) -- waits for either gump c1 or gump c2 to pop up within 7 seconds.  Returns true on success
--          TM_GumpWaitAndSize(c1, x, y) -- waits for gump c1 that is size (x,y) within 7 seconds.  Returns true on success
--
--          TM_IgnoreItem(ignore, findid) -- maintains an "ignore" list.  This table can be passed to TM_ItemInfo
--
--          TM_OpenPaperdoll(x,y)
--          TM_OpenStatusBar(x,y)
--          TM_OpenBackPack(x,y)
---------------------------------------------------------------

This is going to be my main subs distribution file for those functions that don't have a specific location.  I will implement a version number query subroutine so that you can make sure you are using the expected version of this file.  Didn't do that yet.
Title: Re: TrailMyx's Subroutine collection foro OEUO
Post by: TrailMyx on August 30, 2010, 12:45:02 PM
I forgot to add in the color matching for this.  It would be nice for this sub to find all your frostwood, and sum up all the stacks.  ;)

Really, it's pretty easy to do that by hand, so I might as well leave that be.  I can put up the sample code if you'd like.
Title: Re: TrailMyx's Subroutine collection foro OEUO
Post by: TrailMyx on August 31, 2010, 01:07:49 PM
I decided this was stable enough to put out into the public.  Enjoy
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on September 13, 2010, 11:33:21 PM
Playing with OEUO is much easier with these routines, especially if you need to use the finditem function.  With the property information also embedded within each item, you have a very powerful toolset.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on September 15, 2010, 08:55:00 AM
Another nice feature of these functions is the non-blocking timers.

Code: [Select]
local timer = TM_SecondTimer:New{duration = 5} -- creates a 5 SECOND non-blocking countdown timer (automatically starts)
 while timer:Check() == false do
   -- do something else until timer fires.
 end

 if timer:Check() == true then
   print("your timer expired for some reason")
 end
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on September 30, 2010, 10:32:16 AM
Version 7:
Added IGNOREITEM feature into TM_FindItem.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: Endless Night on September 30, 2010, 05:20:49 PM
Version 7:
Added IGNOREITEM feature into TM_FindItem.


Twinkle McNugget is just getting spoiled rotten these days.. ;)
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on September 30, 2010, 06:30:27 PM

Twinkle McNugget is just getting spoiled rotten these days.. ;)

Lol, yeh.  It's time to start put'in out!

Also included in these subs:

TM_OpenPaperdoll(x,y)
TM_OpenStatusBar(x,y)
TM_OpenBackPack(x,y)

The names are explanatory.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on September 30, 2010, 06:51:39 PM
BTW, upgraded to V8.  I released without testing...  Oops.  Works now for TM_IgnoreItem
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: Scrripty on October 01, 2010, 06:08:20 AM
Version 7:
Added IGNOREITEM feature into TM_FindItem.


Twinkle McNugget is just getting spoiled rotten these days.. ;)

My cancer treatment comes before UO.  Sorry. :)  The last 2 days I've been at the docs for 8+ hours each.  I have to go Saturday too, then I should be free for 5 days or so.  We'll see.  Yesterday was a benedryl filled day where I slept with the laptop on my lap most of the day. heh
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: NObama on October 13, 2010, 09:21:45 PM
Ok, I don't understand.

If I want to use this to, say, find and count all powder of fort in containers near my character...I think this is the syntax:

Code: [Select]
count = TMFindItem (4102)
if count > 0 then
  print("Found:"..count)
end 

What I don't understand is how to call the subroutine library...plus, I'm not entirely sure I've got the syntax right above...

*head hurts, time for bed*

 :-[
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on October 13, 2010, 10:46:33 PM
Please take a look at the sample code that's included in the comments.  But you're looking for something like this:

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

temp = {} -- will contain all found items as objects (see tm_subs_collection8.lua for a description of all information stored in the object)
count = 0 -- this is the count.
count, temp = TM_FindItemsByID(4102) -- you can also have a string here representing the EUO-style value like "POF"
if count > 0 then
  print(string.format("Found = %d",count))
  for x,v in ipairs(temp) do
    print(string.format("Finditem is %d",v.findid))
  end
end


This is untested code since I'm traveling I can't test, but it should be close to working.

BE SURE TO SAVE THIS SNIPPET TO A FILE FIRST!! OTHERWISE OEUO WILL NOT WORK

Similar sample code is in the file to use the full-blown finditem.  Please take the time to go over and see what's inside tm_subs_collection8.lua
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: NObama on October 14, 2010, 06:25:40 AM
Thanks, TM.  Believe it or not, I did read your comments...I am just completely lost.  EUO syntax made sense to me, this still does not.  I am not sure UO will be around long enough for me to become literate in Lua.

I told myself I was going to successfully code a snippet that would do something simple, like find the Ant Queen.  Then, I discovered how hard that is in OEUO and I died a little inside.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: Scrripty on October 14, 2010, 07:06:02 AM
 Its far from all that hard, most people are just overcomplicating it for themselves.  Try to write your own finditem routine so you understand how it works a bit better in oeuo before you try to use tms tools.  They are always a bit more complicated than the new user should start with imo.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on October 14, 2010, 09:18:28 AM
Well not in this case. If you know EUO syntax, then these just work.  Everything I've put out so far has the old EUO scripter in mind.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: NObama on October 14, 2010, 06:27:55 PM
Ok - making a little more sense.  What I can't understand is why this code executed several times, then abruptly stopped working:

Code: [Select]
dofile("tm_subs_collection8.lua")
temp = {}
count = 0
count, temp = TM_FindItemsByID(4102)
if count > 0 then
print(count)
end

Now, when I run I just get "Stopped."

Also, the result it was returning before (133) did not accurately count all the POF in the nearby containers.  

EDIT:  Ah ha!  I must have closed containers.  This doesn't count inside closed containers, apparently...is that intended, TM?

Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on October 14, 2010, 06:32:00 PM
So it worked how many times?
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: NObama on October 14, 2010, 06:33:09 PM
I worked until I closed all the containers on screen (logged out/logged back in due to inactivity).  See edit above.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on October 14, 2010, 06:34:58 PM
That's probably a problem with prior then.  Add that to the bug list.
FindItemsByID is a very simple sub.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on October 15, 2010, 08:19:52 AM
Iterating through a table and extracting the index and item is just a Lua idiom, so just snuggled up with a Lua book for a few minutes and read up on "pairs" or "ipairs".

Anyway, I posted a few examples in the other thread.  Should be useful.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on October 29, 2010, 07:42:36 AM
Updated to version 9.  Fixed a timer bug.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: Superslayer on November 01, 2010, 04:11:10 PM
nvrmind...to drunk again..
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: smokinjoe26 on March 04, 2012, 05:58:13 AM
I realize that this is an old topic and OpenEUO is a forgotten cause.  Although, while working with it.  I have found the following when running the below script ...

Code: [Select]
UO.TargCurs = true
wait(100)
while (UO.TargCurs == true) do
  wait(5000)
  print("Target the item you want info on")
end
local obtype = UO.LTargetID
for i = 0, UO.ScanItems(true) do
  local id,type,kind,contid,x,y,z,stack,rep,col = UO.GetItem(i)   
  if id == obtype then
    local name, info = UO.Property(id)
    print ('i = item number ' .. i .. ' in scan items')
    print('name:'..name, 'info:'..info)
    print("the id is:"..id, "the type is:"..type, "the kind is:"..kind, "the contid is:"..contid, "the x coordinate is:"..x, "the y coordinate is:"..y, "the z coordinate is:"..z, "the stack amount is:"..stack, "the rep is:"..rep, "the col is:"..col)
  end
end

I checked my runebook with this and got the following printed result:

i = item number 0 in scan items
name:Runebook
info:Exceptional
Blessed
Weight: 1 Stone
BOD
the id is:1160486928
the type is:8901
the kind is:0
the contid is:1135523425
the x coordinate is:877
the y coordinate is:536
the z coordinate is:0
the stack amount is:0
the rep is:0
the col is:1121


Basically, what I am getting at and what it boils down to is that the subs collections was not scanning the item numbered zero for one of the find item functions.  Mainly pertaining to UO.GetItem(val).  UO.GetItem starts at zero.  I am not sure why but it does.  My character attempting to get bods would not use his runebook because it was UO.GetItem number zero.  Others may ave this same problem.  Just providing potentially useful info is all ... I am not sure if TM wants to mess with this or not.

I changed all of these:
i=1,UO.ScanItems
To these:
i=0,UO.ScanItems

Happy scripting to all.
Title: Re: TrailMyx's Subroutine collection foro OEUO - Includes FINDITEM!
Post by: TrailMyx on March 04, 2012, 09:57:51 AM
I apologize for that.  I've had that fixed in my version for a LONG time now.  I don't know why I never posted it.  Thank you for point it out to everyone - I'll update this thread with the latest version.  Thanks smokinjoe!