ScriptUO

Official ScriptUO EasyUO Scripts => Script Library => Misc. Scripts => Topic started by: TrailMyx on February 06, 2009, 07:22:32 AM

Title: TrailMyx's Buy Agent Subs
Post by: TrailMyx on February 06, 2009, 07:22:32 AM
Code: [Select]
;=================================================================
; Script Name: TrailMyx's Buy Agent Subs
; Author: TrailMyx
; Version: 1.0
; Shard OSI / FS: OSI / FS OK
; Revision Date: 9/29/2007
; Purpose: Automates the process of buying items from NPCs
;
;  TM_BuyAgent_ID = If you know the #FINETYPE of the items you want to purchase
;  TM_BuyAgent_Name = If you want to purchase an item by name
;  #RETURNS #TRUE (-1) if error occurs
;           number of items purchased (no error)
;
; http://www.scriptuo.com
;
; Example:
; set %npc_id XXYYZZ1
; gosub TM_BuyAgent_ID %npc_id OIK 5 ; 5 wooden shields
; gosub TM_BuyAgent_ID %npc_id BSF 10 ; 10 battleaxe
; gosub TM_BuyAgent_Name %npc_id battle_axe 2 ; 10 battleaxe
; gosub TM_BuyAgent_Name %npc_id mandrake_root 100 ; 100  mandrake root
;=================================================================

Just some quick subs I put together to buy items from npc vendors.  Useful to see how the getshopinfo and setshopinfo routines work.
Title: Re: TrailMyx's Buy Agent Subs
Post by: 12TimesOver on February 06, 2009, 09:46:29 AM
Coolness. Going to try these out in my donator, I mean damn why not, half of it is made up from your subs already LOL!

XII

Edit -

BTW, I've been meaning to ask this and it's kind of related to your sub but let me know if I should start a new thread. One of the turnin items available for all NPC's is books. From what I can tell not all purchasable books are the same and not all books are accepted by the NPC's. It also seems as if some NPC's accept more than one type. However, from what I can tell, all of the book types seem to have the same #FINDTYPE value. I haven't gone further with my research yet, I've just been totally overwhelmed lol, but I'm curious how else to handle this. Is it possible to buy an item of type X based on meeting some other type of property?

Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on February 06, 2009, 10:22:02 AM
I was under the impression that if a book was a different shape or used a different graphic, then the book should have a different FINDTYPE.  Books hued differently might be different.  I can't tell you with 100% certainty, but I would think they would act like other items in UO.  dunno.
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on February 06, 2009, 10:59:19 AM
Also, there are easier ways to do this buy thing.  With either UOA or Razor, it's pretty much automatic.  However I don't like relying on an external program.  The way EasyUO does it is slow, but honestly it's nearly the same as one would do it at the keyboard.

I just wish you could sell as well.  ;)
Title: Re: TrailMyx's Buy Agent Subs
Post by: Cerveza on February 06, 2009, 11:14:49 AM
Hmmm.... TM's buy agent and UOA's sell agent.... sounds like a script that's dying to be made  :-X
Title: Re: TrailMyx's Buy Agent Subs
Post by: 12TimesOver on February 06, 2009, 11:48:05 AM
Yeah the sell piece is extremely frustrating since it relies on clicks and gump coordinates. I haven't figured out a better way than to make sure there is nothing in the pack that is sellable other than the one item I'm trying to sell otherwise I don't know how to tell the script what gump coordinates to use.  At least if there is only one itemtype that a given vendor will buy I can assume it will be the top line of the sell gump.

I'll have to double-check your point about the item types, I swear I checked that and that was why I was stumped as to how to differentiate between the books but I may have been very tired and screwed up. I went to a Provisioner, bought each kind of book, and checked the ITEMTYPE value - I either screwed up or they all had the same value. Of course not all three books were donatable which leads me to believe I did screw up. Guess I'll have to go check again.

XII

Edit -
Just wanted to confirm that yes, I screwed up before. Not sure what I did but I'll bet lunch I had two clients running and was looking at the #LLIFTEDTYPE of the wrong client hehe. Blue book = AZF, Red Book = XYF, Brown Book (with a story in it) = NYF.

