Author Topic: Almost done, need help saving the setup variables pretty please!  (Read 3094 times)

0 Members and 1 Guest are viewing this topic.

Offline beefcake420Topic starter

  • Newbie
  • *
  • Posts: 6
  • Activity:
    0%
  • Reputation Power: 1
  • beefcake420 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Hello everyone,

I need some help with saving variables so I dont (any hopefully you dont!) have to run setup each time this script is run.  I have done as much reading on the topic as I can find, but alas I cant make heads nor tails of it.  Could someone either point me to a "how to for dummies" on variable saving and recalling or even better help me to understand it by (assisting me with) incorporating it into the following script.

Also, I wanted to mention, this is my first script, so any assistance would be greatly appreciated!

Code: [Select]
;============================================================================
; Script Name: Sin's Mace and Shield Donator
; Author: Sin
; Version: 1.3.0
; Client Tested with: 7.0.25.7
; EUO version tested with: 1.5.214
; Purpose: Donating to brit library for Mace and Shield Reading glasses
;=============================================================================
;***Setup Instructions***
;1. Runebook with position 1 marked to secure, anvil and forge
;2. Runebook with position 2 marked to Library Turn in NPC
;3. Runebook with position 3 marked to alternate Library Turn in NPC location.
;4. A "Workbag" inside your backpack, I used a "Bag" during testing.
;5. At least one tinker tools in the "Workbag"
;6. Top level of secure should contain Iron Ingots only!
;7. BEFORE running script, use a blacksmith hammer to line up the
;8. (cont) Crafting Gump to the upper left corner.
;9. Under "User Options", set the two variables.
;=============================================================================
; User Options
set %setup 1 ;Currently "MUST" be set to 1 to make script work, **Needs Work**
set %max_buckler_amount 59 ; select number of bucklers to make
==============================================================================
;Update Log
;
;Version 1.3.0
;Fixed Tinker Tool Creation.
;Fixed WaitForGump Sub.
;Improved Speed at which bucklers are made.
;Added a number of checks for stability and to ensure script continues
;to run in the event of lag.
;Added an alternate recall spot to library turn in NPC if the first
;position is blocked.
;06/18/2012 Sin
;
;Version 1.2.0
;Added Tinker Tool Creation Function
;When your workbag is down to one tinker tool, another is produced.
;Various code cleanup.
;Still suffers from being prone to cash, need to add better wait for gump
;functions.  Will work on this.
;06/10/2012 Sin
;
;Version 1.1.0
;Changed the way smith hammers were made, now only 3 are made
;Make Tinker Tools not working at this time.
;06/10/12 Sin
;
;Version 1.0.0
;Completed the first version of the script.  Script can not recover from lag
;or glitches very well at this point, but it runs.  Will continue to work on
;recovery ability etc.
;06/10/2012 Sin
==============================================================================
; Script Variables (Item types)
set %ingots ENK
set %tinker_tools JTL
set %smiths_hammer TLH
set %buckler FIK
set %status_bucklers 0
set %status_ingots 0
set %makefirstbuckler 1
set %check 0
set %count 0
set %loop 0
;list
;%time         - Delay Time in "WaitForGump"
;%setup        - Set to 1 to run script currently **NEEDS WORK HERE**
;%runebook     - This is the runebook used in this script
;%secure       - This is the secure container at the house rune location
;%workbag      - This is the workbags ID number
;%donation_npc - This is the ID of the donation NPC
;=============================================================================
; Main Loop
if %setup = 1
   {
   gosub MainSetup
   set %setup 0
   }
repeat
   {
   ;gosub CheckWeight                            ;sub not currently used
   gosub InvisSelf
   gosub GetIngots
   gosub MakeBuckler
   gosub DropIngots
   gosub TurnInBucklers
   }
until #charghost = yes
display ok You have died, halting script.
halt
display ok End of main, error halting
halt
;=============================================================================
sub MainSetup
; Get Runebook ID
display ok Target your runebook
set #targcurs 1
wait 5
repeat
wait 0
until #targcurs = 0
set %runebook #ltargetID
wait 5

; Get workbag ID number
display ok Target your workbag
set #targcurs 1
wait 5
repeat
wait 0
until #targcurs = 0
set %workbag #ltargetID
set #lobjectID %workbag
wait 5
event macro 17 0
wait 5
set #contPosX 850
set #contPosY 520
wait 25

; Get secure ID number
display ok Target your secure container.
set #targcurs 1
wait 5
repeat
wait 0
until #targcurs = 0
set %secure #ltargetID
set #lobjectID %secure
wait 10
event macro 17 0
wait 10
set #contPosX 675
set #contPosY 500
wait 25

; Get Donation NPC ID
gosub TravelToLibrary
display ok Target the reward NPC
set #targcurs 1
wait 5
repeat
wait 0
until #targcurs = 0
set %donation_npc #ltargetID
wait 5
display ok Setup complete, You can leave it to me now
gosub TravelToHome
wait 5

