Author Topic: Looping a mining script  (Read 3356 times)

0 Members and 1 Guest are viewing this topic.

Offline VicVegaTopic starter

  • Jr. Member
  • **
  • Posts: 71
  • Activity:
    0%
  • Reputation Power: 0
  • VicVega has no influence.
  • Respect: +8
  • Referrals: 0
    • View Profile
Looping a mining script
« on: June 03, 2009, 01:27:26 PM »
0
So my mining script it's something like this at the moment (I only post now the significant code, the main loop):

Code: [Select]
repeat
      gosub checkWeight
      gosub recall firstSpot
      gosub mining
      gosub checkWeight
      gosub recall secondSpot
      gosub mining
until #charGhost = yes

Hope somebody gives me an idea how to loop this with less repetitive or redundant code in order to add mining spots and have a code less horrible.
To learn, read.
To know, write.
To master, teach.

Offline rana70

  • Elite
  • *
  • *
  • Posts: 294
  • Activity:
    0%
  • Reputation Power: 5
  • rana70 has no influence.
  • Gender: Male
  • Respect: +37
  • Referrals: 2
    • View Profile
    • MyScripts
Re: Looping a mining script
« Reply #1 on: June 03, 2009, 02:17:54 PM »
0
Hi,

I think you can reduce the main loop.

First .. you have to do the weightcheck while you do mining !
In your loop you would not be able to recall if you digged to much ore .

You don't need the 1st sport, 2nd spot .... stuff,
you mining sub has to decide the most stuff..

your Mining SUB is the most important thing I guess:
you need to make sure it handles ..
- get / create Mining Tools
- check for overweight
- call SUB to travel home for dropoff
- when this mining spot is done ... inc. a counter to prepair the next recall


Main Loop concept
Code: [Select]

repeat
{
      gosub recall to workplace
      gosub mining ; <- does Weightcheck, and sets a marker for next spot to mine or dropoff location
}
until #charGhost = yes

Offline VicVegaTopic starter

  • Jr. Member
  • **
  • Posts: 71
  • Activity:
    0%
  • Reputation Power: 0
  • VicVega has no influence.
  • Respect: +8
  • Referrals: 0
    • View Profile
Re: Looping a mining script
« Reply #2 on: June 04, 2009, 12:29:26 AM »
0
Hi,

I think you can reduce the main loop.

First .. you have to do the weightcheck while you do mining !
In your loop you would not be able to recall if you digged to much ore .

You don't need the 1st sport, 2nd spot .... stuff,
you mining sub has to decide the most stuff..

your Mining SUB is the most important thing I guess:
you need to make sure it handles ..
- get / create Mining Tools
- check for overweight
- call SUB to travel home for dropoff
- when this mining spot is done ... inc. a counter to prepair the next recall


Main Loop concept
Code: [Select]

repeat
{
      gosub recall to workplace
      gosub mining ; <- does Weightcheck, and sets a marker for next spot to mine or dropoff location
}
until #charGhost = yes


Thanks for your advices, I'll study them in order to think a way to improve my code. But I don't really like to complicate my mining sub adding all that stuff inside, but may be you are right and it's a better way.

Quote
First .. you have to do the weightcheck while you do mining !
In your loop you would not be able to recall if you digged to much ore .

I also do a weightCheck while mining, but I also do a check in case there is no more ore. So when mining, the mining sub can exit in two ways: because overweight or because there is no more ore, so I must use the "checkWeight sub"  in oder to know wich one it is and act accordingly.

The complete script at the moment, hope clarify this:

Code: [Select]
gosub setup

sub setup
set %pickAxeType QPF
set %recallType recall
return

repeat
      gosub checkWeight
      gosub recall firstSpot
      gosub mining
      gosub checkWeight
      gosub recall secondSpot
      gosub mining
until #charGhost = yes
halt

sub recall
    if %1 = home
    {
     set %posX 733
     set %posY 720
     set %runeNo 1
    }
    if %1 = firstSpot
    {
     set %posX 1419
     set %posY 3758
     set %runeNo 2
    }
    if %1 = secondSpot
    {
     set %posX 1419
     set %posY 3751
     set %runeNo 3
    }
    call runeBook.txt %recallType %runeNo
    gosub waitingRecallPos %posX %posY recall
return

sub waitingRecallPos
    set %maxTimeOut 5
    set %timeOut #scnt + %maxTimeOut
    while #charPosX <> %1 && #scnt < %timeOut
          wait 1s
    set %timeOut #scnt + %maxTimeOut
     while #charPosY <> %2 && #scnt < %timeOut
          wait 1s
     if #scnt >= %timeOut
         gosub %3
return

sub checkWeight
  if #weight > #maxWeight
  {
     gosub recall home
     gosub dropItemsChest
  }
return

sub dropItemsChest
set %woodenChestType JIF
set %goldType DWJ
finditem %woodenChestType G_2
set %woodenChestID #findID
finditem %goldType C_ , #backpackID
exevent drag #findID #findStack
wait 2s
exevent dropc %woodenChestID
wait 2s
return

