TF: bashing & targeting scripts

by Unknown

Back to Mechanic's Corner.

Unknown2005-10-17 21:13:40
I've updated my website (finally) with the stuff I've been working on lately. The big changes came in my bashing and targeting scripts. The targeting script now handles 4 targets at once. The bashing script bashes those targets by the numbers with priority given to targets in order (so if any of your first target are in the room it will bash those before any of your second target), also picking up the correct number of corpses and gold dropped (most of the time tongue.gif ).

To set your targets you'd type:
t target1 target2 target3 target4

You're not required to have 4 targets. If you only have 1 or 2 it will just leave the others blank.

When you enter a room with targets present you'd type t by itself. This will tell the targeting script to scan the room for targets and gather their numbers behind the scenes. Typing bon (short for "bashing on") will activate the auto-basher and proceed to kill everything in the room you have targeted. As things are slain, the targeting script will scan the room once again to gather the latest numbers and select a new target. Once everything is dead it will pick up the corpses and gold. If you're unable to kill everything in the room (get into trouble), or need to leave for one reason or another, typing boff will halt the bashing script and you'll be able to move as soon as you've regained balance.

The targets are attacked in the following order:
1) target1, if a number was found for it
2) target2, if a number was found for it
3) target3, if a number was found for it
4) target4, if a number was found for it
5) whichever target was last "seen" (the highlighting triggers keep track of which one was fired last).
6) target1 (default, just in case everything else fails for some reason)

All of the files are available on my site: http://www.bwbettin.com

However, here are a few quick links for syntax highlighted (html) versions of these two scripts:
http://www.bwbettin.com/pages/programming/.../targeting.html
http://www.bwbettin.com/pages/programming/...ml/bashing.html

I also created an HTML log (in color) so you could see what it looks like using a combination of a TF patch from Adrian (Morik) and a Perl script from a person on the TF mailing list. All of the files and instructions for how to do this are located on my site in the Files/Downloads section.

http://www.files.bwbettin.com/2005-10-17_log_bashing.html

Please note that a lot of the echoes and all of the "SENT:" lines in the log DO NOT appear on the screen while you're using the script. I have a lot of extra stuff logged so that you can see what's going on, and to help me debug stuff if something wierd happens.

Here is a raw copy/paste of the two scripts for posterity, and so those too lazy to click on the html links above can still see them. laugh.gif

targeting.tf
CODE
;###############################;
;#####  target management  #####;
;###############################;


/set target1=
/set target1number=
/set target2=
/set target2number=
/set target3=
/set target3number=
/set target4=
/set target4number=
/set target_lastseen=
/set target_spotted=0
/set targeting_was_bashing=0

;### obtain first available object number associated with the current target using INFO HERE
;### syntax: /targeting_get_number
/def targeting_get_number = \\
   /if (({status_phase} == 0)) \\
;       # clear target numbers
       /set target1number= %; \\
       /set target2number= %; \\
       /set target3number= %; \\
       /set target4number= %; \\
;       # create captures for each target that is set
       /def -n1 -p50 -F -t'^".*\\\\b%{target1}(\\\\d+)"' targeting_info_here_catch_target1 = /set target1number=%%{P1} %; \\
       /def -n0 -p50 -F -t'^".*\\\\b%{target1}(\\\\d+)"' targeting_info_here_catch_target1_spotted = /test target_spotted += 1 %; \\
       /if ({target2} !~ "") \\
           /def -n1 -p50 -F -t'^".*\\\\b%{target2}(\\\\d+)"' targeting_info_here_catch_target2 = /set target2number=%%{P1} %; \\
           /def -n0 -p50 -F -t'^".*\\\\b%{target2}(\\\\d+)"' targeting_info_here_catch_target2_spotted = /test target_spotted += 1 %; \\
       /endif %; \\
       /if ({target3} !~ "") \\
           /def -n1 -p50 -F -t'^".*\\\\b%{target3}(\\\\d+)"' targeting_info_here_catch_target3 = /set target3number=%%{P1} %; \\
           /def -n0 -p50 -F -t'^".*\\\\b%{target3}(\\\\d+)"' targeting_info_here_catch_target3_spotted = /test target_spotted += 1 %; \\
       /endif %; \\
       /if ({target4} !~ "") \\
           /def -n1 -p50 -F -t'^".*\\\\b%{target4}(\\\\d+)"' targeting_info_here_catch_target4 = /set target4number=%%{P1} %; \\
           /def -n0 -p50 -F -t'^".*\\\\b%{target4}(\\\\d+)"' targeting_info_here_catch_target4_spotted = /test target_spotted += 1 %; \\
       /endif %; \\
