Total players online: 3



Take the Tour | Site Map

It is currently Thu Dec 14, 2017 8:38 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Apr 07, 2017 2:42 am 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

I'm running a recalling mining script on a server w/o LRC armor. I'm checking my backpack for recall regs, if any are below 5 then restock all of them to 10, but what I have now is rather bulky and clumsy code. I cant just assume all regs are going to have the same amount, razor is scavenging them, so from time to time I get an unbalanced amount.
Code:
  1. sub RestockRegs
  2. set %StockingRegs #false
  3. ;check the qty of regs in backpack
  4. for %RegCounter 1 3
  5. {
  6. finditem %RecallReg . %RegCounter C_ , #backpackid
  7. if #findcnt = 0 || #Findstack < 5 || %StockingRegs = #true
  8. {
  9. set %Drag . %RegCounter 10 - #findstack
  10. set %StockingRegs #true
  11. }
  12. }
  13. ;now if NOT StockingRegs then return else open secure and restock
  14. if %StockingRegs = #false
  15. OpenSecureContLoop:
  16. set #lobjectid %SecureCont
  17. wait 1s
  18. if perform in #journal
  19. goto OpenSecureContLoop
  20. if save in #journal
  21. {
  22. wait 5s
  23. goto OpenSecureContLoop
  24. }
  25. if #contid <> %SecureCont
  26. for %RegCounter 1 3
  27. {
  28. finditem %RecallReg . %RegCounter C_ , %SecureCont
  29. if #findcnt = 0 || #findstack < %Drag . %RegCounter
  30. if %Drag . %RegCounter > 0
  31. {
  32. exevent drag #findid %Drag . %RegCounter
  33. wait 15
  34. wait 15
  35. }
  36. }

as you can see, it's a lot of code for such a simple task...

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Fri Apr 07, 2017 5:04 am 
Offline
Administrator
Administrator
User avatar

Joined: 08/12/2003 07:28
Posts: 18569
Location: Switzerland

I had a restock-sub somewhere... Have to check on my PC via remote... BRB...

Edit:
Ah... It was a work in progress.
Code:
  1.  
  2. ; -------------------------
  3. ; Sub name: restock
  4. ; Autor: Orngrimm
  5. ; Version: 0.3
  6. ; Purpose: To restock a certain type of items in your backpack from a chest
  7. ; Params:       %1      req     what to restock
  8. ;               %2      req     how many to have in the end
  9. ;               %2      req     where to get them? (Container has to be open already)
  10. ; Outputs:      #result         #true / #false for succesfull restocked
  11. ; -------------------------
  12. sub restock
  13. if %0 < 3
  14.         {
  15.         display OK Sub got called with too few arguments.$Script pauses for debugging.
  16.         pause
  17.         return
  18.         }
  19. set !what %1
  20. set !final_amount %2
  21. set !from_where %3
  22.  
  23. if #FindStack >= !final_amount
  24.         { ; enough already
  25.         set !result #true
  26.         goto sub_restock_end
  27.         }
  28. set !amountinbp #FindStack
  29.  
  30. finditem !what C_ , !from_where
  31. if !FindCNT = 0
  32.         { ; No such item in stock
  33.         set !result #false
  34.         goto sub_restock_end
  35.         }
  36.  
  37. set !amounttodrag !final_amount - !amountinbp
  38. if !Findstack < !amounttodrag
  39.         {
  40.         set !amountotdrag #FindStack ; we take all we can.
  41.         ; Display OK WE HAVE NOT ENOUGH IN STOCK!:$ !what ; Uncomment for alert
  42.        
  43. ; uncomment for hard abort if impossible to restock enough
  44.         ; set !result #false
  45.         ; goto sub_restock_end
  46.         }
  47.  
  48. exevent drag #FindID !amountodrag
  49. wait 15
  50.  
  51. if #FindStack >= !final_amount
  52.         set !result #true
  53.         set !result #false
  54.  
  55. sub_restock_end:
  56. set #result !result
  57.  

Call it like
  1. gosub restock ENK 50 %resourcechest


In your case, you can make an array of the items to be stocked:
  1. set %restock_1 XXX
  2. set %restock_2 YYY
  3. set %restock_3 ZZZ
and then loop thru them like
  1. for %cnt 1 3
  2. {
  3. gosub restock %restock_ . %cnt 50 %resourcechest
  4. }

