• Loginserver: illusions.com.br,2593
  • Ultima Online Custom
Hello There, Guest! Login Register


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lumberjack [Easyuo]
#1
Segue anexo o macro, só marcar as runas (recomendo cerca de 30-40 (depende do shard)) uma runa em casa (em frente uma bag, e dar play, tem menu auto explicativo, bem simples.

Use um machado com Spell Chanelling, caso use magery.


Code:
;=======================================================================
; Script Name: neo's Ter Mur Area Lumberjack
; Author: neo
; Version: 2.0
; Client Tested With: 7.0.18.0
; EUO version tested with: 1.50 202
; Shard OSI / FS: OSI
; Revision Date: 09/26/2011
; Public Release: 08/16/2011
; Purpose: Will recall to an area, chop all the trees the user sets in that
;          area, and then recall to the next area and so on.
;--------------------------------------------------------------------------------
; Url:     http://www.scriptuo.com/index.php?topic=8255.0
;================================================================================
; Version 2.0     - Added multi-runebook support. You can add as many runebooks
;                   you want for your trees. Remember to have the proper runebook
;                   selected from the list, and also written the rune number in
;                   the proper edit box BEFORE you click to add a tree.
;                 - Added option to choose your own max weight offset from the menu
;                 New save is required for this to work, so you'll have to setup
;                 everything from scratch, sorry about that!
;----------------------------------------------------------------------------------
; Version 1.0     Okay, so it's been a while since last update, so I'm hoping to
;                 get some feedback on people who use this to see how it's working
;                 and possibily fix any issues that may appear.
;                 - Using my own recall sub now. It was about time I wrote one
;                   myself... :) Please tell me if you find any issues
;                 - Wrote a new drag and drop sub. I did some testing and found
;                   this cool way of moving stuff, again, tell me if
;                   something does not work for you
;                 - Redid the menus
;                 - Added pause button
;                 - Script will now halt if you close the menu
;                 - Script will now save travel method you choose
;                 - Added separate menu for statistics
;                 - Changed max weight offset
;
; Thank you EN and everyone else for the suggestions and feedback, which were
; all essential to the evolution of this script. I hope to continue getting
; feedback from everyone so I can continue updating this until it's nice for
; everyone's use.
;----------------------------------------------------------------------------------
; Version   0.6 - Fixed some codes that could cause issues.
;               - Script will now attempt to recall once per tree per rune.
;                 i.e. if you get blocked location at rune number one, and you
;                 have 4 trees there, it will attempt to recall 4 times to that rune
;                 before trying the next location.
;               - Added new axe types for gargoyles. Thank you Bodfather!
;-----------------------------------------------------------------------------------
; Version   0.5 - Fixed possible overweight issue.
;               - Fixed counter issues(I think)
;---------------------------------------------------------------------------------
; Version   0.4 - If you're axe is not equipped when you're adding trees, it will
;                 be equipped automatically
;               - Fixed core sub. Believe it or not, I left an old version of the
;                 sub in there with the same name, I don't even know how EUO was
;                 handling this.
;               - Removed some useless lines of code I found
;               - Changed how recall subs and dropoff sub work again. Will fine tune
;                 this as I find the need to do so.
;               - Added menu option to choose rune number of secure
;               - Save button will now save your bank option, and also the rune number
;                 of your secure
;               - Fixed Travel Method Choice. Recall and Sacred Journey should
;                 be working just fine now.
; Thanks:
; Thank you Guadah for the feedback, 0.4 is based mostly on your input. Cheers!
;----------------------------------------------------------------------------------
; Version   0.3 - Fixed issue that was causing the script to slow down after 1 hour
;                 or so.
;               - Added Logs/Hour counter
;               - Changed how recall works to improve performance in case of
;                 'something is blocking that location'
;----------------------------------------------------------------------------------
; Version   0.2 Fixed counter bug.
;--------------------------------------------------------------------------------
; Version   0.1 Currently only tested with Melisande's Corroded Hatchet, should work
;               with any axe type. Won't grab anything from secure or craft though.
;               Features:
;               - You can set up as many trees you want it to chop in a specific area.
;                 It will recall to that area and chop all the trees there, until
;                 they're clean, and then it will recall to the next area
;               - Will recall back home or to the bank to drop off your stuff, and
;                 then resume chopping where you left off.
;               - Works in Ter Mur, so will get you Crystal Shards, which is nice
;               - Won't give that horrible recall scripting impression, that will likely
;                 get you reported, especially in Ter Mur.
;               - Will save your setup using TM's NGFS, so you only need to set it up
;                 once.
;
;               Things you'll see in the next versions:
;               - Run away from enemies you set
;               - Multi-runebook support. Although if you do the math, let's say you
;                 set up a full runebook, with 5 trees to chop in each location,
;                 you will easily get to a total of 80 different trees to chop in
;                 each loop.
;               - A check during setup that will warn you if you won't be able to chop
;                 the tree you're trying to set up.
;               - Pause button
;               - User suggestions. I always want to improve things so that they can be
;                 helpful to anyone who tries them. So, if you have ANY suggestions, please
;                 feel free to share them with me! Also, any kind of feedback is appreciated
;                 so that I can try to keep improving this for the ScriptUO community. :)
;----------------------------------------------------------------------------------------------
; Special Thanks:
; Stuff I used from other people's libraries:
; - Tm's Next Generation File System
; - Tm's Runebook/Spellcast Subs
; - Tm's Advanced Journal Handler
; - 12TimesOver's XIIxMaxWeight sub
; So, I would like to thank both TM and 12times for sharing their subs
; with us. I greatly appreciate being able to use their codes in my stuff.
; Thank you.

; I'd also like to thank everyone here at ScriptUO who made me feel right at home.

; Neo
;-----------------------------------------------------------------------------------------------
; Instructions: Have a runebook with all your tree locations and another runebook with you're home/bank
; rune. Then, you have to add every tree using the menu. There's a box next to the Add button where
; you have to input the number of the rune of the current tree your chopping.
; Example: If the tree you're setting is in the first rune of the runebook, you write
; the number '1' into that box, and click add. Then you'll target the tree you want to chop
; and the tree will be added to the list. You can do this for as many tress as you'd like per rune.
; I haven't tested this with trees that are more than one screen away from the recall position though.
; Once this is all done, you can save your setup, so that you don't have to add the trees every time you run this.
; Also, you can easily remove any tree you want from the menu with the Remove Selected button. Also remember to set up
; your secure from the menu.
; Now you're set. Just click the Start Chopping button and the script will do the rest.
; Enjoy.
;======= User settings =======
set %dragwait 10 ; drag and dropwait will be changed to 20 if the lag check is true...
set %dropwait 10 ; however, if you want, you can adjust the wait time to your liking
set %axe ASF_BSF_CSF_FSF_HSF_ISF_LSF_MSF_NSF_OSF_ZRF_RMH_LPH_UOH_OFR_JOH_SMH_MPH_XTH_EIY_SQBB_QQBB ; if your axe type isn't here, you can manually add it

