TF: forging script

by Unknown

Back to Mechanic's Corner.

Unknown2005-10-17 21:22:58
In an attempt to get my little ebonguard the best weapons possible I wrote a nice forging script.

As usual, the files can be found at http://www.bwbettin.com.

Here's a link to a nice html version that's all highlighted: http://www.bwbettin.com/pages/programming/...ml/forging.html

WARNING:
Whenever you're forging something I highly recommend you put ALL other objects remotely similar away so that you don't risk ruining things you want to keep. For example, when forging broadswords you should put all other swords away in a pack or scabbard. Don't come complaining to me if this script eats your stuff...use some common sense! biggrin.gif

Commands:

forge fire
- This will take coal out of your rift and attempt to fire the forge. If you get unlucky and create mercury, it will automatically get the mercury, inr it, and continue attempting to fire the forge until successful.

forge smelt
- This will smelt an item based on the forging id # (found through "forging "), take the metal comms from the forge and inr them. This is handy for when you've forged a lot of something and don't need them all, and is also used to automate other portions of the script.

forge pause
- This allows you to pause everything so that you can use balance/equilibrium to do something quick. Make sure you do it quick enough that the fire doesn't go out or you might FUBAR the item you're working on.

forge restart
- This restarts a paused forging process and picks up where you left off.

forge stop
- This halts a forging process dead in its tracks. There's no restarting it. Whatever you were working on will still be in the forge. Use this with caution, it's just here so you can quit quickly if you need to run defend your friends/family or a higher ranking person needs the forge. wink.gif

forge finish
- This halts the forging process cleanly, after the item you're currently working on is complete and removed from the forge. This is handy when you need to stop forging an order of items early, or to stop for forging for stats process (described below).

forge status
- This echos the status of the current forging process to your screen. Handy to tell how many more items are left to forge in the order you're working on, or to tell how many weapons you've created in stats mode that successfully match the requirements you were looking for.

forge order
- This will forge multiple items of the same type without any further interraction on your part. For example: forge order 12 943 will forge 12 broadswords (design 943). The script takes care of getting the items from the forge, outr'ing the comms, etc.

forge stats
- This is my favorite of the bunch. This command will continue reforging an item until it gets one with stats that meet your requirements. When it finds one that meets your reqs, it will put it in your pack and continue forging another. If the sword it just created does not meet your requirements, it will smelt it down and gather the comms, then start forging another. It will continue this process indefinitly until you either run out of comms or type forge finish or forge stop.
- refers to the sum total of the stats of the item. For weapons this would be damage+precision+speed, for armor this would be cutting+blunt (I have it ignore armor status in this calculation).
- refers the the individual statistics. For weapons it would be damage (1), precision (2), and speed (3). For armor it would be cutting (1), blunt (2), and armor status (3). Each of these refer to the individual stat. So if you set to 185 and were forging a broadsword, any broadsword with the damage stat >= 185 (regardless of the other stats) will be marked as having met your requirements and saved.
- refers to the group of stats as a whole. So if you only wanted to keep broadswords whose stats were >= 180/150/150, you'd set the to 180 150 150.
- Any argument set to 0 is ignored. So let's say you want a broadsword whose damage is >= 180, speed is >= 165, and you don't give a flying f*ck what the precision is. You'd set to 180 0 165.

Now for a combined example of how a forging process would work.

You walk up to a forge, it's cold and unused. forge fire will get the forge fired up for you.

You want to forge a nice broadsword (let's say design #943). You'd like to save anything whose total stats sum to 485 or greater, any weapon whose damage stat is greater or equal to 200 you'd like to save, and if the combined stats have the damage greather than or equal to 180 and the speed greater than or equal to 165 you'd like to save it. You'd do the following, forge stats 943 485 200 0 0 180 0 165. The forging script will take over, outr the comms, and start forging. You can sit back, relax, and watch the show.

A half hour later you notice you get hungry, but you're still forging. forge pause will pause the process. Once you've regained balance you can use satiation and eat, then forge restart.

An hour later you decide to give up on your quest for a cool sword and want to go bash or soemthing. forge finish will finish the sword you're working on and stop, forge stop will kill everything and end it right away (the sword you're currently working on will still be in the forge).

