ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: VicVega on June 03, 2009, 01:27:26 PM
-
So my mining script it's something like this at the moment (I only post now the significant code, the main loop):
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.
-
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
repeat
{
gosub recall to workplace
gosub mining ; <- does Weightcheck, and sets a marker for next spot to mine or dropoff location
}
until #charGhost = yes
-
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
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.
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:
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
-
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
; 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
-
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)
; 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
-
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.
-
glad i could help