;------- Advanced editing ( only change if you know what you're doing )-----------------
; These are error messages that will be searched in the journal while you're chopping
; If you notice any error message happening to you that's not here, you can add it
; Remember to adjust the %errorcnt. Example: set %error7 error_message ; set %errorcnt 7
;----------------------------------------------------------------------------------------
set %error1 you_cannot_see_that_location
set %error2 target_cannot_be_seen
set %error3 that_is_too_far_away
set %error4 you_can't_use_an_axe_on_that.
set %error5 You_can't_do_that
set %error6 enough_wood
set %errorcnt 6
;======= don't edit below this point =======
;======= Item Types =======
set %boards TLK
set %logs ZLK
set %crystals SDHB
set %logs ZLK
set %amber FXS
set %fungi XWS
set %bark NWS
set %switch BWR
set %parasitic YWS
;======= Counters =======
set %normalcnt 0
set %oakcnt 0
set %ashcnt 0
set %yewcnt 0
set %bloodcnt 0
set %heartcnt 0
set %frostcnt 0
set %crystalcnt 0
set %ambercnt 0
set %fungicnt 0
set %barkcnt 0
set %switchcnt 0
set %paracnt 0
set %juststarted #true
set %totalcnt %totalcnt + #findstack
set %runtime 0h:00m:00s
set %logshour 0
set %bank #false
set %homerune 0
set %addedcnt 0
set %bookcnt 0
set %weight_offset 61
;======= Menu Loop =======
gosub menu
repeat
 if #menubutton <> N/A
   gosub #menubutton
until #false
;======= End Loop =======

;======= reset_button sub
sub reset_button
 Display yesno Are you sure you want to remove all you're settings?
 if #dispres = no
 {
   set #menubutton N/A
   return
 }
 for %reset 1 %addedcnt
 {
   set %spotx . %reset N/A
   set %spoty . %reset N/A
   set %spotz . %reset N/A
   set %treex . %reset N/A
   set %treey . %reset N/A
   set %treez . %reset N/A
   set %treetile . %reset N/A
   set %treekind . %reset N/A
   set %treerune . %reset N/A
 }
 set %addedcnt 0
 menu delete addedlist
 menu Font BGColor Window
 menu Font Color WindowText
 menu List Create addedlist 184 112 249 133
 set #menubutton N/A
return
;======= end sub =======

;======= Save_Button Sub =======
sub save_button
 Display yesno Are you sure you want to save?
 if #dispres = no
 {
   set #menubutton N/A
   return
 }
 menu set status_label Saving , #spc , user , #spc , setup
 gosub TM_NGFS_InitializeScript neolumber
 if %addedcnt > 0
 {
   for %savecnt 1 %addedcnt
     gosub TM_NGFS_RegisterVariables neolumber std std spotx . %savecnt spoty . %savecnt spotz . %savecnt treex . %savecnt treey . %savecnt treez . %savecnt treetile . %savecnt treekind . %savecnt treerune . %savecnt book . %savecnt
 }
 if %bookcnt > 0
 {
   for %booksave 1 %bookcnt
     gosub TM_NGFS_RegisterVariables neolumber std std booklist . %booksave
 }
 menu get runenumberedit
 set %homerune #menures
 menu get bankchk
 set %bank #menures
 menu get travelcombo
 if #menures = 1
   set %travel RE
 if #menures = 2
   set %travel SJ
 gosub TM_NGFS_RegisterVariables neolumber std std treebook secure homebook addedcnt homerune bank travel bookcnt weight_offset
 gosub TM_NGFS_SaveVariables neolumber
 set #menubutton N/A
 menu set status_label Saving , #spc , complete
 wait 10
 menu set status_label Idle
return
;======= End Sub =======

;======= Load_button sub =======
sub load_button
 menu set status_label Loading , #spc , user , #spc , setup
 gosub TM_NGFS_InitializeScript neolumber
 gosub TM_NGFS_DoesSaveExist neolumber
 if #result
 {
   gosub TM_NGFS_LoadVariables neolumber
   if %addedcnt > 0
   {
     menu delete addedlist
     menu Font BGColor Window
     menu Font Color WindowText
     menu List Create addedlist 184 112 249 133
     for %savecnt 1 %addedcnt
       menu list add addedlist tree_x: , #spc , %treex . %savecnt , #spc , tree_y: , #spc , %treey . %savecnt , #spc , tree_z: , #spc , %treez . %savecnt , #spc , rune: , #spc , %treerune . %savecnt
   if %bookcnt > 0
   {
     menu delete booklist
     menu Font BGColor Window
     menu Font Color WindowText
     menu List Create booklist 20 144 153 69
     for %booksave 1 %bookcnt
       menu list add booklist %booklist . %booksave
   }
   menu set bankchk %bank
   menu set runenumberedit %homerune
   menu Font BGColor Window
   menu set home_edit %homebook
   menu set secure_edit %secure
   menu set weight_edit %weight_offset
   event macro 31
   wait 20
   event macro 8 1
   gosub neogumpwait paperdoll_gump 262_324
   contpos 800 4
   wait 10
   event macro 8 2
   gosub neogumpwait status_gump 432_184
   contpos 781 331
   wait 10
   event macro 8 7
   gosub neogumpwait container_gump 230_204
   contpos 327 617
   wait 20
 }
 else
 {
   Display No Save Found
   menu set status_label Idle
 }
 menu set status_label Settings , #spc , loaded
 wait 10
 menu set status_label Idle
 set #menubutton N/A
return
;======= End Sub =======

;======= start_button sub =======
sub start_button
 if %juststarted
 {
   set %starttime #scnt
   set %juststarted #false
 }
 gosub getchks
 if #result
 {
   set #menubutton N/A
   gosub statsmenu
   repeat
     gosub core
   until #false
 }
 set #menubutton N/A
return
;======= End sub =======

;======= core sub =======
sub core
 for %n 1 %addedcnt
 {
   if #menubutton = CLOSED
   {
     display Menu closed. Halting.
     halt
   }
   if #menubutton = pause_button
   {
     menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
     menu delete pause_button
     menu font Color Black
     menu Font BGColor BtnFace
     menu Button resume_button 129 266 91 25 Resume
     repeat
     until #menubutton = resume_button
     menu delete pause_button
     menu font Color Black
     menu Font BGColor BtnFace
     menu Button pause_button 129 266 91 25 Pause
   }
   set %nexttree #false
   if %location <> %treerune . %n
   {
     menu set status_label Recalling , #spc , to , #spc , tree , #spc , location.
     repeat
       gosub neotravel %book . %n %treerune . %n %travel 10
     until #result || #result = blocked
     if #result
       set %location %treerune . %n
     if #result = blocked
       set %nexttree #true
   }
   if %nexttree = #false
   {
     menu set status_label Locating , #spc , tree , #spc , to , #spc , chop.
     gosub pathfind %spotx . %n %spoty . %n %spotz . %n
     if #result
     {
       gosub pathfinding %spotx . %n %spoty . %n %spotz . %n
       if #result
       {
         repeat
           gosub chop %treex . %n %treey . %n %treez . %n %treetile . %n %treekind . %n
         until %nexttree
       }
     }
   }
 }
return
;======= end sub =======


;======= addtree sub =======
sub addtree
 set %spotx . %addedcnt #charposx
 set %spoty . %addedcnt #charposy
 set %spotz . %addedcnt #charposz
 finditem %axe C_ , #charid
 if #findkind = -1
 {
   finditem %axe C_ , #backpackid
   exevent drag #findid
   wait %dragwait
   exevent droppd
   wait %dropwait
 }
 set #lobjectid #findid
 repeat
   event macro 17
   target
   gosub timeout #targcurs <> 1
 until #result
 while #targcurs = 1
   wait
 set %treex . %addedcnt #ltargetx
 set %treey . %addedcnt #ltargety
 set %treez . %addedcnt #ltargetz
 set %treetile . %addedcnt #ltargettile
 set %treekind . %addedcnt #ltargetkind
 set %treerune . %addedcnt %runenumber
 }
return
;======= end sub =======

;======= removebook_button sub =======
sub removebook_button
 if %bookcnt > 0
 {
   menu get booklist
   set %removeselected #menures
   if %removeselected = %bookcnt && %removeselected > 1
   {
     set %bookcnt %bookcnt - 1
     menu delete booklist
     menu Font BGColor Window
     menu Font Color WindowText
     menu List Create booklist 20 144 153 69
     for %addlist 1 %bookcnt
       menu list add booklist %booklist . %addlist
   }
   else
   {
     set %r %removeselected + 1
     if %addedcnt > 0
     {
       for %i %r %addedcnt
       {
         set %imin %i - 1
         set %booklist . %imin %booklist . %i
       }
     }
     set %bookcnt %bookcnt - 1
     menu delete booklist
     menu Font BGColor Window
     menu Font Color WindowText
     menu List Create booklist 20 144 153 69
     if %bookcnt > 0
     {
       for %addlist 1 %bookcnt
         menu list add booklist %booklist . %addlist
     }
   }
 }
 set #menubutton N/A
return
;======= End Sub =======

;======= remove_button sub =======
sub remove_button
 if %addedcnt > 0
 {
   menu get addedlist
   set %removeselected #menures
   set %spotx . %removeselected N/A
   set %spoty . %removeselected N/A
   set %spotz . %removeselected N/A
   set %treex . %removeselected N/A
   set %treey . %removeselected N/A
   set %treez . %removeselected N/A
   set %treetile . %removeselected N/A
   set %treekind . %removeselected N/A
   set %treerune . %removeselected N/A
   if %removeselected = %addedcnt && %removeselected > 1
   {
     set %addedcnt %addedcnt - 1
     menu delete addedlist
     menu Font BGColor Window
     menu Font Color WindowText
     menu List Create addedlist 184 112 249 133
     for %addlist 1 %addedcnt
       menu list add addedlist tree_x: , #spc , %treex . %addlist , #spc , tree_y: , #spc , %treey . %addlist , #spc , tree_z: , #spc , %treez . %addlist , #spc , rune: , #spc , %treerune . %addlist
   }
   else
   {
     set %r %removeselected + 1
     if %addedcnt > 0
     {
       for %i %r %addedcnt
       {
         set %imin %i - 1
         set %spotx . %imin %spotx . %i
         set %spoty . %imin %spoty . %i
         set %spotz . %imin %spotz . %i
         set %treex . %imin %treex . %i
         set %treey . %imin %treey . %i
         set %treez . %imin %treez . %i
         set %treetile . %imin %treetile . %i
         set %treekind . %imin %treekind . %i
         set %treerune . %imin %treerune . %i
       }
     }
     set %addedcnt %addedcnt - 1
     menu delete addedlist
     menu Font BGColor Window
     menu Font Color WindowText
     menu List Create addedlist 184 112 249 133
     if %addedcnt > 0
     {
       for %addlist 1 %addedcnt
         menu list add addedlist tree_x: , #spc , %treex . %addlist , #spc , tree_y: , #spc , %treey . %addlist , #spc , tree_z: , #spc , %treez . %addlist , #spc , rune: , #spc , %treerune . %addlist
     }
   }
 }
 set #menubutton N/A
return
;======= End Sub =======

;======= dragdrop sub =======
sub dragdrop
 namespace push
 namespace local dragdrop
 set !item %1
 set !amount %2
 set !bag %3
 set !timeout1 #scnt2 + 10
 set !timeout2 #scnt + 6
 repeat
   event property !bag
 until Stones in #property
 set !initcnt #property
 exevent drag !item !amount
 exevent dropc !bag
 repeat
   repeat
     event property !bag
   until Stones in #property
   set !newcnt #property
 until !initcnt <> !newcnt || #scnt >= !timeout2
 if !initcnt = !newcnt
 {
   event macro 9 7
   wait 1
   nextCPos 776 577
   event macro 8 7
   gosub gumpwait container_gump N/A #backpackid
   wait 15
 }
 repeat
 until #scnt2 >= !timeout1
 namespace pop
return
;======= end sub =======

;======= Drop Off Sub =======
sub dropoff
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 ignoreitem reset
 gosub logs2boards
 menu set status_label Traveling , #spc , home.
 repeat
   gosub neotravel %homebook %homerune %travel 10
 until #result
 if %bank
 {
   repeat
     event macro 1 0 Bank
     gosub neogumpwait container_gump 180_240
   until #result
   wait 10
 }
 repeat
   finditem %secure
 until #findcnt > 0
 menu set status_label Dropping , #spc , resources , #spc , in , #spc , secure.
 repeat
   finditem %boards C_ , #backpackid
   if #findcnt > 0
   {
     if #findcol = 2010
     {
       set %totalcnt %totalcnt + #findstack
       set %oakcnt %oakcnt + #findstack
       menu set oakcnt %oakcnt
     }
     if #findcol = 1191
     {
       set %totalcnt %totalcnt + #findstack
       set %ashcnt %ashcnt + #findstack
       menu set ashcnt %ashcnt
     }
     if #findcol = 1192
     {
       set %totalcnt %totalcnt + #findstack
       set %yewcnt %yewcnt + #findstack
       menu set yewcnt %yewcnt
     }
     if #findcol = 1194
     {
       set %totalcnt %totalcnt + #findstack
       set %bloodcnt %bloodcnt + #findstack
       menu set bloodcnt %bloodcnt
     }
     if #findcol = 1193
     {
       set %totalcnt %totalcnt + #findstack
       set %heartcnt %heartcnt + #findstack
       menu set heartcnt %heartcnt
     }
     if #findcol = 1151
     {
       set %totalcnt %totalcnt + #findstack
       set %frostcnt %frostcnt + #findstack
       menu set frostcnt %frostcnt
     }
     if #findcol = 0
     {
       set %totalcnt %totalcnt + #findstack
       set %normalcnt %normalcnt + #findstack
       menu set normalcnt %normalcnt
     }
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 repeat
   finditem %crystals C_ , #backpackid
   if #findcnt > 0
   {
     set %crystalcnt %crystalcnt + #findstack
     menu set crystalcnt %crystalcnt
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 repeat
   finditem %amber C_ , #backpackid
   if #findcnt > 0
   {
     set %ambercnt %ambercnt + #findstack
     menu set ambercnt %ambercnt
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 repeat
   finditem %fungi C_ , #backpackid
   if #findcnt > 0
   {
     set %fungicnt %fungicnt + #findstack
     menu set fungicnt %fungicnt
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 repeat
   finditem %bark C_ , #backpackid
   if #findcnt > 0
   {
     set %barkcnt %barkcnt + #findstack
     menu set barkcnt %barkcnt
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 repeat
   finditem %switch C_ , #backpackid
   if #findcnt > 0
   {
     set %switchcnt %switchcnt + #findstack
     menu set switchcnt %switchcnt
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 repeat
   finditem %parasitic C_ , #backpackid
   if #findcnt > 0
   {
     set %paracnt %paracnt + #findstack
     menu set paracnt %paracnt
     gosub dragdrop #findid #findstack %secure
   }
 until #findcnt < 1
 menu Font Size 8
 menu Font Style
 gosub timer
return
;======= end sub =======


;======= Get Checks Sub =======
sub getchks
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 menu get runenumberedit
 if #menures = 0
 {
   Display You must select a valid runenumber for you secure
   return #false
 }
 set %homerune #menures
 menu get weight_edit
 set %weight_offset #menures
 menu get bankchk
 if #menures
   set %bank #true
 menu get travelcombo
 if #menures = 0
 {
   if SJ notin %travel && RE notin %travel
   {
     Display You need to select a travel method
     set #menubutton N/A
   return #false
   }
 }
 if #menures = 1
   set %travel RE
 if #menures = 2
   set %travel SJ
return #true
;======= End Sub =======

;======= addtree_button sub =======
sub addtree_button
 menu get booklist
 if #menures > 0
 {
   set %addedcnt %addedcnt + 1
   set %book . %addedcnt %booklist . #menures
   menu get runenumber
   set %runenumber #menures
   gosub addtree
   menu list add addedlist tree_x: , #spc , %treex . %addedcnt , #spc , tree_y: , #spc , %treey . %addedcnt , #spc , tree_z: , #spc , %treez . %addedcnt , #spc , rune: , #spc , %treerune . %addedcnt
 }
 else
   Display You must select the tree runebook to use from the list on the left
 set #menubutton N/A
return
;======= end sub =======

;======= homebook_button sub =======
sub homebook_button
 event SysMessage Target your homebook
 set #targcurs 1
 while #targcurs = 1
   wait
 set %homebook #ltargetid
 menu set home_edit %homebook
 set #menubutton N/A
return
;======= end sub =======

;======= addbook_button =======
sub addbook_button
 event SysMessage Target a tree runebook
 set #targcurs 1
 while #targcurs = 1
   wait
 set %bookcnt %bookcnt + 1
 set %booklist . %bookcnt #ltargetid
 menu list add booklist %booklist . %bookcnt
 set #menubutton N/A
return
;======= end sub =======



;======= secure_button sub =======
sub secure_button
 menu get bankchk
 if #menures = #true
 {
   repeat
     event macro 1 0 Bank
     gosub neogumpwait container_gump 180_240
   until #result = #true
 }
 event SysMessage Target your secure
 set #targcurs 1
 while #targcurs = 1
   wait
 set %secure #ltargetid
 menu set secure_edit %secure
 set #menubutton N/A
return
;======= end sub =======

;======= Convert logs to boards =======
sub logs2boards
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 menu set status_label Converting , #spc , logs , #spc , to , #spc , boards.
 finditem %axe C_
 set #lobjectid #findid
 repeat
   finditem %logs C_ , #backpackid
   set #ltargetid #findid
   set #ltargetkind 1
   event macro 17
   target
   event macro 22
   wait 20
 until #findcnt < 1
return
;====== End Sub =======


;======= chop sub =======
sub chop
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 set %x %1
 set %y %2
 set %z %3
 set %tile %4
 set %kind %5
 menu set status_label Checking , #spc , weight.
 gosub XIIxMaxWeight %weight_offset
 if #weight >= #result
 {
   finditem %boards C_ , #backpackid
   if #findcnt > 0
   {
     set %tempx #charposx
     set %tempy #charposy
     set %tempz #charposz
     gosub dropoff
     menu set status_label Traveling , #spc , back , #spc , to , #spc , last , #spc , tree.
     repeat
       gosub neotravel %book . %n %treerune . %n %travel 10
     until #result
     gosub pathfind %tempx %tempy %tempz
     if #result
     {
       gosub pathfinding %spotx . %n %spoty . %n %spotz . %n
       return
     }
   }
   if #findcnt < 1
     gosub logs2boards
 }
 gosub TM_AdvJournalSync chopping
 menu set status_label Weight , #spc , OK! , #spc , Chopping , #spc , tree.
 set #ltargetx %x
 set #ltargety %y
 set #ltargetz %z
 set #ltargettile %tile
 set #ltargetkind %kind
 finditem %axe C_ , #charid
 if #findkind = -1
 {
   finditem %axe C_ , #backpackid
   exevent drag #findid
   wait %dragwait
   exevent droppd
   wait %dropwait
 }
 set #lobjectid #findid
 repeat
   event macro 17
   target
   gosub timeout #targcurs <> 1
 until #result
 event macro 22
 wait 20
 gosub TM_AdvJournalScan chopping VALID_ADVANCE %error1 %error2 %error3 %error4 %error5 %error6 %error7 %error8
 if #result = #true
 {
   set %nexttree #true
   return
 }
 else
   return
return
;======= end sub =======

;======= sub timeout =======
sub timeout
 namespace push
 namespace local timeout
 set !1 %1
 set !2 %2
 set !3 %3
 set !timeout ( #scnt + 3 )
 while !1 !2 !3
 {
   if !timeout <= #scnt
   {
     namespace pop
     return #false
   }
 }
 namespace pop
return #true
;======= end sub =======

;======= pathfind sub =======
sub pathfind
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 event PathFind %1 %2 %3
 wait 10
 gosub TM_AdvJournalScan pathfind ADVANCE_VALID pathfinding
return #result
;======= end sub =======

;======= pathfinding sub =======
sub pathfinding
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 set %timeout ( #scnt + 10 )
 while #charposx <> %1 || #charposy <> %2 || #charposz <> %3
 {
   if %timeout <= #scnt
     return #false
 }
return #true
;======= end sub =======

;======= Timer Sub =======
sub timer
 if #menubutton = CLOSED
 {
   display Menu closed. Halting.
   halt
 }
 if #menubutton = pause_button
 {
   menu set status_label Paused. , #spc , Click , #spc , to , #spc , resume
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button resume_button 129 266 91 25 Resume
   repeat
   until #menubutton = resume_button
   menu delete pause_button
   menu font Color Black
   menu Font BGColor BtnFace
   menu Button pause_button 129 266 91 25 Pause
 }
 set %currenttime #scnt
 set %time %currenttime - %starttime
 set %hh %time / 3600
 set %rest1 %time % 3600
 set %minutes %rest1 / 60
 if %minutes < 10
   set %mm 0 , %minutes
 else
   set %mm %minutes
 set %seconds %rest1 % 60
 if %seconds < 10
   set %ss 0 , %seconds
 else
   set %ss %seconds
 set %runtime %hh , h , : , %mm , m , : , %ss , s
 menu set runtime %runtime
 set %logshour ( %totalcnt * 3600 ) / %time
 menu set logshour %logshour
return
;======= end sub =======

;======= menu sub =======
sub menu
 menu Clear
    menu Window Title neo's Ter Mur Area Lumberjack
    menu Window Color BtnFace
    menu Window Size 452 405
    menu Font Transparent #true
    menu Font Align Right
    menu Font Name Arial
    menu Font Size 8
    menu Font Style
    menu Font Color WindowText
    menu Font Transparent #false
    menu Font Align Left
    menu Text EUOLabel4 20 12 Travel Method:
    menu Text EUOLabel2 20 260 Secure
    menu Text EUOLabel6 20 64 Rune Books
    menu Text EUOLabel1 20 128 Tree books list
    menu Font Name MS Sans Serif
    menu Text EUOLabel5 184 16 Stand on the spot where you can chop
    menu Text EUOLabel7 184 32 the tree, input the rune number for
    menu Text EUOLabel8 184 48 the tree you're adding, and click 'Add'
    menu Font Name Arial
    menu Text EUOLabel9 20 80 Home/Bank
    menu Text runenumberlabel 20 112 Rune number of secure
    menu Font Size 9
    menu Font Style b
    menu Text EUOLabel3 20 376 Status
    menu Font Color Red
    menu Text status_label 64 376 Idle
    menu Font Size 8
    menu Font Style
    menu Font Color WindowText
    menu Text EUOLabel11 20 96 book
    menu Text EUOLabel12 20 240 Set your secure container below
    menu Font Name MS Sans Serif
    menu Text EUOLabel13 188 304 If you don't know what you're doing
    menu Text EUOLabel10 188 288 Input the max weight offset in this box.
    menu Text EUOLabel14 188 320 just leave it at 61
    menu Text EUOLabel15 184 64 Also, make sure you have the correct
    menu Text EUOLabel16 184 80 runebook selected from the "Tree
    menu Text EUOLabel17 184 96 books list", before clicking 'Add'
    menu Font Name Arial
    menu Button start_button 348 368 91 25 Start Chopping
    menu Font BGColor Window
    menu Combo Create travelcombo 20 32 149
    menu Combo Add travelcombo Recall
    menu Combo Add travelcombo Sacred Journey
    menu List Create addedlist 184 112 249 133
    menu Edit runenumber 372 88 25
    menu Font BGColor BtnFace
    menu Button addtree_button 400 88 31 21 Add
    menu Font BGColor Window
    menu Edit secure_edit 88 260 45 %secure
    menu Font BGColor BtnFace
    menu Button secure_button 140 260 31 21 Set
    menu Button save_button 20 320 71 21 Save Setup
    menu Button load_button 20 340 71 21 Load Setup
    menu Button remove_button 252 248 91 21 Remove Selected
    menu Button addbook_button 140 216 31 21 Add
    menu Font BGColor Window
    menu Edit home_edit 88 80 45 %homebook
    menu Font BGColor BtnFace
    menu Button homebook_button 140 80 31 21 Set
    menu Button reset_button 348 248 83 21 Reset
    menu Check bankchk 20 284 153 29 #false Check this box if your secure is at the bank
    menu Font BGColor Window
    menu Edit runenumberedit 144 104 25 %homerune
    menu List Create booklist 20 144 153 69
    menu Font BGColor BtnFace
    menu Button removebook_button 20 216 47 21 Remove
    menu Font BGColor Window
    menu Edit weight_edit 372 288 29 61
    menu Show
return
;======= end sub =======

;======= sub statsmenu =======
sub statsmenu
 menu Clear
    menu Window Title neo's Ter Mur Area Lumberjack
    menu Window Color BtnFace
    menu Window Size 342 301
    menu Font Transparent #true
    menu Font Align Right
    menu Font Name Arial
    menu Font Size 10
    menu Font Style b
    menu Font Color WindowText
    menu Font Transparent #false
    menu Font Align Left
    menu Text EUOLabel3 119 8 Statistics
    menu Text EUOLabel10 28 60 Wood Types
    menu Font Color $005281B3
    menu Text EUOLabel11 28 80 Plain
    menu Font Color $0021657F
    menu Text EUOLabel12 28 100 Oak
    menu Font Color $00659999
    menu Text EUOLabel13 28 120 Ash
    menu Font Color $00004C81
    menu Text EUOLabel14 28 140 Yew
    menu Font Color $00151778
    menu Text EUOLabel16 28 160 Blood
    menu Font Color $000A430A
    menu Text EUOLabel17 28 180 Heart
    menu Font Color $00AEAF81
    menu Text EUOLabel18 28 200 Frost
    menu Font Color WindowText
    menu Text EUOLabel19 184 60 Other Stuff
    menu Font Color $000B1F2E
    menu Text EUOLabel20 184 180 Switch
    menu Font Color $00657587
    menu Text EUOLabel21 184 120 Bark Fragment
    menu Font Color $00949B9F
    menu Text EUOLabel22 184 140 Fungi
    menu Font Color $00007B52
    menu Text EUOLabel23 184 160 Parasitic
    menu Font Color $0000DCDC
    menu Text EUOLabel24 184 100 Amber
    menu Font Color $00BFAC4D
    menu Text EUOLabel25 184 80 Crystal Shards
    menu Font Color WindowText
    menu Text normalcnt 95 80 %normalcnt
    menu Text oakcnt 95 100 %oakcnt
    menu Text ashcnt 95 120 %ashcnt
    menu Text yewcnt 95 140 %yewcnt
    menu Text bloodcnt 95 160 %bloodcnt
    menu Text heartcnt 95 180 %heartcnt
    menu Text frostcnt 95 200 %frostcnt
    menu Text crystalcnt 293 80 %crystalcnt
    menu Text ambercnt 293 100 %ambercnt
    menu Text barkcnt 293 120 %barkcnt
    menu Text fungicnt 293 140 %fungicnt
    menu Text paracnt 293 160 %paracnt
    menu Text switchcnt 293 180 %switchcnt
    menu Font Size 9
    menu Text logshourlabel 44 36 Logs/Hour:
    menu Font Size 10
    menu Text logshour 122 36 %logshour
    menu Font Size 9
    menu Text EUOLabel1 28 224 Status
    menu Text runlabel 28 244 Time Running:
    menu Font Color Red
    menu Text status_label 72 224 Idle
    menu Font Color WindowText
    menu Text runtime 116 244 %runtime
    menu Font Size 8
    menu Font Style
    menu Button pause_button 129 266 91 25 Pause
    menu Show
return
;======= end sub =======

;======= Other People's Stuff =======
;####################
;SUB XIIxMaxWeight
;####################
; %1 = Maxweight offset
sub XIIxMaxWeight
 Namespace Push
 Namespace Local nsXIIxMaxWeight
 set !offset %1
 If #maxweight = N/A
 {
   event macro 8 2
   wait 5
   event macro 10 2
 }

 set !MaxWeight #MaxWeight

 finditem #CHARID
 if #findtype NOTIN AV_XU_OCB_NCB ;char is human
   set !MaxWeight !MaxWeight + 60

 if !MaxWeight > 550
   set !MaxWeight 550 ;Backpack maximum

 set !MaxWeight !MaxWeight - !offset ;Adjust as see fit for overfull buffer
 set #RESULT !MaxWeight
 Namespace pop
Return #RESULT
;======= end sub =======

;===================================================================================
; Script Name: neo's Runebook Travel Sub
; Author: neo
; Version: 0.2
; Client Tested With: 7.0.16.3
; EUO version tested with: 1.50 199
; Shard OSI / FS: OSI
; Revision Date: 09/08/2011
; Public Release: N/A
; Purpose: Uses recall or sacred journey to travel from selected runebook
;-----------------------------------------------------------------------------------
; Instructions:  Just call this sub with the four needed parameters:
;                - Rune book ID: ID of your rune book
;                - Rune number: 1-16
;                - Method: RE for recall, SJ for SJ
;                - Timeout: number in seconds of time to wait after attempting to recall
;                  to return #false in case position hasn't changed.
;
; Example:       gosub neotravel %runebookid 10 RE 5
;                -> Will attempt to travel from %runebookid, rune number 10, using
;                   Recall. If after 5 seconds the position hasn't changed, #false
;                   will be returned.
;----------------------------------------------------------------------------------------
;======= neotravel sub =======
sub neotravel
 if ( %0 <> 4 || %2 < 1 || %2 > 16 || %3 notin RE_SJ )
   return #false
 namespace push
 namespace local neotravel
 set !_runebook %1
 set !_runenumber %2
 set !_method %3
 set !_wait %4
 if #contname = generic_gump && #contsize = 452_236
 {
   set !closex #contposx + 250
   set !closey #contposy + 100
   click !closex !closey r f dmc
   wait 5
 }
 set !location #charposx , _ . #charposy
 repeat
   set #lobjectid !_runebook
   event macro 17
   gosub neogumpwait generic_gump 452_236
   if #result = #false
   {
     event macro 9 7
     wait 1
     nextCPos 776 577
     event macro 8 7
     gosub gumpwait container_gump N/A #backpackid
     wait 15
   }
 until #result
 set !contposx #contposx
 set !contposy #contposy
 wait 5
 set !page ( !_runenumber / 2 ) + ( !_runenumber % 2 )
 set !page_start 105
 set !page_y 197
 set !page_x ( !page_start + ( !page * 35 ) )
 if !page > 4
   set !page_x !page_x + 30
 set !travel_x 140
 if ( !_runenumber % 2 ) = 0
   set !travel_x !travel_x + 160
 if !_method = RE
   set !travel_y 145
 if !_method = SJ
   set !travel_y 180
 set !x !contposx + !page_x
 set !y !contposy + !page_y
 click !x !y f dmc
 wait 5
 gosub TM_AdvJournalSync neotravel 100
 set !x !contposx + !travel_x
 set !y !contposy + !travel_y
 click !x !y f dmc
 repeat
 until !_runebook <> #contid
 set !timeout #scnt + !_wait
 repeat
   set !newlocation #charposx , _ . #charposy
   gosub TM_AdvJournalScan neotravel VALID Something_is_blocking is_blocked
   if #result = #true
   {
     namespace pop
     return blocked
   }
   gosub TM_AdvJournalScan neotravel VALID not_yet_recovered time_to_recharge
   if #result = #true
   {
     namespace pop
     wait 40
     return #false
   }
   gosub TM_AdvJournalScan neotravel VALID spell_fizzles
   if #result = #true
   {
     namespace pop
     wait 30
     return fizzle
   }
 until !newlocation <> !location || #scnt > !timeout
 if !newlocation <> !location
 {
   namespace pop
   return #true
 }
 namespace pop
return #false
;======= end sub =======

;======= neoGumpwait Sub =======
sub neogumpwait
namespace push
namespace local neogumpwait
set !contname %1
set !contsize %2
set !timeout #SCNT + 5
if !contsize = null
  {
  repeat
  until #contname = !contname || #scnt >= !timeout
     {
     if #contname = !contname
        {
        namespace pop
        return #true
        }
     namespace pop
     return #false
     }
  }
repeat
until ( #contname = !contname && #contsize = !contsize ) || #scnt >= !timeout
if #contname = !contname && #contsize = !contsize
  {
  namespace pop
  return #true
  }
namespace pop
return #false
;======= End Sub =======

;======= Gumpwait Sub =======
sub gumpwait
 namespace push
 namespace local gumpwait
 set !name %1
 set !size %2
 set !id %3
 set !condcnt 0
 set !nameyes #true
 set !sizeyes #true
 set !idyes #true
 set !timeout #SCNT + 5
 if !name = N/A
 {
   set !condcnt !condcnt + 1
   set !nameyes #false
 }
 if !size = N/A
 {
   set !condcnt !condcnt + 1
   set !sizeyes #false
 }
 if !id = N/A
 {
   set !condcnt !condcnt + 1
   set !idyes #false
 }
 repeat
   if #contname = !name && !nameyes = #true
   {
     set !condcnt !condcnt + 1
     set !nameyes #false
   }
   if #contsize = !size && !sizeyes = #true
   {
     set !condcnt !condcnt + 1
     set !sizeyes #false
   }
   if #contid = !id && !idyes = #true
   {
     set !condcnt !condcnt + 1
     set !idyes #false
   }
 until !condcnt = 3 || #scnt > !timeout
 if !condcnt = 3
 {
   namespace pop
   return #true
 }
 namespace pop
return #false
;======= End Sub =======

;=================================================================
; Script Name: TrailMyx's Advanced Journal Scanner
; Author: TrailMyx
; Version: 1.1
; Shard OSI / FS: OSI / FS?
; Revision Date: 10/20/2007
; Purpose:
;   Use these subs to quickly find text in your #journal entries.  These subs
; use #jindex for flawless journal scanning and is much more reliable than using
; standard indexing of #journal and #SYSMSG.
;
;   Now it is possible to manage separate journals based on unrelated text.  It's now possible
; to monitor spellcasting, bandaging, stealing, or anything else without a TM_AdvJournalSync
; potentially removing text needed for another UO funciton.
;
;   New is the ability to either gosub or call these functions without the need to change the
; header!  When calling, a limit of 10 arguments is allowed, but more can be added by editing the
; call interface section.
;
;  Examples:
;     gosub TM_AdvJournalSync speech 100 ; sync "speech" journal space, set #LPC to 100 from default of 1000
;     gosub TM_AdvJournalScan speech VALID Find_this_text and_find_this_too ; will not advance copy of #jindex
;     gosub TM_AdvJournalScan heal VALID_ADVANCE you_heal_what that_patient_is_not ; advances pointer after scan
;     gosub TM_AdvJournalScan spellcast NONE fizzle ; no spam checking and doesn't advance #jindex copy automatically
;
;  Subs included:
;     TM_AdvJournalSync - Must call this in initialzation
;     TM_AdvJournalScan - see header for details....
;
;  Release history:
;    v1.0 - Initial release.
;    v1.1 - debug code added, fixed small possibility to miss an incoming journal entry
;
;  Requirements:
;    Nothing special
;
;  Credit:
;    If you use these subs, please leave credit for me somewhere in your script header.
;=================================================================
;------------------------  Call interface  -----------------------
;=================================================================
set !TM_FunctionCalled #FALSE
if %0 = 1
 gosub %1
if %0 = 2
 gosub %1 %2
if %0 = 3
 gosub %1 %2 %3
if %0 = 4
 gosub %1 %2 %3 %4
if %0 = 5
 gosub %1 %2 %3 %4 %5
if %0 = 6
 gosub %1 %2 %3 %4 %5 %6
if %0 = 7
 gosub %1 %2 %3 %4 %5 %6 %7
if %0 = 8
 gosub %1 %2 %3 %4 %5 %6 %7 %8
if %0 = 9
 gosub %1 %2 %3 %4 %5 %6 %7 %8 %9
if %0 = 10
 gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10
if %0 = 11
 gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11
if %0 > 11
{
 display ok Too many arguments for "call", edit file.
 stop
}

if !TM_FunctionCalled = #TRUE
 exit
if %0 = N/A
 display ok You may not run this script directly.
else
 display ok Function " , %1 , " not found.
stop
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
; %1 - Journal Name
; %2 - #LPC setting (optional)
; Brings !_jindex up to the most recent #journal entry
sub TM_AdvJournalSync
 namespace push
 namespace local TM_AdvJS_ , %1
 set !_jindex #jindex + 1
 if %0 > 1
   set !lpc_set %2
 namespace pop
 set !TM_FunctionCalled #TRUE
return
;-------------------------------------------------------------------------------
; %1 - Journal Name
; %2 - NONE, ADVANCE , ( _VALID ) - advances jindex pointer, anything else
; %3, %4, %5, etc strings to match
; returns #TRUE for match, #FALSE for no match
;  Will not advance !_jindex pointer to allow for scanning journal history for more than one search.
;  Also searches for : , #SPC in journal entry to be sure someone isn't spamming the text
;  About %2 arguments:
;    NONE: defaults to basic journal scan (no SPAM checking, no #jindex pointer copy advancing)
;    ADVANCE: no spam checking, advances #jindex copy
;    VALID: invokes SPAM filtering, no advance of #jindex copy
;    VALID_ADVANCE, VALIDADVANCE, ADVANCE_VALID, etc.: invokes SPAM filtering, advances of #jindex copy
sub TM_AdvJournalScan
 namespace push
 namespace local TM_AdvJS_ , %1
 set !args %2
 set !temp_lpc #LPC
 if !lpc_set = N/A
   set #LPC 1000
 else
   set #LPC !lpc_set
 set !num_args %0
 set !first_arg 3
 set !sampled_jindex #JINDEX
 if !_jindex = N/A
   set !_jindex !sampled_jindex
 if !charname = N/A
 {
   set !charname #CHARNAME
AdvJournalScan_loop1:
   str pos !charname #SPC
   if #STRRES <> 0
   {
     set !val #STRRES - 1
     str left !charname !val
     set !left #STRRES
     set !val !val + 1
     str del !charname 1 !val
     set !charname !left , _ , #STRRES
     goto AdvJournalScan_loop1
   }
 }
 set !index !first_arg
 repeat
   set !temp_jindex !_jindex
   set !text % . !index
   while !temp_jindex <= !sampled_jindex
   {
     scanjournal !temp_jindex
     str pos #JOURNAL !charname 1
     set !namepos #STRRES
     str count #JOURNAL !charname
     set !namecnt #STRRES
     str pos #JOURNAL :_ 1
     set !smcpos #STRRES
     str pos #JOURNAL !text 1
     set !textpos #STRRES
     if !textpos < !smcpos && !smcpos <> 0 || !smcpos = 1 || :_ notin #JOURNAL || VALID notin !args
       set !pass #TRUE
     else
       set !pass #FALSE
     if ( !text in #journal && ( ( !namepos = 1 && !namecnt <= 1 ) || !pass ) )
     {
       set !temp_jindex !temp_jindex + 1
       if ADVANCE in !args
         set !_jindex !temp_jindex
       set #LPC !temp_lpc
       namespace pop
       set !TM_FunctionCalled #TRUE
       return #TRUE
     }
     set !temp_jindex !temp_jindex + 1
   }
   set !index !index + 1
 until !index - !first_arg > !num_args - !first_arg
 set %10 !sampled_jindex - !_jindex
 set %10 %1 , _ , %10 ; for debugging purposes
 set #LPC !temp_lpc
 namespace pop
 set !TM_FunctionCalled #TRUE
return #FALSE

;============================================================
; Script Name: TrailMyx's Next Generation File System (TM_NGFS)
; Author: TrailMyx
; Version: 0.3
; Shard OSI / FS: Any
; Revision Date: 8/1/2010
; Purpose:
;     This powerful set of routines fully automates the script author's ability to save and restore large amounts of data
;   to the Windows registry.  These functions allow you to save/restore data to local/global namespaces as well.
;
; Limitations:
;     .  Not yet able to save data sets to file.
;
; Functions:
;     TM_NGFS_InitializeScript
;     TM_NGFS_RegisterVariables
;     TM_NGFS_SaveVariables
;     TM_NGFS_LoadVariables
;     TM_NGFS_DoesSaveExist
;     TM_NGFS_DeleteName
;     TM_NGFS_ForceDelete
;     TM_NGFS_GetFSIndexVal
;
; Support functions (internal use for TM_NGFS):
;     TM_ReadVariables
;     AddUnderscore
;     AddSpace
;
; Example code:
;    gosub TM_NGFS_InitializeScript test_script
;    set !test 25
;    set !this 35
;    set !variable 45
;    set %newvar another_value
;    ;gosub TM_NGFS_RegisterVariables local std test this variable ; local:std namespace Notice you can register more than one per line!
;    gosub TM_NGFS_RegisterVariables test_script local std test ; from local:std !test
;    gosub TM_NGFS_RegisterVariables test_script local std this ; from local:std !this
;    gosub TM_NGFS_RegisterVariables test_script local std variable ; from local:std !variable
;    gosub TM_NGFS_RegisterVariables test_script std std newvar  ; denotes a %var
;    gosub TM_NGFS_SaveVariables test_script
;    stop
;    -----------------------------------
;    gosub TM_NGFS_DoesSaveExist new_script2
;    if #RESULT = #TRUE
;      display ok new_script2 save exists
;    gosub TM_NGFS_DoesSaveExist new_script2 generic
;    if #RESULT = #TRUE
;      display ok new_script2 generic save exists
;    stop
;    -----------------------------------
;    gosub TM_NGFS_InitializeScript test_script
;    gosub TM_NGFS_LoadVariables test_script
;    stop
;
;============================================================
; Revision History:
;   v0.1 - Released to Elites to play with
;   v0.2 - internal debug version
;   v0.3 - added TM_NGFS_DeleteName, TM_NGFS_ForceDelete, TM_NGFS_GetFSIndexVal
;          Also added warnings when TM_FS is not initialized correctly; just for 12X
;------------------------  Call interface  -----------------------
;=================================================================

set !TM_FunctionCalled #FALSE
if %0 = 1 && !TM_FunctionCalled = #FALSE
 gosub %1
if %0 = 2 && !TM_FunctionCalled = #FALSE
 gosub %1 %2
if %0 = 3 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3
if %0 = 4 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4
if %0 = 5 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5
if %0 = 6 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5 %6
if %0 = 7 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5 %6 %7
if %0 = 8 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5 %6 %7 %8
if %0 = 9 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5 %6 %7 %8 %9
if %0 = 10 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10
if %0 = 11 && !TM_FunctionCalled = #FALSE
 gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11
if %0 > 11
{
 display ok Too many arguments for "call", edit the call header.
 stop
}

if !TM_FunctionCalled = #TRUE ; successfully called function.
 exit
if %0 = N/A
 display ok You may not run this script directly.
else
 display ok Function " , %1 , " not found.
stop
;--------------------------------------------------------------------
;---------------------  Base User Functions -------------------------
;--------------------------------------------------------------------
; TM_NGFS_InitializeScript
; %1 - ScriptName
; %2 = (opt) generic : add this tag to create a generic (non-character relative data set)
sub TM_NGFS_InitializeScript
 namespace push
 namespace local TM_NGFS , _ , %1
 namespace clear
 set !lpc #LPC
 set #LPC 10000
 if %0 = 0
 {
   display ok You must name your script, spaces will be converted to underscores.
   stop
 }
 set !TM_FSSIZE 1000 ; do not change this!!
 set !script_name %1
 set !args %0
 gosub AddUnderscore !script_name
 set !script_name #RESULT
 if !args = 1
 {
   gosub AddUnderscore #SHARD
   set !slot #CHARID , _ , #RESULT , _ , !script_name , _vars
 }
 else
 {
   set !slot generic , _ , !script_name , _vars
 }
 set ! . !slot
 set !varcnt 0
 set !index 0
 set !script_index N/A
 while *TM_FS . !index <> N/A
 {
   if *TM_FS . !index = !slot
   {
     set !script_index !index
     break
   }
   set !index !index + 1
 }
 if !script_index = N/A
 {
   set !script_index !index
   set *TM_FS . !script_index !slot
 }
 set #LPC !lpc
 namespace pop
 set !TM_Function_found #TRUE
return
;--------------------------------------------------------------------
; TM_NGFS_RegisterVariables
; %1 - ScriptName
; %2 - NSType (local, global, std)  --> std is a %var
; %3 - NSName (std) --> std is a %var
; %4, %5, %6, etc. variable names (don't include the % or ! - so %var becomes var, etc)
sub TM_NGFS_RegisterVariables
 if %0 <= 3
 {
   display ok Not enough arguments
   stop
 }
 namespace push
 namespace local TM_NGFS , _ , %1
 if !slot = N/A
 {
   display ok You must name your script and also run TM_NGFS_InitializeScript first.
   stop
 }
 set !nstype %2
 set !nsname %3
 for !i 4 %0
 {
   set !var % . !i
   if !nstype ,  , !nsname ,  , !var notin ! . !slot
   {
     set !newval ! . !slot
     set ! . !slot !newval , !nstype ,  , !nsname ,  , !var , 
     set !varcnt !varcnt + 1
   }
 }
 namespace pop
 set !TM_Function_found #TRUE
return
;--------------------------------------------------------------------
; TM_NGFS_SaveVariables
; %1 - ScriptName
; assuming you have registered the variables, then everything will be saved in one call
sub TM_NGFS_SaveVariables
 if %0 = 0
 {
   display ok You must name your script, spaces will be converted to underscores.
   stop
 }
 namespace push
 namespace local TM_NGFS , _ , %1
 if !TM_FSSIZE = N/A
 {
   display ok You must first call TM_NGFS_InitializeScript and have$registered variables with TM_NGFS_RegisterVariables - STOPPING.
   stop
 }
 set !lpc #LPC
 set #LPC 10000
 set !outstring
 set !start 1
 set !sepcnt 1
 set !line_count 0
 set !temp_str ! . !slot

 for !i 1 !varcnt
 {
   gosub ReadItem ! . !slot
   set !nstype #RESULT
   gosub ReadItem ! . !slot
   set !nsname #RESULT
   gosub ReadItem ! . !slot
   set !var #RESULT
   if std in !nstype
   {
     set !val % . !var
   }
   else
   {
     namespace copy !var from !nstype !nsname
     set !val ! . !var
   }
   set !outstring !outstring , !nstype ,  , !nsname ,  , !var ,  , !val , 
   str len !outstring
   if #STRRES >= !TM_FSSIZE
   {
     set * . !slot , !line_count !outstring
     set !outstring
     set !line_count !line_count + 1
     set !start !start - 1
     str del ! . !slot 1 !start
     set ! . !slot #STRRES
     set !start 1
     set !sepcnt 1
   }
 }
 str len !outstring
 if #STRRES > 0
 {
   set * . !slot , !line_count !outstring
   set !line_count !line_count + 1
 }
 set * . !slot , !line_count N/A ; make sure there's nothing left at end of the list
 set #LPC !lpc
 set ! . !slot !temp_str
 namespace pop
 set !TM_Function_found #TRUE
return
;--------------------------------------------------------------------
; TM_NGFS_LoadVariables
; %1 - ScriptName
; note you have to call TM_NGFS_InitializeScript
sub TM_NGFS_LoadVariables
 if %0 = 0
 {
   display ok You must name your script, spaces will be converted to underscores.
   stop
 }
 namespace push
 namespace local TM_NGFS , _ , %1
 if !TM_FSSIZE = N/A
 {
   display ok You must first call TM_NGFS_InitializeScript - STOPPING.
   stop
 }
 set !lpc #LPC
 set #LPC 10000
 set !start 1
 set !sepcnt 1
 set !line_count 0
 set !temp !slot , !line_count
 set !string * . !temp
 set ! . !slot
 set !varcnt 0
 set !continue #TRUE
 while !continue = #TRUE
 {
   gosub ReadItem !string
   if !continue = #TRUE
   {
     set !nstype #RESULT
     gosub ReadItem !string
     set !nsname #RESULT
     gosub ReadItem !string
     set !var #RESULT
     gosub ReadItem !string
     set !val #RESULT
     if std in !nstype
     {
       set % . !var !val
     }
     else
     {
       set ! . !var !val
       namespace copy !var to !nstype !nsname
     }
     set !newval ! . !slot
     set ! . !slot !newval , !nstype ,  , !nsname ,  , !var , 
     set !varcnt !varcnt + 1
   }
   if !continue = #FALSE
   {
     set !line_count !line_count + 1
     set !temp !slot , !line_count
     set !string * . !temp
     set !start 1
     set !sepcnt 1
     if !string <> N/A
       set !continue #TRUE ; still more to process
   }
 }
 set #LPC !lpc
 namespace pop
 set !TM_Function_found #TRUE
return
;--------------------------------------------------------------------
; Used internally
sub ReadItem
 str pos %1  !sepcnt
 if #STRRES <> 0
 {
   set !len #STRRES - !start
   str mid %1 !start !len
   set !start !start + !len + 1
   set !sepcnt !sepcnt + 1
   return #STRRES
 }
 set !continue #FALSE
return #TRUE
;--------------------------------------------------------------------
; Used internally
; %1 - string to mung
sub AddUnderscore
 namespace push
 namespace local AU
 set !tempstring %1
AddUnderscore_loop1:
 str pos !tempstring #SPC
 if #STRRES <> 0
 {
   set !val #STRRES - 1
   str left !tempstring !val
   set !left #STRRES
   set !val !val + 1
   str del !tempstring 1 !val
   set !tempstring !left , _ , #STRRES
   goto AddUnderscore_loop1
 }
 set #RESULT !tempstring
 namespace pop
return #RESULT
;--------------------------------------------------------------------
;----------------  Advanced File System Functions -------------------
;--------------------------------------------------------------------
; TM_NGFS_DoesSaveExist
; %1 - ScriptName
; #RESULT = #TRUE - exists, #FALSE - doesn't exist
; note: this is relative to the current character.
sub TM_NGFS_DoesSaveExist
 namespace push
 namespace local TM_NGFS , _ , %1
 set !lpc #LPC
 set #LPC 10000
 set !script_name %1
 set !args %0
 gosub AddUnderscore !script_name
 set !script_name #RESULT
 if !args = 1
 {
   gosub AddUnderscore #SHARD
   set !tempslot #CHARID , _ , #RESULT , _ , !script_name , _vars
 }
 else
 {
   set !tempslot generic , _ , !script_name , _vars
 }
 set !index 0
 set #RESULT #FALSE
 while *TM_FS . !index <> N/A
 {
   if *TM_FS . !index = !tempslot
   {
     set #RESULT #TRUE
     break
   }
   set !index !index + 1
 }
 set #LPC !lpc
 namespace pop
 set !TM_Function_found #TRUE
return #RESULT
;--------------------------------------------------------------------
; TM_NGFS_DeleteName
; %1 = script name tag
; %2 = (opt) generic : add this tag to create a generic (non-character relative data set)
; note: this will also clean up the data stored within the data set
sub TM_NGFS_DeleteName
 namespace push
 namespace local TM_NGFS , _ , %1
 set !lpc #LPC
 set #LPC 10000
 set !script_name %1
 set !args %0
 gosub AddUnderscore !script_name
 set !script_name #RESULT
 if !args = 1
 {
   gosub AddUnderscore #SHARD
   set !tempslot #CHARID , _ , #RESULT , _ , !script_name , _vars
 }
 else
 {
   set !tempslot generic , _ , !script_name , _vars
 }
 set !index 0
 set #RESULT #FALSE
 set !start #FALSE
 while *TM_FS . !index <> N/A
 {
   if *TM_FS . !index = !tempslot
     set !start #TRUE
   if !start = #TRUE
   {
     set !next !index + 1
     set *TM_FS . !index *TM_FS . !next
   }
   set !index !index + 1
 }
 if !start = #TRUE
 {
   set !index 0
   while !tempslot . !index <> N/A
   {
     set !tempslot . !index N/A
     set !index !index + 1
   }
 }
 set #LPC !lpc
 namespace pop
 set !TM_Function_found #TRUE
return #RESULT
;--------------------------------------------------------------------
; TM_NGFS_ForceDelete
; %1 = Force delete when entire *TM_FSn var value is known - (get from TM_NGFS_GetFSIndexVal)
; full names are made up like this:  XXYYZZ_Shard_ScriptName_vars (XXYYZZ = CHARID, _vars is required)
; note: this will also clean up the data stored within the data set
sub TM_NGFS_ForceDelete
 namespace push
 namespace local TM_NGFS , _ , %1
 set !lpc #LPC
 set #LPC 10000
 set !full_name %1
 set !index 0
 set #RESULT #FALSE
 set !start #FALSE
 while *TM_FS . !index <> N/A
 {
   if *TM_FS . !index = !full_name
     set !start #TRUE
   if !start = #TRUE
   {
     set !next !index + 1
     set *TM_FS . !index *TM_FS . !next
   }
   set !index !index + 1
 }
 if !start = #TRUE
 {
   set !index 0
   while !full_name . !index <> N/A
   {
     set !full_name . !index N/A
     set !index !index + 1
   }
 }
 set #LPC !lpc
 namespace pop
 set !TM_Function_found #TRUE
return #RESULT
;--------------------------------------------------------------------
; TM_NGFS_GetFSIndexVal
; %1 = retrieves the *TM_FSn value.  This will be terminated by N/A at the end of the list
; index value is integer starting at 0 to n
sub TM_NGFS_GetFSIndexVal
 namespace push
 namespace local TM_NGFS , _ , %1
 set #RESULT *TM_FS . %1
 namespace pop
 set !TM_Function_found #TRUE
return #RESULT
;--------------------------------------------------------------------
[Image: bannergateway.png]
 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)