EasyPeasy ;)

All this is untested code BTW...

It is not really short but has a lot of bells and whistles. :)

_________________
EUO Member and postwhore since: 19th Dezember, 2002; Loosing on freeshard Alexandria since: 5th January, 2005
Searches cure for cancer since: 17th November, 2003 on GRID.org & Worldcommunitygrid.org
Made scripts for Project 'Programmers for Alexandria' worth 50$
Image
Quote "mmorning": Where would theses boards be if Orn didn't miss all the sarcasm. Man its great having him here :)
Quote "author-unknown": Good idea. I gotta start doing that too. You're a trendsetter Orn. :)
Quote "dreyfus": #true is always #true


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Fri Apr 07, 2017 5:43 am 
Offline
Legendary Scripter
Legendary Scripter
User avatar

Joined: 12/23/2003 03:27
Posts: 1144
Location: Seige Perilous

Trying to rethink and modify what I had, I've come up with this:
Code:
  1. set %Reg1 %BPType
  2. set %Reg2 %BMType
  3. set %Reg3 %MRType
  4. gosub RestockRegs
  5.  
  6. sub RestockRegs
  7. ;check the qty of regs in backpack
  8. for %RegCounter 1 3
  9. {
  10. finditem %Reg . %RecCounter C_ , #backpackid
  11. set %Drag . %RegCounter 10 - #findstack
  12. }
  13. if %Drag1 < 5 && %Drag2 < 5 && %Drag3 < 5
  14. OpenSecureContLoop:
  15. set #lobjectid %SecureCont
  16. wait 1s
  17. if perform in #journal
  18. goto OpenSecureContLoop
  19. if save in #journal
  20. {
  21. wait 5s
  22. goto OpenSecureContLoop
  23. }
  24. if #contid <> %SecureCont
  25. for %RegCounter 1 3
  26. {
  27. finditem %Reg . %RegCounter C_ , %SecureCont
  28. if #findcnt = 0 || #findstack < %Drag . %RegCounter
  29. exevent drag #findid %Drag . %RegCounter
  30. wait 15
  31. wait 15
  32. }

Any tweaks I can make here
This is just a subroutine being called in main script, the set variables at top are actually set at script beginning with variable definitions.

_________________
While a = a
{
Scanjournal 1
If Daemon_is_attacking_you in #journal || ( you_are_attacking in #journal && Daemon in #journal )
Terminate UO
}


Top
  ProfileShow poster's scripts in the public script library 
PostPosted: Fri Apr 14, 2017 5:36 am 
Offline
Script Kiddie
Script Kiddie

Joined: 10/31/2011 11:11
Posts: 3
do a finditem for all 3 types of regs then for loop 1 to findcnt checking findstack. This does assume that each reg will always be stacked.


Top
  Profile 
PostPosted: Tue May 16, 2017 8:28 am 
Offline
Script Kiddie
Script Kiddie

Joined: 01/03/2014 05:37
Posts: 6
That's quite the confusing bit of code for something so simple.

I don't like using EXEVENTS because they crash my UO, but this is how I restock recall regs for my mining script:
Code:
  1.  
  2. SET %playerX        ; #CURSORX when hovering over player
  3. SET %playerY        ; #CURSORY when hovering over player
  4. SET %storageCont    ; ID of container where regs are stored
  5. SET %bpID KUF       ; ID of black pearl
  6. SET %bmID JUF       ; ID of blood moss
  7. SET %mrID MZF       ; ID of mandrake root
  8.  
  9. {
  10.   FINDITEM %bpID C_ , %storageCont
  11.   IF #FINDID <> X
  12.   {
  13.     GOSUB dragRegs
  14.   }
  15. }
  16. {
  17.   FINDITEM %bmID C_ , %storageCont
  18.   IF #FINDID <> X
  19.   {
  20.     GOSUB dragRegs
  21.   }
  22. }
  23. {
  24.   FINDITEM %mrID C_ , %storageCont
  25.   IF #FINDID <> X
  26.   {
  27.     GOSUB dragRegs
  28.   }
  29. }
  30.  
  31. SUB dragRegs
  32.   WAIT 15
  33.   MSG 5$
  34.   CLICK %playerX %playerY p
  35.   WAIT 15
  36.  


Top
  ProfileShow poster's scripts in the public script library 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Hosted by CalWeb Internet Services, Inc.