;       # gag information from "info here"
       /def -n0 -p49 -ag -t'^".*\\\\b\\\\w+( \\(dead\\))?\\\\d+"' targeting_info_here_catch_all %; \\
;       # cleanup the captures and gags, output the results
       /def -n1 -p50 -ag -t"^Number of objects: \\\\d+" targeting_info_here_end = \\
           /undef targeting_info_here_catch_all %%; \\
           /purge -mglob targeting_info_here_catch_target* %%; \\
           /if (({target1number} =~ "") & ({target2number} =~ "") & ({target3number} =~ "") & ({target4number} =~ "")) \\
               /echol BCcyan 0 <<<< no target present >>>> %%; \\
           /else \\
               /echol BCcyan 0 <<<< new target aquired - %%{target_spotted} total >>>> %%; \\
           /endif %%; \\
           /set target_spotted=0 %%; \\
           /log_entry BCcyan <<<< target1 # = %%{target1number} >>>> %%; \\
           /log_entry BCcyan <<<< target2 # = %%{target2number} >>>> %%; \\
           /log_entry BCcyan <<<< target3 # = %%{target3number} >>>> %%; \\
           /log_entry BCcyan <<<< target4 # = %%{target4number} >>>> %%; \\
           /if ({targeting_was_bashing} == 1) \\
               /set targeting_was_bashing=0 %%; \\
               /set bashing_toggle_auto_bash=1 %%; \\
           /endif %; \\
       info here %; \\
   /endif