That's good news for me then :P
Title: Re: TrailMyx's Buy Agent Subs
Post by: Khameleon on December 31, 2009, 10:29:41 AM
working with these subs here...
I came across this I think maybe something is up here.
if an item isn't on the vendor I get to the bottom of the list, and it just loops forever.
I think this might be the problem.

      event property #SHOPITEMID
      if !item_name notin #PROPERTY
      {
        set !temp #SHOPCURPOS
        click !clickx !clicky dmc
        repeat
          getshopinfo
        until #SHOPCURPOS <> !temp

maybe it should be...

until #SHOPCURPOS <> !temp || #SHOPCURPOS = #ShopCnt
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on December 31, 2009, 01:10:23 PM
Ah, that's a good idea.  I never thought about an item that isn't in the list.  +1 karma!
Title: Re: TrailMyx's Buy Agent Subs
Post by: Khameleon on December 31, 2009, 01:34:49 PM
atm it doesn't return #True....
Title: Re: TrailMyx's Buy Agent Subs
Post by: Khameleon on January 01, 2010, 01:12:17 PM
found another little hiccup...

        wait 5
        set !clickx #CONTPOSX - 44
        set !clicky #CONTPOSY - 150
        click !clickx !clicky d dmc
        setshopitem #shopItemID !amount
        set !clickx #CONTPOSX + 44
        set !clicky #CONTPOSY + 207
        click !clickx !clicky dmc
        set #RESULT !amount
        repeat
        until #CONTNAME <> bill_gump
        break

maybe something like...
if #ShopItemMax < !Amount
Set !Amount #ShopItemMax
        setshopitem #shopItemID !amount
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on January 01, 2010, 07:30:50 PM
If you get a version that's running smoother, let me know your changes and I'll update with appropriate kudos to ya!  :)  I just have no time to play with this particular snippet.
Title: Re: TrailMyx's Buy Agent Subs
Post by: Khameleon on January 01, 2010, 07:55:45 PM
It kinda got it working with the two mods I posted up here. only thing is I'm not sure how to force it to close the buy gump, and return a #True statement instead it returns a 0 item bought value.
Title: Re: TrailMyx's Buy Agent Subs
Post by: NObama on March 24, 2010, 05:42:15 PM
I've been trying to incorporate this into a wider script.  Unfortunately, I've just learned that it only buys one item at a time - inconvenient if you're using it to farm regs.

If I wanted this to purchase, say, 20 nightshade, how could I change it?

For the record, I'm using the correct syntax and I've var dumped to check the value of !amount...it is correct, but the script keeps dbl clicking the buy option in these lines:

      {
        wait 5
        set !clickx #CONTPOSX - 44
        set !clicky #CONTPOSY - 150
        click !clickx !clicky d dmc
        setshopitem #shopItemID !amount  <--- at this point, vardump tells me !mount is 20
        set !clickx #CONTPOSX + 44
        set !clicky #CONTPOSY + 207
        click !clickx !clicky dmc  <--- At this point, the script clicks 'buy' with only one nightshade on the contract
        set #RESULT !amount
        repeat
        until #CONTNAME <> bill_gump
        break
      }
Title: Re: TrailMyx's Buy Agent Subs
Post by: NObama on March 24, 2010, 05:44:01 PM
Whoops - I just read Kham's post.  I'll try his version.

 :P

EDIT:  Nope - same problem.  Help?  I really don't think the answer is 19 more clicks...or 998.

Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on March 24, 2010, 05:44:55 PM
It should by whatever number you want.  Or it did the last time I tested it.
Title: Re: TrailMyx's Buy Agent Subs
Post by: NObama on March 24, 2010, 05:49:35 PM
I agree.  It *should*   :P

Unfortunately, it's not...unless it's supposed to buy them one at a time?

Hmm...is there a way to make EUO hold the shift key and dbl click?  I see you can hold down two keys at once, but there doesn't seem to be anything in the documentation on keying and clicking simultaneously.
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on March 24, 2010, 05:54:56 PM
Well should and *did* at one point.  So if it's only buying one thing now, I'm worried that something has broken on the EUO side of things.  This script hasn't changed from the time where it worked well even before Khams suggestions.  Dunno.
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on March 24, 2010, 06:21:56 PM
And does still work.  Just tested.  However, remember the gump doesn't update the amount; it's updated in memory.  Please refer to the EUO documentation for this note:

Quote
# Despite the fact that using setShopItem will not update the graphics in the buy gump, the ammount to sell is set in the client's memory.

http://wiki.easyuo.com/index.php/SetShopItem
Title: Re: TrailMyx's Buy Agent Subs
Post by: NObama on March 24, 2010, 06:25:13 PM
Ah - thanks, TM.  I really appreciate it.  I would never have thought to delve into setShopItem...I didn't know enough to look.

I'm slowing succumbing to the lure of gen2000's script...trying not to, but it's hard.

 :)
Title: Re: TrailMyx's Buy Agent Subs
Post by: Twisted1851 on October 23, 2011, 04:24:01 PM
Could someone help me figure out how to make this buy from 7 faction bottle vendors? I tried setting it up, but after trying to buy 1 set of bottles from one npc, and failing, it gave up. Thanks!
Title: Re: TrailMyx's Buy Agent Subs
Post by: Grandewd on August 24, 2013, 04:42:20 PM
Just found this awesome sub after spending a couple of hours playing with all the getShopInfo options... Now I can quit that thanks to TM   :)

It works perfectly.... Not surprised...

Question:  Is there a way to have it buy ALL of an item? :)
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on August 24, 2013, 05:53:57 PM
I don't think so.  There's no #SHOP* variable that reveals how may items are currently for sale.
Title: Re: TrailMyx's Buy Agent Subs
Post by: Grandewd on August 24, 2013, 06:07:32 PM
I don't think so.  There's no #SHOP* variable that reveals how may items are currently for sale.

Ok, np... It works perfectly for buying any quantity otherwise...  :)
Title: Re: TrailMyx's Buy Agent Subs
Post by: 12TimesOver on May 19, 2014, 08:56:28 AM
Question:  Is there a way to have it buy ALL of an item? :)
Just doing some buy sub stuff and saw this comment.

