Jump to content

Help with some functions


Recommended Posts

I need a function that removes all level 9 arcane spells from creatures with class "caster" and level > 18.  Solved

I've got a bug with my current install that's causing every mage in my game to get a 9th level spell, and unfortunately many of them have the script blocks to cast it. 

 

 

The second thing I'm trying to do is substitute out all fiend summoning spells from non-evil conjurers. There's something in the code below that's causing an error. WIZARD_MONSTER_SUMMONING_6 is added with SR. 

Spoiler
////////////////////////////// only evil aligned conjurers summon demons //////////////////////////////////////

DEFINE_PATCH_FUNCTION mage_spell_swap_alignment
     INT_VAR level=0
     STR_VAR spells=""
             kit=""
             alignment=""
     RET spells
BEGIN
    TO_UPPER alignment
    PATCH_MATCH ~%alignment%~ WITH LAWFUL_GOOD NEUTRAL_GOOD CHAOTIC_GOOD LAWFUL_NEUTRAL NEUTRAL CHAOTIC_NEUTRAL BEGIN
     PATCH_IF (level>13 && ~%kit%~ STRING_EQUAL_CASE conjurer) BEGIN
         LPF substitute_spells STR_VAR spells swap_out=CACOFIEND swap_in=~MORDENKAINENS_SWORD WIZARD_POWER_WORD_STUN~ RET spells=spells END
         LPF substitute_spells STR_VAR spells swap_out=SUMMON_FIEND swap_in=WIZARD_MONSTER_SUMMONING_6 RET spells=spells END
         LPF substitute_spells STR_VAR spells swap_out=GATE swap_in=~ABSOLUTE_IMMUNITY WIZARD_SPELL_STRIKE~ RET spells=spells END
     END

END

 

I run the above function with 

Spoiler

// fine-tune remaining spells

      LPF mage_spell_swap_race STR_VAR kit race spells RET spells=spells END
      LPF mage_spell_swap_level INT_VAR level STR_VAR kit spells RET spells=spells END
      LPF mage_spell_swap_alignment INT_VAR level STR_VAR kit spells alignment RET spells=spells END
      PATCH_IF spells_are_bg1=1 BEGIN
         LPF mage_spell_swap_bg1 STR_VAR spells RET spells=spells END
      END

Thanks

Edited by WanderingScholar
Link to comment

Well, let's start with the obvious surface-level problem: your BEGINs and ENDs don't match. You have two ENDs at the end, where you need three; one for the IF block, one for the MATCH block, and one for the function definition. Judging by your indentation, it's the MATCH block that's missing its END. But when WeiDU goes to parse this, it assigns that second END to the MATCH block, leaving the function definition open, and whatever's next in that document becomes part of the function when it isn't supposed to be, at least until the whole thing collapses in syntax errors that appear to point somewhere far from the actual problem. Or, worse, it runs and does things you weren't expecting at all.

Link to comment
5 minutes ago, jmerry said:

Well, let's start with the obvious surface-level problem: your BEGINs and ENDs don't match. You have two ENDs at the end, where you need three; one for the IF block, one for the MATCH block, and one for the function definition. Judging by your indentation, it's the MATCH block that's missing its END. But when WeiDU goes to parse this, it assigns that second END to the MATCH block, leaving the function definition open, and whatever's next in that document becomes part of the function when it isn't supposed to be, at least until the whole thing collapses in syntax errors that appear to point somewhere far from the actual problem. Or, worse, it runs and does things you weren't expecting at all.

Yep, that would explain why I'm getting errors further down the page. It was really confusing me. Still learning 🙄

Link to comment
Posted (edited)

Darn it, I should have tested this right away after making the change. I got distracted with something else and assumed I'd found the answer.

I still get a parse error. What on earth is it upset about!?Screenshot_20240102_083954.thumb.png.3c8510a79b5a9a9474375f795ee7d62d.png

Spoiler
////////////////////////////// only evil aligned conjurers summon demons //////////////////////////////////////

DEFINE_PATCH_FUNCTION mage_spell_swap_alignment
     INT_VAR level=0
     STR_VAR spells=""
             kit=""
             alignment=""
     RET spells
BEGIN
    TO_LOWER alignment
    PATCH_MATCH ~%alignment%~ WITH lawful_good neutral_good chaotic_good lawful_neutral neutral chaotic_neutral BEGIN
        PATCH_IF (level>13 && ~%kit%~ STRING_EQUAL_CASE conjurer) BEGIN
         LPF substitute_spells STR_VAR spells swap_out=CACOFIEND swap_in=~MORDENKAINENS_SWORD POWER_WORD_STUN~ RET spells=spells END
         LPF substitute_spells STR_VAR spells swap_out=SUMMON_FIEND swap_in=MONSTER_SUMMONING_LEVEL_6 RET spells=spells END
         LPF substitute_spells STR_VAR spells swap_out=GATE swap_in=MONSTER_SUMMONING_LEVEL_9 RET spells=spells END
        END    
    END
END

One END for the PATCH_IF, PATCH_MATCH, and DEFINE_PATCH_FUNCTION.

The whole setup file is filled with functions structured the exact same way.

NVM. The second END needed to be END DEFAULT END. 😮‍💨

Edited by WanderingScholar
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...