Code: Select all
|New TS
| ts.mac (tradeskill.mac)
|INI Support by Diggler
#turbo
#define INIFile "c:\macroquest\release\macros\recipes.ini"
#event SkillTrivial "You can no longer advance your skill from making this item"
#event SkillUp "You have become better at"
#event SkillFailure "You lacked the skills"
#event SkillSuccess "You have fashioned the items together to create something new"
#event FullInventory "There was no place to put that"
#event CombineError "You cannot combine these items in this container type!"
#chat tell
Sub Main
/declare ShowStats global
/declare EndOnTrivial global
/declare dly global
/declare abt global
/declare FinishedProduct global
/declare DesiredSuccesses global
/declare ErrorAtCombine global
/declare CombineErrorCounter global
/declare SkillTrivialCounter global
/declare SkillFailCounter global
/declare SkillSuccessCounter global
/declare SuccessRate global
/declare TotalAttempts global
/declare SkillUpRate global
/declare SkillUpCounter global
/declare CombInt global
/declare CombStr global
/declare TotalComp global
/declare l0 local
/declare a array
/call SetDefaults
/if $defined(Param0)==false /call ExecError
/if "@Param0"=="help" /call ShowHelp
/call ParseArgs "@Param0"
/varset ErrorAtCombine 0
/varset CombineErrorCounter 0
/varset SkillTrivialCounter 0
/varset SkillFailCounter 0
/varset SkillSuccessCounter 0
/varset SuccessRate 0
/varset TotalAttempts 0
/varset SkillUpRate 0
/varset SkillUpCounter 0
/call CombFind "$ini("INIFile","@Param1","Cont")"
/if n @CombInt<=7 /varset CombStr "pack @CombInt"
/if @CombInt==8 {
/varset CombInt e
/varset CombStr enviro
}
/if @CombInt>=98 /if @CombInt<=99 {
/if n @CombInt==99 /echo Cannot find container << @Param1 >>
/if n @CombInt==98 /echo Too far away from << @Param1 >>
/endmacro
}
/varset TotalComp 0
/call ClearCursor @FinishedProduct
:CountComponents
/varset a(@TotalComp) "$ini("INIFile","@Param1","Comp$int(@TotalComp)")"
/varadd TotalComp 1
/if n $int(@TotalComp)>10 /call ExecError
/echo Component $int(@TotalComp): "@a($int($calc(@TotalComp-1))")"
/if "$ini("INIFile","@Param1","Comp$int(@TotalComp)")"~~"@" {
/goto :DestroyCheck
} else /if "$ini("INIFile","@Param1","Comp$int($calc(@TotalComp))")"=="NOTFOUND" {
/goto :DestroyCheck
} else {
/goto :CountComponents
}
:DestroyCheck
/if @FinishedProduct=="DESTROY" {
/press F1
/echo This macro is currently set to destroy successful combines!!!!
}
:Begin
/call ClearCursor @FinishedProduct
/doevents
/if "$target(name,clean)"=="$char(name)" {
/echo Pausing!! To resume, type /target clear or target something else.
:HoldingPattern
/delay 2s
/if "$target(name,clean)"=="$char(name)" /goto :HoldingPattern
}
/if n @DesiredSuccesses!=0 /if n @DesiredSuccesses<=@SkillSuccessCounter {
/echo Created $int(@DesiredSuccesses) items as requested!
/call EndCombines
}
/for l0 0 to $int($calc(@TotalComp-1))
|/echo calling AddComp "@a(@l0)" @l0
/call AddComp "@a(@l0)" @l0
/next l0
:Combine
/doevents
/call DoCombine
:ClearCursor
/doevents
/call ClearCursor @FinishedProduct
}
/goto :Begin
/return
Sub SetDefaults
/varset ShowStats 1
/varset EndOnTrivial 0
/varset dly 2
/varset abt 0
/varset FinishedProduct "keep"
/varset DesiredSuccesses 0
/return
Sub CheckOptions
/if "@Param1"=="" {
/echo Syntax: /call CheckOptions "option" "value"
/endmacro
}
/if "@Param0"=="combines" {
/varset DesiredSuccesses $int(@Param1)
/return
}
/if "@Param0"=="cursor-delay" {
/varset dly $int(@Param1)
/return
}
/if "@Param0"=="end-on-trivial" {
/varset EndOnTrivial $int(@Param1)
/return
}
/if "@Param0"=="abort-on-tell" {
/varset abt $int(@Param1)
/return
}
/if "@Param0"=="destroy" {
/if n @Param1==1 /varset FinishedProduct "destroy"
/return
}
/if "@Param0"=="show-stats" {
/varset ShowStats $int(@Param1)
/return
}
/echo unknown option @Param0
/return
Sub ParseArgs
/declare l0 local
/declare l1 local
/declare l2 local
/declare l3 local
/declare l4 local
/if $defined(Param0)==false {
/echo Syntax: /call ParseArgs "space seperated string of arguments"
/endmacro
}
/if "@Param0"~~"default" {
/call SetDefaults
/goto :EndOptions
}
/varset l0 "@Param0"
/call CountArgs "@l0"
/varset l1 $int($return)
/for l2 1 to @l1
/if n @l1>1 /varset l0 "$arg($int(@l2),"@Param0")"
/varset l3 $left($instr("=","@l0"),"@l0")
/varset l4 $right($calc($strlen("@l0")-$instr("=","@l0")-1),"@l0")
/call CheckOptions "@l3" "@l4"
/next l2
:EndOptions
/return
Sub CountArgs
/declare l0 local
/declare l1 local
/if $defined(Param0)==false {
/echo Syntax: /call CountArgs "space seperated string of arguments"
/endmacro
}
/varset l0 1
/varset l1 1
:Loop
/if "$mid($int(@l1),1,"@Param0")"==" " /varadd l0 1
/varadd l1 1
/if n @l1<$strLen("@Param0") /goto :Loop
/return $int(@l0)
Sub ExecError
/echo Syntax error.
/echo Type the following for more help:
/echo /macro sits "help"
/endmacro
/return
Sub ShowHelp
/echo Syntax: /macro ts <options> <keyword>
/echo Example: /macro ts "show-stats=0 destroy=0 abort-on-tell=0 end-on-trivial=0" swatch
/echo -
/echo MAKE SURE THAT:
/echo * INIFile is pointing to YOUR ini file!
/echo * Inventory is open.
/echo * All your containers are open.
/echo * Nothing crosses over each other, all windows (bags, inventory, buttons) must be free.
/echo * Your window positions are saved (by closing them and opening them again after they have been moved).
/echo -
/echo Options:
/echo --------
/echo * show-stats
/echo -- Syntax: show-stats=1|0
/echo -- Example: show-stats=0
/echo -- Shows combine statistics.
/echo -- Set to 1 for show showing stats, 0 to leave out the stats.
/echo -- Default set to 1 (show stats).
/echo -
/echo * destroy
/echo -- Syntax: destroy=1|0
/echo -- Example: destroy=1
/echo -- Tells the macro wether end-result is destroyed or kept.
/echo -- Set to 1 for destroying end-result, 1 to keep end-result.
/echo -- Default set to 0 (keep end-result).
/echo -
/echo * abort-on-tell
/echo -- Syntax: abort-on-tell=1|0
/echo -- Example: abort-on-tell=1
/echo -- Tell the macro wether it should /endmacro when recieving a tell.
/echo -- Set to 1 for ending macro on tells, 0 to ignore tells.
/echo -- Default set to 0 (ignore tells).
/echo -
/echo * end-on-trivial
/echo -- Syntax: end-on-trivial=1|0
/echo -- Example: end-on-trivial=1
/echo -- Tell the macro wether it should stop combines when recieving a trivial message.
/echo -- Set to 1 for ending macro on trivial, 0 to ignore trivial.
/echo -- Default set to 0 (ignore trivial).
/echo -
/echo * cursor-delay
/echo -- Syntax: cursor-delay=#
/echo -- Example: cursor-delay=4
/echo -- The delay between mouse commands in the macro.
/echo -- Increase this number to make the macro combine slower, but more safely. Decrease the number to combine faster, but more prone to errors.
/echo -- Default set to 2 (this is as fast as it has been tested to be able to go)
/echo -
/echo * combines
/echo -- Syntax: combine=#
/echo -- Example: combine=100
/echo -- The number of successfull combines you want made (or till no more components are available).
/echo -- Set to 0 for unlimited combines (or till no more components are available), or to the wanted amount.
/echo -- Default set to 0 (unlimited).
/echo -
/echo * default
/echo -- Syntax: default
/echo -- Tell the macro to use all default settings, any other options set will be ignored and defaults will be used.
/endmacro
/return
Sub CleanPack
/declare l0 local
/declare l1 local
/press ctrl
/sendkey down shift
/if "@CombStr"=="enviro" {
/varset l0 10
} else {
/varcalc l0 $pack(@CombInt,slots)-1
}
/for l1 0 to @l0
/click left @CombStr @l1
/call WaitForPickup
/click left auto
/call WaitForDrop
/next l1
/sendkey up shift
/press shift
/return
sub ClearCursor
/declare l0 local
/declare l1 local
/declare l2 local
:Loop
/delay @dly
/if $cursor()!=NULL {
/if "@Param0"=="DESTROY" {
/varset l0 0
:SubLoop
/if "@a(@l0)"~~"#" {
/varset l1 "$right($calc($strlen("@a(@l0)")-1),"@a(@l0)")"
/varset l2 0
} else {
/varset l1 "@a(@l0)"
/varset l2 1
}
/if n @l2==0 /if "$cursor(name)"~~"@l1" {
/click left auto
/delay @dly
} else /if n @l2==1 /if "$cursor(name)"=="@l1" {
/click left auto
/delay @dly
}
/if "$cursor()"!="NULL" {
/if n @l0< $calc(@TotalComp-1) {
/varadd l0 1
/goto :SubLoop
} else {
/click left destroy
/delay @dly
}
}
} else {
/click left auto
/delay @dly
}
}
/if $cursor()!=NULL /goto :Loop
/return
sub DoCombine
/click left @CombStr combine
:Loop
/doevents
/delay 2
| careful here, this seems to take a long time
/if $pack(@CombInt,empty)==FALSE /goto :Loop
/return
sub AddComp
/press shift
/sendkey down ctrl
/if "@Param0"~~# {
/finditem similar "$right($calc($strlen("@Param0")-1),"@Param0")"
} else {
/finditem "@Param0"
}
/if $find()==FALSE /goto :NoComp
/call WaitForPickup
/click left @CombStr @Param1
/call WaitForDrop
/goto :End
:NoComp
/echo Could not find << @Param0 >>
/call EndCombines
:End
/sendkey up ctrl
/press ctrl
/return
Sub CombFind
/declare l0 local
/declare l1 local
/declare l2 local
/declare l3 local
/varset CombInt 99
/if "@Param0"~~"#" {
/varset l1 "$right($calc($strlen("@Param0")-1),"@Param0")"
/varset l2 0
} else {
/varset l1 "@Param0"
/varset l2 1
}
/for l3 0 to 7
/if n @l2==0 /if "$pack(@l3,name)"~~"@l1" /varset CombInt @l3
/if n @l2==1 /if "$pack(@l3,name)"=="@l1" /varset CombInt @l3
/next l3
/if n @CombInt==99 {
/if "@l1"=="enviro" /varset CombInt 8
/if n @CombInt!=8 /itemtarget @Param0
/if n @CombInt!=8 /if n $ground(id)==0 /varset CombInt 99
/if n @CombInt!=8 /if n $distance(item)>20 /varset CombInt 98
/if n @CombInt!=8 /if n $ground(id)>0 /if n $distance(item)<=20 /varset CombInt 8
}
/return @CombInt
Sub DisplayStats
/echo Combine Statistics - Successes: $int(@SkillSuccessCounter), Failures: $int(@SkillFailCounter), Trivial: $int(@SkillTrivialCounter)
/varcalc TotalAttempts @SkillFailCounter + @SkillSuccessCounter
/if n @TotalAttempts>0 {
/varcalc SuccessRate @SkillSuccessCounter / @TotalAttempts * 100
/varcalc SkillUpRate @SkillUpCounter / @TotalAttempts * 100
/echo Successes Rate: $int(@SuccessRate) % out of $int(@TotalAttempts) attempts
} else {
/echo Unable to complete a combine. No Stats to report
}
/if n @SkillUpCounter>0 /echo Skill Ups: $int(@SkillUpCounter) , Skill Rate: $int(@SkillUpRate) % out of $int(@TotalAttempts) attempts
/if n @SkillTrivialCounter>0 /echo THIS ITEM IS OR HAS GONE TRIVIAL!
/return
Sub EndCombines
/call CleanPack
/if n @ShowStats==1 /call DisplayStats
/endmacro
/return
Sub Event_Chat
/if "@abt"=="TRUE" {
/echo Got a tell, pausing.
/press F1
}
/return
Sub Event_CombineError
/varcalc ErrorAtCombine @SkillFailCounter + @SkillSuccessCounter
/varadd CombineErrorCounter 1
/if n @CombineErrorCounter<=1 {
/echo Attempting to recover from failed combine!
/call CleanPack
} else {
/echo Failed to recover from failed combine!
/call EndCombines
}
/return
Sub Event_FullInventory
/echo Your inventory is full, ending macro.
/call EndCombines
/return
Sub Event_SkillFailure
/varadd SkillFailCounter 1
/if n @CombineErrorCounter>=1 /varset CombineErrorCounter 0
/return
Sub Event_SkillSuccess
/varadd SkillSuccessCounter 1
/if n @CombineErrorCounter>=1 /varset CombineErrorCounter 0
/return
Sub Event_SkillUp
/varadd SkillUpCounter 1
/echo $int(@SkillUpCounter) skill ups in $int($calc(@SkillFailCounter+@SkillSuccessCounter)) attempts!
/return
Sub Event_SkillTrivial
/call ClearCursor @FinishedProduct
/varadd SkillTrivialCounter 1
/if n @ShowStats==1 /if n @SkillTrivialCounter==1 /echo THIS ITEM IS OR HAS GONE TRIVIAL!
/if n @EndOnTrivial==1 /if n @SkillTrivialCounter==1 /call EndCombines
/return
Sub WaitForPickup
:waiting
/if $cursor()==FALSE /goto :waiting
/return
Sub WaitForDrop
:waiting
/if $cursor()==TRUE /goto :waiting
/return Code: Select all
[bits]
Cont=enviro
Comp0=Small Piece of Ore
Comp1=Small Piece of Ore
Comp2=Water Flask
[dough]
Cont=#mixing
Comp0=#egg
Comp1=#Milk
Comp2=#flourEDITED 10/28/03: Updated code to fix the 'Cannot Combine when hands are full' etc. spam messages. Thx Catt for noticing