;### set/unset your target
;### syntax: t ]] | none]
/alias t \\
   /if ({#} > 0) \\
;       # cleanup highlights
       /purge -mglob targeting_highlight_target* %; \\
       /if (({target1} !~ "") | ({target2} !~ "") | ({target3} !~ "") | ({target4} !~ "")) \\
           /undef targeting_slain %; \\
       /endif %; \\
;       # clear target names and numbers
       /set target1= %; \\
       /set target1number= %; \\
       /set target2= %; \\
       /set target2number= %; \\
       /set target3= %; \\
       /set target3number= %; \\
       /set target4= %; \\
       /set target4number= %; \\
;       # if new targets are supplied, set the names, create highlights, and get the numbers of targets currently present
       /if ({1} !~ "none") \\
           /set target1=%{1} %; \\
           /set target2=%{2} %; \\
           /set target3=%{3} %; \\
           /set target4=%{4} %; \\
           /set target_lastseen=1 %; \\
           /def -n0 -p110 -F -P1xBCgreen -t"\\\\b(%{target1})\\\\b" targeting_highlight_target1 = /set target_lastseen=1 %; \\
           /if ({target2} !~ "") \\
               /def -n0 -p110 -F -P1xBCgreen -t"\\\\b(%{target2})\\\\b" targeting_highlight_target2 = /set target_lastseen=2 %; \\
           /endif %; \\
           /if ({target3} !~ "") \\
               /def -n0 -p110 -F -P1xBCgreen -t"\\\\b(%{target3})\\\\b" targeting_highlight_target3 = /set target_lastseen=3 %; \\
           /endif %; \\
           /if ({target4} !~ "") \\
               /def -n0 -p110 -F -P1xBCgreen -t"\\\\b(%{target4})\\\\b" targeting_highlight_target4 = /set target_lastseen=4 %; \\
           /endif %; \\
           /def -n0 -p48 -F -P1BCcyan -t"^(You have slain) .*\\\\.\\$" targeting_slain = \\
               /if ({bashing_toggle_auto_bash} == 1) \\
                   /set bashing_toggle_auto_bash=0 %%; \\
                   /set targeting_was_bashing=1 %%; \\
               /endif %%; \\
               /targeting_get_number %; \\
           /log_entry BCcyan <<<< target1 = %{target1} >>>> %; \\
           /log_entry BCcyan <<<< target2 = %{target2} >>>> %; \\
           /log_entry BCcyan <<<< target3 = %{target3} >>>> %; \\
           /log_entry BCcyan <<<< target4 = %{target4} >>>> %; \\
           /targeting_get_number %; \\
;       # if "none" is supplied, leave the target names and numbers cleared
       /else \\
           /log_entry BCcyan <<<< target unset >>>> %; \\
       /endif %; \\
;   # if no arguments are supplied, search the room for targets currently present
   /else \\
       /if (({target1} !~ "") | ({target2} !~ "") | ({target3} !~ "") | ({target4} !~ "")) \\
           /log_entry BCcyan <<<< target1 = %{target1} >>>> %; \\
           /log_entry BCcyan <<<< target2 = %{target2} >>>> %; \\
           /log_entry BCcyan <<<< target3 = %{target3} >>>> %; \\
           /log_entry BCcyan <<<< target4 = %{target4} >>>> %; \\
           /targeting_get_number %; \\
       /else \\
           /echol BCcyan 0 <<<< no target defined >>>> %; \\
       /endif %; \\
   /endif

;### obtain the targeting value to use (either the name or the number)
;### syntax: target() or /target
;### note: this is intended to be used in other scripts to reference the target (as opposed to a variable)
/def target = \\
   /if ({target1number} !~ "") \\
       /result {target1number} %; \\
   /elseif ({target2number} !~ "") \\
       /result {target2number} %; \\
   /elseif ({target3number} !~ "") \\
       /result {target3number} %; \\
   /elseif ({target4number} !~ "") \\
       /result {target4number} %; \\
   /elseif ({target_lastseen} !~ "") \\
       /let target_name=$ %;\\
       /let target_value= %; \\
       /test target_value:=%{target_name} %; \\
       /result {target_value} %; \\
   /else \\
       /result {target1} %; \\
   /endif


bashing.tf
CODE
;##############################################;
;#####  auto bashing macro and interface  #####;
;##############################################;


;### Usage:
;### First you'll need to set your target by issuing the command "t ".  Now go hunting for your target.  When you
;### walk into a room with 1 or more targets, you'll want to immediatly issuse the command "t".  This searches the room for
;### available targets, and sets your target to the actual number of a target.  Then issue the command "bon" (short for
;### "bashing on") to start attacking the target until it is dead.  You only need to type "bon" once, it will continuously
;### attack as quickly as possible without any further work on your part.  Once the target has been dispatched, the targeting
;### script will search the room for another target and get its number.  If it finds one, it will continue attacking.  If no
;### target is found, "boff" will be automatically executed and you can continue hunting for more targets.  If at anytime
;### you're in trouble or need to flee from the battle, issue the command "boff".  This will tell the script to stop attacking;
;### as soon as you've regained balance/equilibrium you will be able to flee.


/set bashing_toggle_auto_bash=0
/set bashing_target1_corpse_count=0
/set bashing_target2_corpse_count=0
/set bashing_target3_corpse_count=0
/set bashing_target4_corpse_count=0
/set bashing_gold_dropped=0

;### auto bashing
/def -n0 -p1025 -F -q -h"PROMPT (\\\\d+)h, (\\\\d+)m, (\\\\d+)e, (\\\\d+)p, (\\\\d+)en, (\\\\d+)w (.*)\\\\-" bashing_prompt_catch_auto_bash = \\
   /if ({bashing_toggle_auto_bash} == 1) \\
       /if (({status_balance} == 1) & ({status_equilibrium} == 1) & (({status_balance_arm_left} == 1) | ({status_balance_arm_right} == 1))) \\
;           # if any targets remain, continue attacking
           /if (({target1number} !~ "") | ({target2number} !~ "") | ({target3number} !~ "") | ({target4number} !~ "")) \\
               swing $ %; \\
;           # when all targets are dispatched and you have balance, pick up the corpses and gold
           /else \\
               /if (({status_balance_arm_left} == 1) & ({status_balance_arm_right} == 1)) \\
                   boff %; \\
                   /while ({bashing_target1_corpse_count} > 0) \\
                       /test bashing_target1_corpse_count -= 1 %; \\
                       get %{target1} %; \\
                   /done %; \\
                   /while ({bashing_target2_corpse_count} > 0) \\
                       /test bashing_target2_corpse_count -= 1 %; \\
                       get %{target2} %; \\
                   /done %; \\
                   /while ({bashing_target3_corpse_count} > 0) \\
                       /test bashing_target3_corpse_count -= 1 %; \\
                       get %{target3} %; \\
                   /done %; \\
                   /while ({bashing_target4_corpse_count} > 0) \\
                       /test bashing_target4_corpse_count -= 1 %; \\
                       get %{target4} %; \\
                   /done %; \\
                   /if ({bashing_gold_dropped} == 1) \\
                       get gold %; \\
                       put gold into pack %; \\
                       /set bashing_gold_dropped=0 %; \\
                   /endif %; \\
               /endif %; \\
           /endif %; \\
       /endif %; \\
   /endif

;### toggle auto bashing
/alias bon \\
   /set bashing_toggle_auto_bash=1 %; \\
;   # gag excessive balance messages (occur when you receive prompts after sending an attack command, but before it's processed by lusternia)
   /def -n0 -p50 -agL -t"^Your left arm is off balance\\\\.\\$" bashing_gag_balance_arm_left %; \\
   /def -n0 -p50 -agL -t"^Your right arm is off balance\\\\.\\$" bashing_gag_balance_arm_right %; \\
;   # adjust the corpse count when a creature is slain
   /def -n0 -p50 -F -t"^You have slain .*\\\\.\\$" bashing_slain = \\
       /if ({target1number} !~ "") \\
           /test bashing_target1_corpse_count += 1 %%; \\
       /elseif ({target2number} !~ "") \\
           /test bashing_target2_corpse_count += 1 %%; \\
       /elseif ({target3number} !~ "") \\
           /test bashing_target3_corpse_count += 1 %%; \\
       /elseif ({target4number} !~ "") \\
           /test bashing_target4_corpse_count += 1 %%; \\
       /else \\
           /test bashing_target1_corpse_count += 1 %%; \\
       /endif %; \\
;   # set a flag if any creatures drop gold
   /def -n0 -p50 -F -aBCcyan -t"sovereign(s)? spill(s)? from the corpse\\\\.\\$" bashing_gold_dropped_catch = /set bashing_gold_dropped=1 %; \\
;   # begin the attack
   swing $

/alias boff \\
   /set bashing_toggle_auto_bash=0 %; \\
   /undef bashing_gag_balance_arm_left %; \\
   /undef bashing_gag_balance_arm_right %; \\
   /undef bashing_slain %; \\
   /undef bashing_gold_dropped_catch
Alger2005-10-17 23:33:47
hmm mines a bit different I'll post it when I figure out how to copy/paste again. Stupid Safari is screwing with me again.
Unknown2005-10-18 02:46:46
I thought Auto-bashing was illegal.
Unknown2005-10-18 02:49:34
If you put the macro on, walk out of the room, and have your character be able to bash for you without your attention is illegal. This still requires you to walk around, therefore its not illegal, since you physically have to be there in order to continue to bash.
Unknown2005-10-18 04:26:52
Yep, Nine Breaker is correct. To my knowledge you can automate anything you want as long as it's not 100% automated and requires no attention on your part. Now if I were to combine the auto-demesne script I wrote for Razyx which walked a certain path around a village to demesne the entire thing with this script...that would probably be illegal...which is why I didn't do that tongue.gif

Alger, I'd appreciate seeing any implementations you have for bashing/targeting. I don't think my way is probably the cleanest or most efficient way of doing it, but it worked and I was busy messing with other things so I was happy enough with it. biggrin.gif
Unknown2005-10-18 08:57:58
meh, looks grey area to me tongue.gif