Technically you should be able to tell it to buy #SHOPITEMMAX and it will buy all of whatever the vendor has in stock of that given item.

XIIx "GM Res'er of Threads" OveR
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on May 19, 2014, 09:02:34 AM
Title: Re: TrailMyx's Buy Agent Subs
Post by: 12TimesOver on May 19, 2014, 09:28:39 AM
:P

I was wondering about the pixel scanning thing. I know the Buy position is different for different NPC's so a generic Buy sub is pretty much impossible without doing that. This is an area I've always been too intimidated to delve into but have always wanted to try so I guess I'll play around with it.

I wish the getshopinfo was more similar to finditem, allowing you to address specific indexes directly with one load rather than having to click to move through the items and getshopinfo repeatedly - or am I missing something that will make me happy?

X
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on May 19, 2014, 09:32:27 AM
Yes, that's what the pixel scanning does in this set of subs.  Just like for quest item marking, I use this sub to locate the "Buy" in the context dropdown of the NPC.  So it should handle any position changes found from NPC to NPC.

To be honest, it's been so long since I've looked at these so I kinda forget how they work.  lol
Title: Re: TrailMyx's Buy Agent Subs
Post by: declo on June 03, 2014, 10:26:20 AM
Yes, that's what the pixel scanning does in this set of subs.  Just like for quest item marking, I use this sub to locate the "Buy" in the context dropdown of the NPC.  So it should handle any position changes found from NPC to NPC.

To be honest, it's been so long since I've looked at these so I kinda forget how they work.  lol

Is it possible to purchase 2 items within the loop?

ie

gosub TM_BuyAgent_ID %npc_id OIK 5 %npc_id QSK 5
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on June 03, 2014, 12:37:02 PM
Nope, you have to purchase one of those at a time.
Title: Re: TrailMyx's Buy Agent Subs
Post by: The Ghost on October 26, 2014, 07:17:35 PM
TM. 
This is a nice build.  easy to use.   thx. 
Title: Re: TrailMyx's Buy Agent Subs
Post by: Crisis on March 16, 2015, 06:05:33 PM
I have this set to what I want to buy and I added in Kham's fix but if the items I want is not on the list, it does not click accept and it just hangs there. I have it to buy

Code: [Select]
set %npc_id1 YEDUG
set %npc_id2 XOCDC
gosub TM_BuyAgent_ID %npc_id1 NZF 999 ; 999 Fertile Dirt  (I set this to 999 to buy max of the amount, hoping it will buy all if amount is lower)
gosub TM_BuyAgent_ID %npc_id2 NZF 999 ; 999 Fertile Dirt

wait 300s   ;so it will check back every 5 minutes to see if they have respawned
return
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on March 17, 2015, 04:34:10 PM
So I don't understand what you'd like here. I can see how the subs will just stall out until the item you're shopping for comes back into inventory.  I suppose a counter can be put into the loop, so when you scroll all the way down, it will just give up.
Title: Re: TrailMyx's Buy Agent Subs
Post by: Crisis on March 17, 2015, 05:25:08 PM
I was just curious if anyone had a fix for it. It will sit with the buy gump open after scrolling through it if the item you want to buy is not there. You can manually click accept but it stalls out and doesn't do anything else. I usually use Gens but the mystics in Ter Mur are the only NPC's for fertile dirt so his doesn't work for that. It's no big deal, i was just curious is all.
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on March 17, 2015, 07:05:53 PM
I was just curious if anyone had a fix for it. It will sit with the buy gump open after scrolling through it if the item you want to buy is not there. You can manually click accept but it stalls out and doesn't do anything else. I usually use Gens but the mystics in Ter Mur are the only NPC's for fertile dirt so his doesn't work for that. It's no big deal, i was just curious is all.

So what you're trying was sold out at the time?
Title: Re: TrailMyx's Buy Agent Subs
Post by: Crisis on March 17, 2015, 08:14:04 PM
Yes, it was sold out. I had it set so it check to check every 5 minutes or at least think I had it set right but when it scrolled through and the item wasn't there it would stop at the bottom of the list and stall out, never clicking on accept.
Title: Re: TrailMyx's Buy Agent Subs
Post by: The Ghost on March 18, 2015, 08:56:18 AM
I see one a long time ago that use this time of info.  I only have this info now.   Hope I had better filling system back them. 


Code: [Select]
getshopinfo
    for !i 1 !_buyCnt
    {
      if #shopItemType = !_itemType . !i && ! !_bought . !i
      {
        if #shopItemPrice <= !_maxprice . !i
Title: Re: TrailMyx's Buy Agent Subs
Post by: TrailMyx on March 18, 2015, 10:59:05 AM
Yes, it was sold out. I had it set so it check to check every 5 minutes or at least think I had it set right but when it scrolled through and the item wasn't there it would stop at the bottom of the list and stall out, never clicking on accept.

I'll have to fiddle with it then.  The dynamics of how the shopinfo stuff works is kinda NOT intuitive.  And frankly, I've forgotten all the stuff that went into the debugging.. :)