guyudennis Posted August 10, 2021 Share Posted August 10, 2021 First I have a 2da file set up as this: Spoiler spdr101 WIZARD_BURNING_HANDS spdr102 WIZARD_SHOCKING_GRASP spdr201 WIZARD_STINKING_CLOUD spdr202 WIZARD_AGANNAZAR_SCORCHER spdr301 WIZARD_FIREBALL spdr302 WIZARD_LIGHTNING_BOLT spdr401 WIZARD_ICE_STORM spdr402 WIZARD_FIRE_SHIELD_RED spdr501 WIZARD_CONE_OF_COLD spdr502 WIZARD_SUN_FIRE spdr601 WIZARD_DEATH_FOG spdr602 WIZARD_CHAIN_LIGHTNING spdr701 WIZARD_PROTECTION_FROM_THE_ELEMENTS spdr702 WIZARD_DELAYED_BLAST_FIREBALL Then I have the following code in my tp2: Spoiler COPY ~yys_tweaks/2da/avenger_spl.2da~ ~override~ // copy specific file PATCH_IF (MOD_IS_INSTALLED ~setup-iwdification.tp2~ ~30~) BEGIN // if iwdification wizard spell pack is installed REPLACE_TEXTUALLY ~WIZARD_STINKING_CLOUD~ ~WIZARD_SNILLOCS_SNOWBALL_SWARM~ REPLACE_TEXTUALLY ~WIZARD_LIGHTNING_BOLT~ ~WIZARD_ICELANCE~ REPLACE_TEXTUALLY ~WIZARD_FIRE_SHIELD_RED~ ~WIZARD_VITRIOLIC_SPHERE~ REPLACE_TEXTUALLY ~WIZARD_SUN_FIRE~ ~WIZARD_SHROUD_OF_FLAME~ REPLACE_TEXTUALLY ~WIZARD_DEATH_FOG~ ~WIZARD_OTILUKES_FREEZING_SPHERE~ REPLACE_TEXTUALLY ~WIZARD_PROTECTION_FROM_THE_ELEMENTS~ ~WIZARD_ACID_STORM~ END COUNT_2DA_COLS cols // count the max column number READ_2DA_ENTRIES_NOW rows cols // read the selected content into memory FOR (row = 0; row < rows; ++row) BEGIN // iterate through all spells READ_2DA_ENTRY_FORMER rows row 0 avg_spl // read from memory the selected value and store it READ_2DA_ENTRY_FORMER rows row 1 spl_ids_syl // read from memory the selected value and store it LAF RES_NUM_OF_SPELL_NAME STR_VAR spell_name = EVAL ~%spl_ids_syl%~ RET spell_res END // launch macro to return spell resource INNER_ACTION BEGIN COPY_EXISTING ~%%spell_res%.spl%~ ~override/%avg_spl%.spl~ // copy specific file over WRITE_SHORT 0x1C 2 // set spell type to priest BUT_ONLY END PRINT "Successfully converted wizard spell %spell_res% to druid spell %avg_spl%" // mumble success for debug purpose END BUT_ONLY But when executing the code Weidu spits out a parsing error: Spoiler [./weidu] WeiDU version 24700 In state 1548, I expected one of these tokens: [254] END Parse error (state 1548) at LAUNCH_ACTION_FUNCTION [yys_tweaks/yys_tweaks.tp2] PARSE ERROR at line 273 column 1-7 Near Text: LAF GLR parse error [yys_tweaks/yys_tweaks.tp2] ERROR at line 273 column 1-7 Near Text: LAF Parsing.Parse_error ERROR: parsing [yys_tweaks/yys_tweaks.tp2]: Parsing.Parse_error ERROR: problem parsing TP file [yys_tweaks/yys_tweaks.tp2]: Parsing.Parse_error FATAL ERROR: Parsing.Parse_error Press ENTER to exit. Can anyone help me find out what I'm missing here? Must be something obvious? Thanks in advance! Quote Link to comment
Magus Posted August 10, 2021 Share Posted August 10, 2021 (edited) LAF is short for LAUNCH_ACTION_FUNCTION, which is an action, but you're using it in patch context. Edited August 10, 2021 by Magus Quote Link to comment
guyudennis Posted August 11, 2021 Author Share Posted August 11, 2021 Switching to LPF and taking out a couple of erroneously placed extra % around the variables did the trick. Thank you! Now onto figuring out code to loop through the generated druid spells and change all immunity to resource targets from old wizard spells to new druid spells… Quote Link to comment
subtledoctor Posted August 11, 2021 Share Posted August 11, 2021 (edited) 2 hours ago, guyudennis said: Now onto figuring out code to loop through the generated druid spells and change all immunity to resource targets from old wizard spells to new druid spells… I once created a function to do that sort of thing. It was adapted (i.e. copied and then viciously deformed) from Weidu's CLONE_EFFECT patch function. You use it like: INCLUDE ~%MOD_FOLDER%/lib/spell_clone_effects.tpa~ COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~ LPF SPELL_CLONE_EFFECTS INT_VAR match_opcode=206 STR_VAR match_resource=~spwi103~ resource=~spdr101~ END BUT_ONLY COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~ LPF SPELL_CLONE_EFFECTS INT_VAR match_opcode=206 STR_VAR match_resource=~spwi103~ resource=~spdr101~ END BUT_ONLY Something like that. And repeat for each spell. My first version of that took 45 minutes to run. The version I linked to now took about 4 minutes to run. Much better... but still painfully slow. The best way to do this is to use old-fashioned GET_OFFSET_ARRAY to manually look at the effects of every spell and item, and the resource field of files with matching effects; make a list of the ones that need patching; and then just patch the ones in the list. Something like: COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ override SET slot_item = 0 PATCH_IF SOURCE_SIZE > 0x72 BEGIN GET_OFFSET_ARRAY glob_fx ITM_V10_GEN_EFFECTS PHP_EACH glob_fx AS idx => off BEGIN PATCH_IF (SHORT_AT off == 206) OR (SHORT_AT off == 321) OR (SHORT_AT off == 318) OR (SHORT_AT off == 324) BEGIN SET slot_item = 1 READ_ASCII off + 0x16 resource PATCH_IF (~%resource%~ STRING_EQUAL_CASE ~spwi103~) BEGIN TEXT_SPRINT $burning_hands_items(~%SOURCE_RES%~) ~1~ END END END END BUT_ONLY [and ditto for spells] ACTION_PHP_EACH burning_hands_items AS file => ind BEGIN COPY_EXISTING ~%file%.itm~ ~override~ LPF CLONE_EFFECT STR_VAR match_resource = ~spwi103~ resource = ~spdr101~ END BUT_ONLY END [and ditto for spells] It'd be a bit annoying to do that for all your spell replacements, but it would be quite fast. Edited August 11, 2021 by subtledoctor Quote Link to comment
guyudennis Posted August 12, 2021 Author Share Posted August 12, 2021 (edited) Thanks. I could not for the life of mine get that array going. For the FnP macro, I went as far as getting your SPELL_CLONE_EFFECTS to properly clone the effect, but the new resource could not be inserted, and I ended up with two identical effects. In the end, I went with the most basic solution with the standard Weidu CLONE_EFFECT, but painfully slow as you said. Edited August 12, 2021 by guyudennis Quote Link to comment
guyudennis Posted August 13, 2021 Author Share Posted August 13, 2021 Finally got the array to work. Thanks once again, @Magus and @subtledoctor. Here's the final code just in case anyone is interested: Spoiler BEGIN @10000 DESIGNATED 100 INCLUDE ~yys_tweaks/lib/remove_lines.tpa~ // macro to remove empty lines within file, borrowed from Tweaks-Anthology COPY_EXISTING ~clabdr04.2da~ ~override~ PATCH_FOR_EACH spelltarget IN ~GA_SPCL611~ ~GA_SPCL612~ ~GA_SPCL613~ ~GA_SPCL632~ ~GA_SPCL633~ ~GA_SPCL634~ ~GA_cdidrbb~ ~GA_cdidrww~ ~GA_cdidrpb~ ~GA_cdidrfe~ ~GA_cdidree~ ~GA_cdidrwe~ BEGIN // set original avenger shapeshifting abilities as targets to remove REPLACE_TEXTUALLY ~%spelltarget%~ ~**** ~ END LPM remove_blank_lines APPEND_FILE ~yys_tweaks/2da/avenger_clab.2da~ BUT_ONLY COPY ~yys_tweaks/2da/avenger_spl.2da~ ~override~ PATCH_IF (MOD_IS_INSTALLED ~setup-iwdification.tp2~ ~30~) BEGIN // if iwdification wizard spell pack is installed REPLACE_TEXTUALLY ~WIZARD_STINKING_CLOUD~ ~WIZARD_SNILLOCS_SNOWBALL_SWARM~ REPLACE_TEXTUALLY ~WIZARD_LIGHTNING_BOLT~ ~WIZARD_ICELANCE~ REPLACE_TEXTUALLY ~WIZARD_FIRE_SHIELD_RED~ ~WIZARD_VITRIOLIC_SPHERE~ REPLACE_TEXTUALLY ~WIZARD_SUN_FIRE~ ~WIZARD_SHROUD_OF_FLAME~ REPLACE_TEXTUALLY ~WIZARD_DEATH_FOG~ ~WIZARD_OTILUKES_FREEZING_SPHERE~ REPLACE_TEXTUALLY ~WIZARD_PROTECTION_FROM_THE_ELEMENTS~ ~WIZARD_ACID_STORM~ END COUNT_2DA_COLS cols READ_2DA_ENTRIES_NOW rows cols FOR (row = 0; row < rows; ++row) BEGIN READ_2DA_ENTRY_FORMER rows row 0 avg_spl READ_2DA_ENTRY_FORMER rows row 1 spl_ids_syl LPF RES_NUM_OF_SPELL_NAME STR_VAR spell_name = EVAL ~%spl_ids_syl%~ RET spell_res END INNER_ACTION BEGIN COPY_EXISTING ~%spell_res%.spl~ ~override/%avg_spl%.spl~ WRITE_SHORT 0x1C 2 // set spell type to priest BUT_ONLY COPY_EXISTING_REGEXP GLOB ~^.+\.spl$~ ~override~ PATCH_IF (SOURCE_SIZE > 0x71) BEGIN GET_OFFSET_ARRAY ab_array_spl SPL_V10_HEADERS PHP_EACH ab_array_spl AS int => ab_off BEGIN GET_OFFSET_ARRAY2 fx_array_spl ab_off SPL_V10_HEAD_EFFECTS PHP_EACH fx_array_spl AS int => fx_off BEGIN READ_SHORT fx_off fx_type PATCH_IF ((fx_type = 206) OR (fx_type = 321) OR (fx_type = 318) OR (fx_type = 324)) BEGIN READ_ASCII fx_off + 0x14 resource PATCH_IF (~%resource%~ STRING_EQUAL_CASE EVAL ~%spell_res%~) BEGIN TEXT_SPRINT $spls_to_patch(~%SOURCE_RES%~) ~1~ END END END END END BUT_ONLY ACTION_PHP_EACH spls_to_patch AS file => ind BEGIN COPY_EXISTING ~%file%.spl~ ~override~ LPF CLONE_EFFECT STR_VAR match_resource = EVAL ~%spell_res%~ resource = EVAL ~%avg_spl%~ END BUT_ONLY END COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~ PATCH_IF (SOURCE_SIZE > 0x71) BEGIN GET_OFFSET_ARRAY ab_array_itm ITM_V10_HEADERS PHP_EACH ab_array_itm AS int => ab_off BEGIN GET_OFFSET_ARRAY2 fx_array_itm ab_off ITM_V10_HEAD_EFFECTS PHP_EACH fx_array_itm AS int => fx_off BEGIN READ_SHORT fx_off fx_type PATCH_IF ((fx_type = 206) OR (fx_type = 321) OR (fx_type = 318) OR (fx_type = 324)) BEGIN READ_ASCII fx_off + 0x14 resource PATCH_IF (~%resource%~ STRING_EQUAL_CASE EVAL ~%spell_res%~) BEGIN TEXT_SPRINT $itms_to_patch(~%SOURCE_RES%~) ~1~ END END END END END BUT_ONLY ACTION_PHP_EACH itms_to_patch AS file => ind BEGIN COPY_EXISTING ~%file%.itm~ ~override~ LPF CLONE_EFFECT STR_VAR match_resource = EVAL ~%spell_res%~ resource = EVAL ~%avg_spl%~ END BUT_ONLY END PRINT "Successfully converted wizard spell %spell_res% to druid spell %avg_spl%" END END BUT_ONLY Quote Link to comment
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.