return
;=============================================================================
; Check weight subroutine
sub CheckWeight                                  ;more work to be done with this
set %avail = ( #maxweight - #weight )
return
;=============================================================================
; Cast Invis on Self at Secure
sub InvisSelf
set #ltargetID #charID                           ;set pc as last target
wait 5
event macro 15 43                                ;cast invis spell
wait 50
event macro 22 0                                 ;last target
wait 5
return
;=============================================================================
; Places ingots in backpack
sub GetIngots
oops:                                            ;return if ingots were not put in workbag, trys again
set #lobjectID %secure
wait 10
event macro 17 0
;set #contPosX 675                               ;if you position the secure, it moves the
;set #contPosY 500                               ;position of the workbag for some reason
wait 25
finditem %ingots C_ , %secure
if #findkind = -1
   {
   display ok Your secure container has run out of ingots, Ending Script.
   halt
   }
if #findstack < 1000
   {
   set %stack #findstack
   }
else
    {
    set %stack 1000
    }
exevent drag #findID %stack
wait 10
exevent dropc %workbag
wait 15
finditem %ingots C_ , %workbag                   ;anti lag measure, check to ensure ingots were
if #findkind = -1                                ;placed in workbag.  If not returns and tries
   {                                             ;again.
   goto oops
   }
set %status_ingots ( %status_ingots + %stack )
return
;=============================================================================
; Make Bucklers Loops
sub MakeBuckler
finditem %smiths_hammer C_ , %workbag            ;check to see how many smith hammers
if #findkind = -1                                ;are in the workbag, if 0 makes more
   {
   gosub MakeHammer
   }
finditem %smiths_hammer C_ , %workbag            ;select smith's hammer
set #lobjectID #findID
wait 5
event macro 17 0                                 ;open crafting gump
wait 5
set #contPosX 0                                  ;position gump
set #contPosY 0                                  ;position gump
wait 5
while %makefirstbuckler = 1
   {
   click 25 130 dmc
   wait 5
   gosub WaitForGump
   set #contPosX 0
   set #contPosY 0
   click 233 70 dmc
   wait 5
   gosub WaitForGump
   set %makefirstbuckler  0
   gosub MoreBuck
   click 27 452 dmc                              ;close blacksmithing window
   wait 25
   }
set %makefirstbuckler 1
return
;============================================================
; 1 to 50 bucklers
sub MoreBuck
while %count < %max_buckler_amount
      {
      click 282 453 dmc                          ;click make last button
      wait 10
      gosub WaitForGump                          ;wait for gump to refresh
      if #weight > 450                           ;checks if character is overweight
      {                                          ;if overweight, drops ingots and
      wait 10                                    ;moves to turn in NPC to drop bucklers
      return
      }
      wait 10
      finditem %smiths_hammer C_ , %workbag      ;find hammer in workbag
      if #findkind = -1                          ;checks to see how many hammers there are
          {
          gosub MakeHammer                       ;if 0 go make more
          }
      else
      if %check = 5
         {
         finditem %smiths_hammer C_ , %workbag   ;ensure hammer is targeted
         set #lobjectID #findID                  ;ensure hammer is targeted
         event macro 17 0                        ;lasttarget (activate a new hammer if last broke)
         wait 5
         set #contPosX 0                         ;reposition gump for makelast button
         set #contPosY 0                         ;reposition gump for makelast button
         wait 5
         set %check 0
         }
      else
      set %check %check + 1
      set %count %count + 1
      }
set %count 0
return
;=============================================================================
; Move ingots to secure
sub DropIngots
finditem %ingots C_ , %workbag
wait 5
exevent drag #findid #findstack
wait 10
exevent dropc %secure
set %status_ingots ( %status_ingots - #findstack )
wait 25
return
;=============================================================================
; Turns bucklers into the Donation NPC
sub TurnInBucklers
gosub TravelToLibrary
oops2:
set #lobjectID %donation_npc
event macro 17 0
gosub WaitForGump
wait 5
click 288 214 dmc                                ;select "by bag" option on npc, get target cursor
repeat
      wait 5                                     ;repeat looking until bag target cursor
      finditem %workbag C_ , #backpackid         ;is gone (anti lag measure)
      set #ltargetID #findID
      wait 5
      event macro 22 0                           ;set lasttarget to %workbag, selectlasttarget
until #targcurs = 0
gosub WaitForGump
wait 10
click 606 392 dmc                                ;select "ok" basically
wait 25
      if #weight > 250                           ;checks to see if buckler turn in was succesful
      {                                          ;if not, returns and trys again
      wait 10
      goto oops2
      }
gosub TravelToHome
return
;=============================================================================
; Makes 3 smith's hammers
sub MakeHammer
finditem %tinker_tools C_ , %workbag             ;check for tinker tools
if #findcnt < 2                                  ;if 1 left, make one more
   {
   gosub MakeTinker                              ;make tinker tools
   }
finditem %tinker_tools C_ , %workbag             ;select tinker tools
set #lobjectID #findID
wait 10
event macro 17 0                                 ;open tinkering gump
gosub WaitForGump
set #contPosX 0                                  ;position tinkering gump
set #contPosY 0                                  ;position tinkering gump
wait 10
click 28 131 dmc                                 ;select tools option in gump
gosub WaitForGump
wait 10
click 385 270 dmc                                ;select next page option in gump
gosub WaitForGump
wait 10
click 230 130 dmc                                ;select smith hammer option in gump
gosub WaitForGump
wait 25
;first hammer
click 282 453 dmc                                ;click make last button option in gump
gosub WaitForGump
wait 25
;second hammer
click 282 453 dmc                                ;click make last button option in gump
gosub WaitForGump
wait 25
;third and final hammer
finditem %smiths_hammer C_ , %workbag            ;change last object from tinker tool
set #lobjectID #findID                           ;to smiths hammer
wait 5
return
;=============================================================================
; Makes one tinker tool
sub MakeTinker
finditem %tinker_tools C_ , %workbag             ;check for tinker tools
if #findcnt > 1                                  ;if more then 1 return
   {                                             ;this is to make sure the script doesnt
   return                                        ;make excess tinker tools
   }
finditem %tinker_tools C_ , %workbag
set #lobjectID #findID
wait 10
event macro 17 0                                 ;open tinkering gump
gosub WaitForGump
set #contPosX 0                                  ;position tinkering gump
set #contPosY 0                                  ;position tinkering gump
wait 10
click 28 131 dmc                                 ;select tools option in gump
gosub WaitForGump
wait 10
click 232 130 dmc                                ;select tinker's tools
gosub WaitForGump
wait 10
return
;=============================================================================
; Travel Home to Secure Storage, Anvil, and Forge
sub TravelToHome
recallfailhome:
set %runbook #ltargetID
set #lobjectID %runebook
set %charx_runebook #charposx                    ;set current character position X
set %chary_runebook #charposy                    ;set current character position Y
wait 5
event macro 17 0                                 ;open runebook
wait 10
set #contPosX 0                                  ;position runebook
set #contPosY 0                                  ;position runebook
wait 5
click 138 196 dmc                                ;clicking page 1
wait 10
click 139 145 dmc                                ;selecting home location
wait 10
gosub WaitForRecallHome
return
;=============================================================================
; Wait For Recall Home
sub WaitForRecallHome
set %loop 0
repeat
if %charx_runebook <> #charposx || %chary_runebook <> #charposy
   {
   wait 5
   return
   }
set %loop %loop + 1
until %loop > 200
goto recallfailhome
;=============================================================================
; Travel to Library to Drop off Shields / Select turn in NPC
sub TravelToLibrary
recallfaillibrary:
set %runbook #ltargetID
set #lobjectID %runebook
set %charx_runebook #charposx                    ;set current character position X
set %chary_runebook #charposy                    ;set current character position Y
wait 5
event macro 17 0                                 ;open runebook
wait 10
set #contPosX 0                                  ;position runebook
set #contPosY 0                                  ;position runebook
wait 10
click 138 196 dmc                                ;click page 1
wait 10
click 298 145 dmc                                ;selecting Library Location
wait 10
gosub WaitForRecallLibrary
return
;=============================================================================
; Travel To Library Location 2
sub TravelToLibrary2
set %runbook #ltargetID
set #lobjectID %runebook
set %charx_runebook #charposx                    ;set current character position X
set %chary_runebook #charposy                    ;set current character position Y
wait 5
event macro 17 0                                 ;open runebook
wait 10
set #contPosX 0                                  ;position runebook
set #contPosY 0                                  ;position runebook
wait 10
click 173 195 dmc                                ;click page 2
wait 10
click 139 145 dmc                                ;select recall option
wait 10
gosub WaitForRecallLibrary
return
;=============================================================================
; Wait For Recall Library
sub WaitForRecallLibrary
set %loop 0
repeat
if Something_is_blocking in #sysmsg              ;if primary library rune is blocked
   {
   wait 10
   gosub TravelToLibrary2
   }
if %charx_runebook <> #charposx || %chary_runebook <> #charposy
   {
   wait 5
   return
   }
set %loop %loop + 1
until %loop > 200
goto recallfaillibrary
;=============================================================================
; Wait for gump
sub WaitForGump
set %time #scnt
repeat
if You_mark_ in #sysmsg
   {
   break
   }
if #scnt > ( %time + 5 )
   {
   break
   }
wait 0
until #contname = generic_gump
wait 5
return
;=============================================================================

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Almost done, need help saving the setup variables pretty please!
« Reply #1 on: June 19, 2012, 04:31:29 AM »
0
The basic, and easy way is to simply save your variables as "Persistent" (*) type rather than "standard" (%) or "namespace" (!). Persistent variables are stored in the registry and can be recovered or even used by other scripts at any time:

%Var = global
!Var = Namespace
*Var = Persistent

Maybe start by reading up on variable types here.

Of course, leaving a bunch of persistent variables in the registry isn't the cleanest way to go. There are a number of helper subs out there where scripters have come up with ways to take this type of function to a different level. For example, you can check out TM's NGFS subs here. It can be a little daunting to understand how these work but you will find that it's worth it if you can get your mind wrapped around them.

So, hopefully this gets you heading down the right path at least!

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Mythix

  • Jr. Member
  • **
  • Posts: 20
  • Activity:
    0%
  • Reputation Power: 1
  • Mythix has no influence.
  • Gender: Female
  • Respect: +1
  • Referrals: 0
    • View Profile
Re: Almost done, need help saving the setup variables pretty please!
« Reply #2 on: June 19, 2012, 07:06:08 AM »
0
I was looking at your crafting snippets and the way you handle the gumps is pretty unusual. :O
If you are wanting to move the gump to position 0,0 everytime, then just a simple
Code: [Select]
contpos 0 0 ; <--can use this after any gump is open to move it to specified place on screen.  You can also use nextcpos prior to opening a gump.would work better.
However, an easier way to handle this would be to make a sub and then go to it each time you want to click.  This way you don't have to keep moving gumps around.
Code: [Select]
sub clickinggumps
set %xpos %1
set %ypos %2

set %clickx #contposx + %xpos
set %clicky #contposy + %ypos
click %clickx %clicky dmc f
wait 5
then in place of your clicks you can use:
Code: [Select]
gosub clickinggumps 154 456  ; or whatever x,y you wantThis way you don't have to keep moving the crafting gump around.

Looks like a nice script!!


Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Almost done, need help saving the setup variables pretty please!
« Reply #3 on: June 19, 2012, 07:51:44 AM »
0
TM wrote something a while back.

HERE
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline beefcake420Topic starter

  • Newbie
  • *
  • Posts: 6
  • Activity:
    0%
  • Reputation Power: 1
  • beefcake420 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Almost done, need help saving the setup variables pretty please!
« Reply #4 on: June 19, 2012, 05:22:14 PM »
0
12TimesOver,
Thanks man, I read that before but somehow I failed and missed the persistent variable.  I used that, and it worked perfect.  Thank you very much.

Mythix,
Yes, I would agree.  Only thing I can say to that is, I was learning as I was going.  I think at this point I will rewrite much of the script to ver 2.0.0 and change the way alot of stuff is done.  There is a bunch of code, or the way things are handled that I dont care for.  But I was learning as I went.  I will use your suggestion in Ver 2.0 and call on subs to handle alot of repeat actions, and I would also like to change the way the recalling is done.

Cerveza,
I looked at what TM has done, and at this point its a bit beyond my ability.  I dont mind just throwing someones subs in, as long as I understand what it is doing.  For my purposes persistent variables (of which I only use 4 currently) will suit my purpose.  But I dont like the idea of having stuff written to the registry where it will just sit there, it doesnt seem very "clean".  I will continue to work to improve my knowledge.

Thank you everyone for the input, truly I appreciate it.  Look for Ver 2.0 to come!

Offline Mythix

  • Jr. Member
  • **
  • Posts: 20
  • Activity:
    0%
  • Reputation Power: 1
  • Mythix has no influence.
  • Gender: Female
  • Respect: +1
  • Referrals: 0
    • View Profile
Re: Almost done, need help saving the setup variables pretty please!
« Reply #5 on: June 19, 2012, 06:24:29 PM »
0
I know you didn't ask for advice on the rest of your script, so I hope I didn't step on any toes.  I just couldn't help myself.  ;)
I, myself, haven't even tried to do persistent variables yet, so this reading is helpful to me, too! 

Also, (warning: unsolicited advice coming again!) When you are casting invis on yourself, you can use event macro 23 0 which is "target self" instead of setting up the #ltargetid and using event macro 22 0 "last target".

Also, (gah! can't help myself!) Check out TrailMyx's Recall Subs for all your traveling needs. http://www.scriptuo.com/index.php?topic=18.msg18#msg18

Good Luck with this! 

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: Almost done, need help saving the setup variables pretty please!
« Reply #6 on: June 19, 2012, 09:03:42 PM »
0
I need to post up my changes to the NGFS.  It's done but not completely tested yet.  Perhaps I'll have time once I get back from my little road trip.  So far we've seen the Grand Canyon, Meteor Crater and Zion National Park.  All awesome in their own rights.
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: