I typically have all bags open, and enviro container open also, before I start the macro.
Only reason, destroy interested me so much, was doing hundreds of pottery combines, that you are never going to fire, and which only sell for coppers, wasn't worth my time.
This macro does everything that I want of it now, so I doubt I will make anymore changes to it.
Code: Select all
| ts.mac (slightly improved tradeskill.mac)
| -----------------------
| *** DESCRIPTION ***
| IF YOU ARE USING AN ENVIRONMENTAL CONTAINER, HAVE IT OPEN WHEN YOU START THE MACRO
| Syntax: /macro ts <0-X> <enviro|Combinername> <keep|destroy> <Component1>....[Component10]
|
| The first option is how many successes you want, 0 means unlimited and any other number is used for how many successful combines you want
| Can add up to 10 components and combine them in the selected combiner. Can specify wether to keep or destroy the finished product, returned components
| WILL NOT be destroyed, only the new item(s), that isn't part of the component list. As a precaution, it must specifically say "destroy" (case doesn't
| matter, case insensitive), if it says anything else it will keep the end product.
|
| To speed up the macro I put in #turbo and /delay's after just about each mouse movement. The delay is defined the ghe global variable $dly
| Set wether to pause macro on tell or to ignore it with the global variable $abt
|
| Scroll down to "VARIABLES TO LOOK AT!" for some user setable variables
|
| *** FEATURES ***
| - Pause script by targeting self
| - Combine X number of successes (or unlimited)
| - Keep or Destory result (set from cmd line)
| - Turn on/off display of statistics
| - Statistics about combines such as trivial combines, successes, failures, skillups, % of successes and % of skillups
| - Trivial warning
| - Failed combine DNC recovery, cleans pack and retries. If no error in 2 more attempts will reset and not exit.
| - Can use wildcard matching "#ShortName" instead of "Pieces of ShortName" (included in previous version, but not mentioned)
|
| *** CREDITS ***
| These are the persons I know I borrowed code from, I'm sure I forgot some..
| --
| General idea, and many of the sub routines from:
| - Gengis (http://macroquest2.com/phpBB2/viewtopic.php?p=4759#4759)
| - Pigeon (http://macroquest2.com/phpBB2/viewtopic.php?p=15523#15523)
|
| - #Wildcard sub routine idea from Serberus (http://macroquest2.com/phpBB2/viewtopic.php?p=9443#9443)
|
|
| *** TODO ***
| - Rumors say that when using "destroy", the macro is not working completely as intended. Investigating.
| - !DONE BY FRYFROG! Thinking about adding some statistic Sub Routines, as in Zeuz's macro (http://macroquest2.com/phpBB2/viewtopic.php?p=16800#16800)
| - !DONE BY FRYFROG! On CombineError, make the macro "/call CleanPack" 1 time, then retry combine. If CombineError 2 times in a row then "/call EndCombines".
|
|
#turbo
#define CombStr v1
#define CombInt v2
#define TotalComp v3
#define dly v4
#define abt v5
#define cbe v6
#define SkillFailCounter v50
#define SkillSuccessCounter v51
#define SuccessRate v53
#define TotalAttempts v54
#define SkillUpCounter v55
#define SkillUpRate v56
#define ShowStats v57
#define CombineErrorCounter v58
#define SkillTrivialCounter v59
#define FinishedProduct v60
#define ErrorAtCombine v61
#define DesiredSuccesses v62
#define EndOnTrivial v63
#define CombineKeep v64
#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
| ############################## VARIABLES TO LOOK AT! #####################################
| SET SHOWSTATS TO 1 TO SHOW STATS AND WARNINGS, 0 FOR OFF
/varset ShowStats 1
| SET EndOnTrivial to 1 to stop the macro when it becomes trivial
/varset EndOnTrivial 0
| SET THE DELAY BETWEEN MOUSE CLICKS HERE
/varset dly 2
| ABORT ON RECIEVING A TELL, SET TO "TRUE" or "FALSE"
/varset abt "TRUE"
| ############################## VARIABLES TO LOOK AT! #####################################
| /cleanup
/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
/varset CombineKeep 0
/call ClearCursor $FinishedProduct
/if "$p2"=="destroy" {
/varset FinishedProduct "DESTROY"
/varset CombineKeep 1
} else /if "$p2"=="keep" {
/varset FinishedProduct "KEEP"
/varset CombineKeep 1
}
/if n "$CombineKeep"==0 {
/echo Syntax: /macro ts <0-X> <enviro|Combinername> <keep|destroy> <Component> [Component]...
/endmacro
}
/if "$p3"=="" {
/echo Syntax: /macro ts <0-X> <enviro|CombinerName> <keep|destroy> <Component> [Component]...
/endmacro
}
/if n $p0>0 /if n $p0<=5000 {
/echo Setting to $p0 successful attempts!
/varset DesiredSuccesses $p0
} else /if $p0==0 {
/echo Setting to unlimited attempts!
/varset DesiredSuccesses 0
} else {
/echo Invalid setting for # of attempts
/endmacro
}
/call CombFind "$p1"
/if $CombInt<=7 /call OpenInv
/if $CombInt==8 {
/call OpenEnv
/delay $dly
}
/if $CombInt>=98 /if $CombInt<=99 {
/if n $CombInt==99 /echo Cannot find container << $p1 >>
/if n $CombInt==98 /echo Too far away from << $p1 >>
/endmacro
}
/call HandlePacks open
/varset TotalComp 0
/call ClearCursor $FinishedProduct
:CountComponents
/varset a(1,$TotalComp) "$p$int($calc($TotalComp+3))"
/varadd TotalComp 1
/if n $int($TotalComp)>10 {
/echo Syntax: /macro ts <0-X> <CombinerName> <keep|destroy> <Component> [Component]...
/echo You can only add up to a total of 10 components.
/endmacro
}
/echo Component $int($TotalComp): $p$int($calc($TotalComp+2))
/if "$p$int($calc($TotalComp+3))"~~"$" {
/goto :DestroyCheck
} else /if "$p$int($calc($TotalComp+3))"=="" {
/goto :DestroyCheck
} else {
/goto :CountComponents
}
:DestroyCheck
/if $FinishedProduct=="DESTROY" {
/beep
/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))
/call AddComp "$a(1,$l0)" $l0
/next l0
:Combine
/doevents
/call DoCombine
:ClearCursor
/doevents
/call ClearCursor $FinishedProduct
}
/goto :Begin
/return
Sub CleanPack
/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
/delay $dly
/click left auto
/delay $dly
/next l1
/sendkey up shift
/press shift
/return
Sub HandlePacks
/varset l0 0
/if "$p0"=="open" /goto :Open
/if "$p0"=="close" /goto :Close
/if "$p0"=="" /goto :Syntax
:Open
/for l0 0 to 7
/if "$pack($int($l0))"=="TRUE" /if "$pack($int($l0),open)"=="FALSE" {
/click right inv $int($l0)
/delay $dly
}
/next l0
/goto :End
:Close
/for l0 0 to 7
/if "$pack($int($l0))"=="TRUE" /if "$pack($int($l0),open)"=="TRUE" {
/click right inv $int($l0)
/delay $dly
}
/next l0
/goto :End
:Syntax
/echo Syntax: /call HandlePacks <open|close>
/endmacro
:End
/return
Sub OpenInv
/varset CombStr "pack $CombInt"
/if "$pack($int($l0),open)"=="FALSE" /click right inv $int($l0)
/delay $dly
/if $pack($CombInt,empty)==FALSE /call CleanPack
/return
Sub OpenEnv
/varset CombInt e
/varset CombStr enviro
| /face item
/delay $dly
|/click left item
|/delay $dly
| Code currently not functioning.
| :WaitOpen
| /if $pack($CombInt,open)==FALSE /goto :WaitOpen
| /delay $dly
| /if $pack($CombInt,empty)==FALSE /call CleanPack
/return
sub ClearCursor
:Loop
/delay $dly
/if $cursor()!=NULL {
/if "$p0"=="DESTROY" {
/varset l0 0
:SubLoop
/if "$a(1,$l0)"~~"#" {
/varset l1 "$right($calc($strlen("$a(1,$l0)")-1),"$a(1,$l0)")"
/varset l2 0
} else {
/varset l1 "$a(1,$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
:Loop
/click left $CombStr combine
/doevents
/delay $dly
/if $pack($CombInt,empty)==FALSE /goto :Loop
/return
sub AddComp
/press shift
/sendkey down ctrl
/if "$p0"~~# {
/finditem similar "$right($calc($strlen("$p0")-1),"$p0")"
} else {
/finditem "$p0"
}
/if $find()==FALSE /goto :NoComp
/delay $dly
/click left $CombStr $p1
/goto :End
:NoComp
/echo Could not find << $p0 >>
/call EndCombines
:End
/sendkey up ctrl
/press ctrl
/return
Sub CombFind
/varset CombInt 99
/if "$p0"~~"#" {
/varset l1 "$right($calc($strlen("$p0")-1),"$p0")"
/varset l2 0
} else {
/varset l1 "$p0"
/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 $p0
/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 $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
|/cleanup
/if n $ShowStats==1 /call DisplayStats
/endmacro
/return
Sub Event_Chat
/if "$abt"=="TRUE" {
/echo Got a tell, pausing.
/press F1
| /call EndCombines
}
/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
/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