sub mining
      event sysmessage mining!
      gosub tileName
      while #weight <= #maxWeight && #result = #true
      {
      gosub usePicket
      gosub scan
      wait 2s
      }
return

sub scan
  set %timeout #scnt + 15
  set %jrnl #jindex
  scanjournal %jrnl

  while #scnt < %timeout
  {
    if %jrnl < #jindex
    {
      set %jrnl %jrnl + 1
      scanjournal %jrnl
    }

    if ( you_dig in #journal || loosen_some in #journal )
      return #true

    if ( there_is_no_metal in #journal || no_quedan_minerales in #journal )
      return #false
  }
return

sub UsePicket
  set #lTargetKind 3
  set #lTargetX #CHARPOSX
  set #lTargetY #CHARPOSY
  set #lTargetZ #charPosZ
  finditem %pickAxeType C_ , #backpackID
  set #LOBJECTID #FINDID
  event macro 17
  target 3s
  event macro 22
return

sub tileName
    set %miningPosX #charPosX + %x
    set %miningPosY #charPosY + %y
    tile init
    tile cnt %miningPosX %miningPosY
    for %j 1 #tilecnt
    {
     tile get %miningPosX %miningPosY  %j
     set %canMine cave_floor in #tileName
     if %canMine
     {
     set #lTargetTile #tileType
     return #true
     }
    }
return
To learn, read.
To know, write.
To master, teach.

Offline rana70

  • Elite
  • *
  • *
  • Posts: 294
  • Activity:
    0%
  • Reputation Power: 5
  • rana70 has no influence.
  • Gender: Male
  • Respect: +37
  • Referrals: 2
    • View Profile
    • MyScripts
Re: Looping a mining script
« Reply #3 on: June 04, 2009, 01:15:38 AM »
0
Hi again,

so you check your weight inside the mining sub as I see ...
and why do you check it again in the main loop ?

I think if you do one correct weight check it is really enough,
and will reduce "doubled" stuff :-)

btw. about your weight check ... there is a small issue in your way
to do it .... humans and elfs have to be handled differend...

If you are interested .. to see more about this ...
I added my usual way of weightcheck sub.....

And make sure you think about the fact that one dig can bring
up lots of weight in one round ... let's say the char can handle
450 stones .. you already have 440 and you digup a pile of 12 ore...
result is .. you got stuck ...

I for sure respect your idea to do a recall sub on your own ....
but there is a great transportation SUB for public use around ...
a guy named TrailMyx  ;) ... made it available to the public....
great code... very easy to handle ... he just asks for creditin the
header of the script  ;D

Code: [Select]
; Prepair to get the Data to do a propper WeightCheck
;------------------------ Data -----------------------------
SUB WeightCheckSetup
  Set %Human #FALSE
  FindItem #CHARID *
   if #FindType notin XU_AV
    {
     Set %Human #TRUE
  ;Open Status if it is closed
  if #MAXWEIGHT = N/A
   {
    Event Macro 8 2
     Wait %DelayEvent
   }
RETURN

; WeightCheck to prevent from Overload
;------------------------ Routine -----------------------------
SUB WeightCheck
  if %Human = #TRUE
   Set %MaxFreeBackPackLoad ( #MAXWEIGHT + 60 ) - #WEIGHT
  if %Human = #FALSE
   Set %MaxFreeBackPackLoad #MAXWEIGHT - #WEIGHT
  if %MaxFreeBackPackLoad > 550
   Set %MaxFreeBackPackLoad 550
  if %MaxFreeBackPackLoad < 0
   Set %MaxFreeBackPackLoad 0
  RETURN

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Looping a mining script
« Reply #4 on: June 04, 2009, 06:04:02 AM »
0
Here is a cleaner way of setting your positions (set at top of script).  With a new concept for you to sudy and learn (the use of . when setting variables)

Code: [Select]
; at top of script 3..4 .. etc
 set %posX1 733
 set %posY1 720
 set %posX2 1419
 set %posY2 3758  ; add more posy3 etc set max runes to represent number of entries.
 set %runeNo 0
 set %maxRunes 2

; Inside script
repeat
      gosub checkWeight
      Gosub MoveToNextPosition
      gosub mining
until #charGhost = yes

Sub MoveToNextPosition
   set %runeNo %runeNo + 1
   If %Runeno > %MaxRunes
       set %runeNo 1

   set %posX  %posX . %RuneNo
   set %posY  %posY . %RuneNo

   call runeBook.txt %recallType %runeNo
   gosub waitingRecallPos %posX %posY recall
Return
« Last Edit: June 04, 2009, 06:09:39 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline VicVegaTopic starter

  • Jr. Member
  • **
  • Posts: 71
  • Activity:
    0%
  • Reputation Power: 0
  • VicVega has no influence.
  • Respect: +8
  • Referrals: 0
    • View Profile
Re: Looping a mining script
« Reply #5 on: June 05, 2009, 01:41:58 AM »
0
That's exactly what I was looking for, thanks.

I've changed already my script, I will publish it when I test it a little more.
To learn, read.
To know, write.
To master, teach.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Looping a mining script
« Reply #6 on: June 05, 2009, 07:13:02 AM »
0
glad i could help
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: