ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: VicVega on May 13, 2009, 06:56:54 AM

Title: Fishing 4x4 Version 0.1 for Public testing
Post by: VicVega on May 13, 2009, 06:56:54 AM
Fishing 4x4

(http://i524.photobucket.com/albums/cc324/duncanHaleck/4x4_fishing.png)

The script works fine but I wanna post it here for a while before posting it on the Submit Your Script (http://www.scriptuo.com/index.php?board=75.0) section, in case anyone has any suggestions about the code and how to improve it.

(http://www.uolegends.net/forums/images/smiles/icon_arrow.gif) Purpose


(http://www.uolegends.net/forums/images/smiles/icon_arrow.gif) Current features


(http://www.uolegends.net/forums/images/smiles/icon_arrow.gif) Version History

new in 0.1  (13/5/09)


(http://www.uolegends.net/forums/images/smiles/icon_arrow.gif) Posible Future Features


(http://www.uolegends.net/forums/images/smiles/icon_arrow.gif) Notes


Quote
Time: 145210
Time fishing: 436 s 7 min
Total time fishing: 2705 s 45 min
Total Steaks: 860
Steaks Gained This Loop: 132
Total Steaks Gained: 860
Steaks Per Hour: 1144
...



Quote
8x8 resource blocks are how UO handles resources that respawn.  Resources don't restock in a tile/tile basis.  So when you just fish in 4x4 blocks around you, you are depleting all possible resources by only fishing in 4 spots!

Actually it works out pretty close actually.  If you fish one 4x4 square to being empty, then the other 3, you are really close to having the resources replenished.  Trust me, I have a couple fishing scripts out there and have been doing the fishing thing for just about the beginning of my scripting life, so I've tweaked it a bunch.  It's all come to successful fishing attempts/hr so if you over-fish an area, you'll waste a lot of time in that same area knowing you won't fish anything up.

(http://www.uolegends.net/forums/images/smiles/icon_arrow.gif) Instructions


Code: [Select]
;=================================================================
; Script Name: Fishing 4x4
; Author: VicVega
; Version: 0.1
; Shard OSI / FS: UO Legends
; Revision Date: 13/5/2009
; Purpose: Fish in a port or a boat till you are overloaded
; Globals: None
;=================================================================
; Instructions:
; You need wearing a pole in the paperdoll, you also need a dagger
; in the backpack.
; %sellFishsteaks - set #true for sell the fish steaks or #false
;                   it's #false by default, you need to add fishSteaks
;                   at the Razor's Sell Agent
; %saveData - set #true for save data in fishing4x4Data.txt or #false
;             it's #true by default
; %boatFishing - set #true for fishing from a boat or #false
;                it's #false by default
;************************ Setup **********************************
gosub setup
;*********************** Main Loop *******************************
repeat
  gosub fishing
  gosub saveData
  gosub moveBoat
  gosub dropBoots
  gosub dropSpecialFishes
until #CharGhost = YES
halt
;************************* Subs **********************************
sub setup
  set %sellFishSteaks #false
  set %saveData #true
  set %boatFishing #false
  set %poleType KDF
  set %daggerType WSF
  set %maxTimeOutScan 15
  set %maxweight 570
  set %totalTimeFishing 0
  set %fishSteaksType IND
  set %forward #true
  finditem %poleType C_ , #charID
  set %poleID #findID
  finditem %daggerType C_ , #backpackID
  set %daggerID #findID
  gosub saveStartingData
return

sub saveData
  if %saveData
  {
    set %loopTime #scnt - %startingLoopTime
    set %totalTimeFishing %totalTimeFishing + %loopTime
    set %loopTimeMinutes %loopTime / 60
    set %totalTimeFishingMinutes %totalTimeFishing / 60
    finditem %fishSteaksType C_ , #backpackID
    set %nSteaks #findStack
    set %nSteaksLoop %nSteaks - %nSteaksStartingLoop
    set %totalSteaks %nSteaks
    set %nSteaks %nSteaks - %nStartingSteaks
    set %steaksPerHour ( %nSteaks * 3600 ) / %totalTimeFishing
    execute SaveTextToFile.Vbs #false #false #curPath fishing4x4Data.txt
    + Time: #time $
    + Time fishing: %loopTime s %loopTimeMinutes min $
    + Total time fishing: %totalTimeFishing s %totalTimeFishingMinutes min $
    + Total Steaks: %totalSteaks $
    + Steaks Gained This Loop: %nSteaksLoop $
    + Total Steaks Gained: %nSteaks $
    + Steaks Per Hour: %steaksPerHour $
  }
return

sub saveStartingData
  if %saveData
  {
    finditem %fishSteaksType C_ , #backpackID
    set %nStartingSteaks #findStack
    set %startingTime #time
    execute SaveTextToFile.Vbs #false #false #curPath fishing4x4Data.txt
    + Starting time: %startingTime $
    + Starting steaks: %nStartingSteaks
  }
return

sub fishing
  gosub startingLoopData
  for %i 1 4
  {
    gosub sellFishSteaks
    gosub fishingSpot
    gosub tileName %1 %2
    event sysmessage %1 %2
    while #result = #true
    {
      gosub usePole
      gosub scan
    }
    gosub cutFish
  }
return

sub moveBoat
  if %boat
  {
    if %forward
    {
      for %k 0 3
      {
        msg forward one $
        wait 2s
        set %forward #false
      }
    }
    else
    {
      for %m 0 11
      {
        msg backwards one $
        wait 2s
        set %forward #true
      }
    }
  }
return

sub startingLoopData
  if %saveData
  {
    finditem %fishSteaksType C_ , #backpackID
    set %nSteaksStartingLoop #findStack
    set %startingLoopTime #scnt
  }
return

sub fishingSpot
  if %i = 1
    gosub setTargets 4 4
  if %i = 2
    gosub setTargets 4 -4
  if %i = 3
    gosub setTargets -4 4
  if %i = 4
    gosub setTargets -4 -4
return

sub setTargets
  set #lTargetKind 2
  set #lTargetX #charPosX + %1
  set #lTargetY #charPosY + %2
return

sub scan
  set %timeout #scnt + %maxTimeOutScan
  set %jrnl #jindex
  scanjournal %jrnl
 
  while #scnt < %timeout
  {
    if %jrnl < #jindex
    {
      set %jrnl %jrnl + 1
      scanjournal %jrnl
    }
    set %spotWithFish fail_to_catch in #journal || pull_out in #journal &&
    set %spotWithoutFish don't_seem_to_be_biting in #journal
    if %spotWithFish
      return #true
    if %spotWithoutFish
      return #false
  }
return

sub UsePole
  set #lTargetZ #tileZ
  set #lObjectID %poleID
  event macro 17
  target
  event macro 22
return

sub tileName
  set %fishingPosX #charPosX + %1
  set %fishingPosY #charPosY + %2
  tile init
  tile cnt %fishingPosX %fishingPosY
  for %j 1 #tilecnt
  {
    tile get %fishingPosX %fishingPosY %j
    set %canFish water in #tileName || jungle in #tileName
    if %canFish
      return #true
  }
return

sub dropSpecialFishes
  set %fishType YDF
  finditem %fishType C_ , #backpackID
  while #findKind <> -1
  {
    exevent drag #findID #findStack
    wait 1s
    exevent dropg #charPosX #charPosY
    wait 1s
    finditem %fishType C_ , #backpackID
  }
return

sub cutFish
  set %fishType FQD_DQD_GQD_EQD
  set #lTargetKind 1
  set #lObjectID %daggerID
  finditem %fishType C_ , #backpackID
  while #findKind <> -1
  {
    set #lTargetID #findID
    event macro 17
    target
    event macro 22
    wait 1s
    finditem %fishType C_ , #backpackID
  }
return

sub dropBoots
  set %bootsType TVI_ZVI_ZVI_PVI_NVI
  finditem %bootsType C_ , #backpackID
  while #findKind <> -1
  {
    exevent drag #findID #findStack
    wait 1s
    exevent dropg #charPosX #charPosY
    wait 1s
    finditem %bootsType C_ , #backpackID
  }
return

sub sellFishSteaks
  set %shouldSellFishSteaks %sellFishSteaks && #weight > #maxWeight
  if %shouldSellFishSteaks = #true
  {
    finditem %fishSteaksType C_ , #backpackID
    if #findKind <> -1
      msg vendor sell $
    wait 1s
    if %saveData
      gosub saveStartingData
  }
  else
  {
    if #weight > %maxWeight
      halt
  }
return
Title: Re: Fishing 4x4 Version 0.1 for Public testing
Post by: Endless Night on May 13, 2009, 08:38:30 AM
Wow its so nice to see nice clean indented code... Im going to start a fisher and give it a twirl just because of that
Title: Re: Fishing 4x4 Version 0.1 for Public testing
Post by: TrailMyx on May 13, 2009, 10:57:35 AM
Here's a couple esthetic suggestions:

Suppose you want to display your skills with the decimal?  So 132 becomes 13.2:

Code: [Select]
; %1 = input - Skill to convert
; #RESULT -  Skill converted to ###.# format
sub ConvertSkill
  namespace push
  namespace local CS
  set !intpart %1 / 10
  set !decpart %1 % 10
  set #RESULT !intpart , #dot , !decpart
  namespace pop
return #RESULT

And the same goes for time:

Code: [Select]
;-------------------------------------------------------------------------------
; %1 = input - Time to convert
; #RESULT -  Time converted to H:MM:SS format
sub ConvertTimeHourMinSec
  namespace push
  namespace local ctime
  set !hourpart %1 / 3600
  set !secpart ( %1 % 3600 ) % 60
  set !minpart ( ( %1 % 3600 ) / 60 )

  if !hourpart >= 10
    set #RESULT !hourpart , :
  else
    set #RESULT 0 , !hourpart , :
  if !minpart < 10
    set #RESULT #RESULT , 0
  set #RESULT #RESULT , !minpart , :
  if !secpart < 10
    set #RESULT #RESULT , 0
  set #RESULT #RESULT , !secpart
  namespace pop
return #RESULT