And here is the raw code for everyone too lazy to click above!
CODE
;###################;
;####  forging  ####;
;###################;


/set forging_item_type=
/set forging_item_number=
/set forging_item_action=
/set forging_item_action_start=
/set forging_order_total=
/set forging_stats_met=
/set forging_stats_notmet=
/set forging_overallstats=
/set forging_singlestat_1=
/set forging_singlestat_2=
/set forging_singlestat_3=
/set forging_totalstat_1=
/set forging_totalstat_2=
/set forging_totalstat_3=
/set forging_process_type=
/set forging_process_paused=0
/set forging_process_finish=0
/set forging_in_progress=0

;### take out the necessary comms and set necessary forging values (type, action, and action_start)
;### syntax: /forging_outr_comms
/def forging_outr_comms = \\
   /if ({#} > 0) \\
;       # masterweapons
       /if ({1} == 876) \\
           outr 100 steel %; \\
           outr 20 iron %; \\
           /set forging_item_type=rapier %; \\
           /set forging_item_action=forge %; \\
           /set forging_item_action_start=forge for %; \\
       /elseif ({1} == 943) \\
           outr 50 steel %; \\
           outr 20 gold %; \\
           outr 20 silver %; \\
           outr 15 platinum %; \\
           /set forging_item_type=broadsword %; \\
           /set forging_item_action=forge %; \\
           /set forging_item_action_start=forge for %; \\
       /elseif ({1} == 1204) \\
           outr 70 steel %; \\
           outr 10 onyx %; \\
           outr 10 silk %; \\
           outr 10 sapphire %; \\
           /set forging_item_type=katana %; \\
           /set forging_item_action=forge %; \\
           /set forging_item_action_start=forge for %; \\
       /elseif ({1} == 1254) \\
           outr 100 steel %; \\
           outr 50 silver %; \\
           outr 50 platinum %; \\
           outr 10 coal %; \\
           /set forging_item_type=waraxe %; \\
           /set forging_item_action=forge %; \\
           /set forging_item_action_start=forge for %; \\
;       # masterarmour
       /elseif ({1} == 1077) \\
           outr 20 steel %; \\
           outr 20 platinum %; \\
           outr 135 iron %; \\
           outr 40 silver %; \\
           outr 10 coal %; \\
           /set forging_item_type=full plate %; \\
           /set forging_item_action=forge %; \\
           /set forging_item_action_start=forge for %; \\
       /else \\
           /echol BCcyan 0 <<<< forging_outr_comms error: the item number you provided does not exist. %; \\
           forge stop %; \\
       /endif %; \\
   /else \\
       /echol BCcyan 0 <<<< forging_outr_comms error: you must provide an item number. %; \\
       forge stop %; \\
   /endif

;### smelt the item and get the necessary comms from the forge
;### syntax: /forging_smelt_comms
/def forging_smelt_comms = \\
   /if ({#} > 0) \\
;       # masterweapons
       /if ({1} == 876) \\
           smelt rapier %; \\
           get steel from forge %; \\
           get iron from forge %; \\
           inr steel %; \\
           inr iron %; \\
       /elseif ({1} == 943) \\
           smelt broadsword %; \\
           get steel from forge %; \\
           get gold from forge %; \\
           get silver from forge %; \\
           get platinum from forge %; \\
           inr steel %; \\
           inr gold %; \\
           inr silver %; \\
           inr platinum %; \\
       /elseif ({1} == 1204) \\
           smelt katana %; \\
           get steel from forge %; \\
           inr steel %; \\
       /elseif ({1} == 1254) \\
           smelt waraxe %; \\
           get steel from forge %; \\
           get silver from forge %; \\
           get platinum from forge %; \\
           inr steel %; \\
           inr silver %; \\
           inr platinum %; \\
;       # masterarmour
       /elseif ({1} == 1077) \\
           smelt fullplate %; \\
           get steel from forge %; \\
           get platinum from forge %; \\
           get iron from forge %; \\
           get silver from forge %; \\
           inr steel %; \\
           inr platinum %; \\
           inr iron %; \\
           inr silver %; \\
       /else \\
           /echol BCcyan 0 <<<< forging_smelt_comms error: the item number you provided does not exist. %; \\
       /endif %; \\
   /else \\
       /echol BCcyan 0 <<<< forging_smelt_comms error: you must provide an item number. %; \\
   /endif

;### put away any excess comms
;### syntax: /forging_inr_comms
/def forging_inr_comms = \\
   inr coal %; \\
   inr gold %; \\
   inr iron %; \\
   inr onyx %; \\
   inr platinum %; \\
   inr sapphire %; \\
   inr silk %; \\
   inr silver %; \\
   inr steel

;### assists in pausing the forging process between finishing one item and starting another (reduces failed forging spam due to prompts received from outr'ing comms and whatnot)
;### syntax: /delay_next_forge
/def delay_next_forge = \\
   /set forging_process_paused=1 %; \\
   /def -n1 -p50 -t"^You lay the commodities out before you on " forging_unpause_process = /set forging_process_paused=0

;### compares the stats of the forged item with the requirements desired, saves the item if requirements are met, continues forging unless finished
;### syntax: /forging_compare_stats (weapon|armor)
/def forging_compare_stats = \\
   /if (({#} == 4) & (({1} =~ "weapon") | ({1} =~ "armor"))) \\
       /let compare_type=%{1} %; \\
       /let stat_1=%{2} %; \\
       /let stat_2=%{3} %; \\
       /let stat_3=%{4} %; \\
       /if ({compare_type} =~ "weapon") \\
           /let stat_1_name=damage %; \\
           /let stat_2_name=precision %; \\
           /let stat_3_name=speed %; \\
           /let stat_total=$ %; \\
       /else \\
           /let stat_1_name=cutting %; \\
           /let stat_2_name=blunt %; \\
           /let stat_3_name=armor status %; \\
           /let stat_total=$ %; \\
       /endif %; \\
       /let keep_item=0 %; \\
;       # compare the over stat total
       /if (({forging_overallstats} != 0) & ({stat_total} >= {forging_overallstats})) \\
           /let keep_item=1 %; \\
           /echol BCcyan 0 <<<< met overall stats - %{stat_total} >= %{forging_overallstats} >>>> %; \\
       /endif %; \\
;       # compare the single damage stat
       /if (({forging_singlestat_1} != 0) & ({stat_1} >= {forging_singlestat_1})) \\
           /let keep_item=1 %; \\
           /echol BCcyan 0 <<<< met %{stat_1_name} stat - %{stat_1} >= %{forging_singlestat_1} >>>> %; \\
       /endif %; \\
;       # compare the single precision stat
       /if (({forging_singlestat_2} != 0) & ({stat_2} >= {forging_singlestat_2})) \\
           /let keep_item=1 %; \\
           /echol BCcyan 0 <<<< met %{stat_2_name} stat - %{stat_2} >= %{forging_singlestat_2} >>>> %; \\
       /endif %; \\
;       # compare the single speed stat
       /if (({forging_singlestat_3} != 0) & ({stat_3} >= {forging_singlestat_3})) \\
           /let keep_item=1 %; \\
           /echol BCcyan 0 <<<< met %{stat_3_name} stat - %{stat_3} >= %{forging_singlestat_3} >>>> %; \\
       /endif %; \\
;       # compare the total combination of stats
       /if (((({forging_totalstat_1} == 0) | ({stat_1} >= {forging_totalstat_1})) & (({forging_totalstat_2} == 0) | ({stat_2} >= {forging_totalstat_2})) & (({forging_totalstat_3} == 0) | ({stat_3} >= {forging_totalstat_3}))) & (({forging_totalstat_1} != 0) | ({forging_totalstat_2} != 0) | ({forging_totalstat_3} != 0))) \\
           /let keep_item=1 %; \\
           /echol BCcyan 0 <<<< met combined stats - %{stat_1}-%{stat_2}-%{stat_3} >= %{forging_totalstat_1}-%{forging_totalstat_2}-%{forging_totalstat_3} >>>> %; \\
       /endif %; \\
;       # if the item met the requirements, pack it away
       /if ({keep_item} == 1) \\
           /test forging_stats_met += 1 %; \\
           putp1 %{forging_item_type} %; \\
           /echol BCcyan 0 <<<< item has met the stat requirements >>>> %; \\
;       # if the item failed to meet the requirements, smelt it down
       /else \\
           /test forging_stats_notmet += 1 %; \\
           /forging_smelt_comms %{forging_item_number} %; \\
           /echol BCcyan 0 <<<< item failed to reach the stat requirements >>>> %; \\
       /endif %; \\
;       # continue forging more items unless the finish flag has been set
       /if ({forging_process_finish} == 0) \\
           /forging_outr_comms %{forging_item_number} %; \\
           /sendl %{forging_item_action_start} %{forging_item_number} %; \\
           forge status %; \\
       /else \\
           forge stop %; \\
           /undef forging_unpause_process %; \\
           /echol BCcyan 0 <<<< forging complete >>>> %; \\
       /endif %; \\
   /else \\
       forge stop %; \\
       /undef forging_unpause_process %; \\
       /echol BCcyan 0 <<<< forging_compare_stats error: illegal arguments provided. %; \\
   /endif

;### utilize a forge for forging orders
;### syntax: forge ;###                order |
;###       (weapon) stats |
;###        (armor) stats >
;### note: for (armor) stats, should only include cutting and blunt, armor status is ignored.
/alias forge \\
;   # fire up a forge to prepare it for forging
   /if ({1} =~ "fire") \\
       /if ({forging_in_progress} == 0) \\
;           # if firing the forge fails, get the mercury and try again
           /def -n0 -p50 -t"^Good grief! As you attempt to fire up " forging_firing_failed = \\
               get mercury from forge %%; \\
               inr mercury %%; \\
               outr 1 coal %%; \\
               put coal into forge %%; \\
               fire forge %; \\
;           # if firing the forge succeeds, clean up the catches
           /def -n1 -p50 -t"^You light .*, and work the bellows until " forging_firing_succeed = \\
               /undef forging_firing_failed %; \\
           outr 1 coal %; \\
           put coal into forge %; \\
           fire forge %; \\
       /else \\
           /echol BCcyan 0 <<<< forging is already in progress >>>> %; \\
       /endif %; \\
;   # smelt an item for its comms
   /elseif ({1} =~ "smelt") \\
       /if ({forging_in_progress} == 0) \\
           /if ({#} == 2) \\
               /forging_smelt_comms %{2} %; \\
           /else \\
               /echol BCcyan 0 <<<< smelt error: illegal arguments, must be "smelt ". %; \\
           /endif %; \\
       /else \\
           /echol BCcyan 0 <<<< unable to smelt, forging is in progress >>>> %; \\
       /endif %; \\
;   # pause the forging of an order
   /elseif ({1} =~ "pause") \\
       /if ({forging_in_progress} == 1) \\
           /set forging_process_paused=1 %; \\
           /echol BCcyan 0 <<<< forging paused >>>> %; \\
       /else \\
           /echol BCcyan 0 <<<< there is no forging in progress to pause >>>> %; \\
       /endif %; \\
;   # finish forging after the current item
   /elseif ({1} =~ "finish") \\
       /if ({forging_in_progress} == 1) \\
           /set forging_process_finish=1 %; \\
           /echol BCcyan 0 <<<< forging will finish after this item >>>> %; \\
       /else \\
           /echol BCcyan 0 <<<< there is no forging in progress to finish >>>> %; \\
       /endif %; \\
;   # stop and cancel the forging of an order
   /elseif ({1} =~ "stop") \\
       /if ({forging_in_progress} == 1) \\
           /set forging_in_progress=0 %; \\
           /set forging_process_paused=0 %; \\
           /set forging_process_finish=0 %; \\
           /undef forging_unfired %; \\
           /undef forging_nocomms %; \\
           /undef forging_prompt_catch_forge %; \\
           /undef forging_finished %; \\
           /echol BCcyan 0 <<<< forging stopped >>>> %; \\
       /else \\
           /echol BCcyan 0 <<<< there is no forging in progress to stop >>>> %; \\
       /endif %; \\
;   # restart the forging process of a paused order
   /elseif ({1} =~ "restart") \\
       /if ({forging_in_progress} == 1) \\
           /set forging_process_paused=0 %; \\
           /sendl %{forging_item_action} %; \\
           /echol BCcyan 0 <<<< forging restarted >>>> %; \\
       /else \\
           /echol BCcyan 0 <<<< there is no forging in progress to restart >>>> %; \\
       /endif %; \\
;   # display the status of the current order
   /elseif ({1} =~ "status") \\
       /if ({forging_in_progress} == 1) \\
           /if ({forging_process_type} =~ "order") \\
               /echol BCcyan 0 <<<< ORDER - $ more items to forge after this one >>>> %; \\
           /else \\
               /echol BCcyan 0 <<<< STATS (%{forging_overallstats} %{forging_singlestat_1} %{forging_singlestat_2} %{forging_singlestat_3} %{forging_totalstat_1} %{forging_totalstat_2} %{forging_totalstat_3}) - $ items forged, %{forging_stats_met} met reqs >>>> %; \\
           /endif %; \\
       /else \\
           /echol BCcyan 0 <<<< there is no forging in progress >>>> %; \\
       /endif %; \\
;   # begin a new forging order
   /elseif (({1} =~ "order") | ({1} =~ "stats")) \\
       /if ({forging_in_progress} == 0) \\
           /if ((({1} =~ "order") & ({#} == 3)) | (({1} =~ "stats") & ({#} == 9))) \\
;               # set the appropriate forging flags and initialize the system for order or stats
               /set forging_in_progress=1 %; \\
               /set forging_process_type=%{1} %; \\
               /set forging_process_paused=0 %; \\
               /set forging_process_finish=0 %; \\
               /if ({forging_process_type} =~ "order") \\
                   /set forging_order_total=%{2} %; \\
                   /set forging_item_number=%{3} %; \\
               /else \\
                   /set forging_stats_met=0 %; \\
                   /set forging_stats_notmet=0 %; \\
                   /set forging_item_number=%{2} %; \\
                   /set forging_overallstats=%{3} %; \\
                   /set forging_singlestat_1=%{4} %; \\
                   /set forging_singlestat_2=%{5} %; \\
                   /set forging_singlestat_3=%{6} %; \\
                   /set forging_totalstat_1=%{7} %; \\
                   /set forging_totalstat_2=%{8} %; \\
                   /set forging_totalstat_3=%{9} %; \\
               /endif %; \\
;               # if the forge is not prepared, stop the forging process
               /def -n0 -p50 -t"^The forge is dark and cold\\\\.\\$" forging_unfired = \\
                   /forging_inr_comms %%; \\
                   forge stop %; \\
;               # if you do not have the proper comms, stop the forging process
               /def -n0 -p50 -t"^You do not have the required commodities to forge that\\\\.\\$" forging_nocomms = \\
                   /forging_inr_comms %%; \\
                   forge stop %; \\
;               # prompt catch to forge whenever you regain balance
               /def -n0 -p1050 -F -q -h"PROMPT (\\\\d+)h, (\\\\d+)m, (\\\\d+)e, (\\\\d+)p, (\\\\d+)en, (\\\\d+)w (.*)\\\\-" forging_prompt_catch_forge = \\
                   /if ({forging_process_paused} == 0) \\
                       /if (({status_balance} == 1) & ({status_equilibrium} == 1) & ({status_balance_arm_left} == 1) & ({status_balance_arm_right} == 1)) \\
                           /sendl %%{forging_item_action} %%; \\
                       /endif %%; \\
                   /endif %; \\
;               # catch for when the item is finished
               /def -n0 -p50 -t"^Your eye for detail tells you that" forging_finished = \\
                   /delay_next_forge %%; \\
;                   # when you've regained balance, remove the finished item from the forge and decide what to do next
                   /def -n0 -p1050 -F -q -h"PROMPT (\\\\\\\\d+)h, (\\\\\\\\d+)m, (\\\\\\\\d+)e, (\\\\\\\\d+)p, (\\\\\\\\d+)en, (\\\\\\\\d+)w (.*)\\\\\\\\-" forging_prompt_catch_get_item = \\
                       /if (({status_balance} == 1) & ({status_equilibrium} == 1) & ({status_balance_arm_left} == 1) & ({status_balance_arm_right} == 1)) \\
                           /undef forging_prompt_catch_get_item %%%; \\
                           get %%%{forging_item_type} from forge %%%; \\
;                           # if forging an order, make another item if the order is incomplete
                           /if ({forging_process_type} =~ "order") \\
                               /test forging_order_total -= 1 %%%; \\
                               /if (({forging_order_total} > 0) & ({forging_process_finish} == 0)) \\
                                   /forging_outr_comms %%%{forging_item_number} %%%; \\
                                   /sendl %%%{forging_item_action_start} %%%{forging_item_number} %%%; \\
                                   forge status %%%; \\
                               /else \\
                                   forge stop %%%; \\
                                   /undef forging_unpause_process %%%; \\
                                   /echol BCcyan 0 <<<< forging order complete >>>> %%%; \\
                               /endif %%%; \\
;                           # if forging for stats, determine whether to save the item by comparing its stats to the requirements, then continue forging another
                           /else \\
;                               # weaponprobe the finished item
                               /def -n1 -p50 -t'^"%%%{forging_item_type}(\\\\\\\\\\\\\\\\d+)"' forging_info_inv_catch = \\
                                   weaponprobe %%%%{P1} %%%; \\
;                               # catches for armor's weaponprobe data
                               /def -n1 -p50 -t"^Physical cutting:\\\\\\\\\\\\\\\\s+(\\\\\\\\\\\\\\\\d+)\\\\\\\\\\\\\\$" forging_weaponprobe_armor_catch1 = \\
                                   /set forging_weaponprobe_armor1=%%%%{P1} %%%; \\
                               /def -n1 -p50 -t"^Physical blunt:\\\\\\\\\\\\\\\\s+(\\\\\\\\\\\\\\\\d+)\\\\\\\\\\\\\\$" forging_weaponprobe_armor_catch2 = \\
                                   /set forging_weaponprobe_armor2=%%%%{P1} %%%; \\
                               /def -n1 -p50 -t"^Armour Status:\\\\\\\\\\\\\\\\s+(\\\\\\\\\\\\\\\\d+)\\\\\\\\\\\\\\$" forging_weaponprobe_armor_catch3 = \\
                                   /forging_compare_stats armor %%%%{forging_weaponprobe_armor1} %%%%{forging_weaponprobe_armor2} %%%%{P1} %%%%; \\
                                   /undef forging_weaponprobe_weapon_catch %%%%; \\
                                   /unset forging_weaponprobe_armor1 %%%%; \\
                                   /unset forging_weaponprobe_armor2 %%%; \\
;                               # catches for weapon's weaponprobe data
                               /def -n1 -p50 -t"^Damage: (\\\\\\\\\\\\\\\\d+)\\\\\\\\\\\\\\\\s+Precision: (\\\\\\\\\\\\\\\\d+)\\\\\\\\\\\\\\\\s+Speed: (\\\\\\\\\\\\\\\\d+)\\\\\\\\\\\\\\$" forging_weaponprobe_weapon_catch = \\
                                   /forging_compare_stats weapon %%%%{P1} %%%%{P2} %%%%{P3} %%%%; \\
                                   /undef forging_weaponprobe_armor_catch1 %%%%; \\
                                   /undef forging_weaponprobe_armor_catch2 %%%%; \\
                                   /undef forging_weaponprobe_armor_catch3 %%%; \\
                               info inv %%%{forging_item_type} %%%; \\
                               /echol BCcyan 0 <<<< comparing the item to the stat requirements >>>> %%%; \\
                           /endif %%%; \\
                       /endif %%; \\
                   /echol BCcyan 0 <<<< item complete >>>> %; \\
               /delay_next_forge %; \\
               /forging_outr_comms %{forging_item_number} %; \\
               forge status %; \\
               /sendl %{forging_item_action_start} %{forging_item_number} %; \\
           /else \\
               /echol BCcyan 0 <<<< forge error: illegal arguments provided. %; \\
           /endif %; \\
       /else \\
           /echol BCcyan 0 <<<< forging is already in progress >>>> %; \\
       /endif %; \\
   /else \\
       /echol BCcyan 0 <<<< forge error: you provided an illegal option. %; \\
   /endif