Skip to content

Need help with a copy and patching function.

Gel87Gel87 Member Posts: 412
edited May 8 in General Modding
Yo.

Im trying to do 3 things and they are really not working out for me.

1:
Copy all cleric spells between SPPR100 and SPPR720 -> GelC100 to GelC720.
Change them to spelltype wizard. Then learn all copied spells via adding OP code 147 to GelCLea.spl. The spell is made and copied earlier with its spell ability 0 having zero effects.

2:
Then the excact same for druid spells. SPPR100 and 720 -> GelD100 to GelC720, GelDLea.spl is adding OP code 147 for theese..

3:
Then copy all druid spells between SPPR100 and 720 -> GelA100 to GelA720, remove exclusion flag for cleric and GelALea.spl to learn them.

They are going to be used theese ways(this i have ready) :
"I want my Mage/Thief to become a Mage / Cleric / Thief" -> Kitchange and AP_GelCLea via clab.
"I also want to add all druid spells into my arcane mage book" -> GelDLea
"I want to add all druid spells into my devine spellbook" -> GelALea


Functions i have tried:
This one miss the stop after 720, and it fails to install:
// =============================================
// 1. GELC - Cleric → Wizard
// =============================================
OUTER_TEXT_SPRINT GelC_list ""

COPY_EXISTING_REGEXP GLOB ~^SPPR[1-7][0-9][0-9]\.spl~ ~.~
  PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
    READ_LONG 0x001E excl_flags

    PATCH_IF (excl_flags & 0x40000000) = 0 BEGIN
      SPRINT newres ~GelC%SOURCE_RES%~
      OUTER_TEXT_SPRINT GelC_list ~%GelC_list% %newres%~

      COPY ~%SOURCE_FILE%~ ~override/%newres%.spl~
      INNER_PATCH_FILE ~override/%newres%.spl~ BEGIN
        WRITE_BYTE 0x001C 1
        WRITE_LONG 0x001E 0
      END
    END
  END
END
BUT_ONLY

// =============================================
// 2. GELD - Druid → Wizard
// =============================================
OUTER_TEXT_SPRINT GelD_list ""
COPY_EXISTING_REGEXP GLOB ~^SPPR[1-7][0-9][0-9]\.spl$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
    READ_LONG 0x001E excl_flags
    PATCH_IF (excl_flags & 0x80000000) <> 0 BEGIN
      SPRINT newres ~GelD%SOURCE_RES:~4%~
      OUTER_TEXT_SPRINT GelD_list ~%GelD_list% %newres%~
      
      COPY ~%SOURCE_FILE%~ ~override/%newres%.spl~
      INNER_PATCH_FILE ~override/%newres%.spl~ BEGIN
        WRITE_BYTE 0x001C 1
        WRITE_LONG 0x001E 0
      END
    END
  END
BUT_ONLY

// =============================================
// 3. GELA - Druid → Cleric
// =============================================
OUTER_TEXT_SPRINT GelA_list ""
COPY_EXISTING_REGEXP GLOB ~^SPPR[1-7][0-9][0-9]\.spl$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
    READ_LONG 0x001E excl_flags
    PATCH_IF (excl_flags & 0x80000000) <> 0 BEGIN
      SPRINT newres ~GelA%SOURCE_RES:~4%~
      OUTER_TEXT_SPRINT GelA_list ~%GelA_list% %newres%~
      
      COPY ~%SOURCE_FILE%~ ~override/%newres%.spl~
      INNER_PATCH_FILE ~override/%newres%.spl~ BEGIN
        WRITE_BYTE 0x001C 0
        WRITE_LONG 0x001E (excl_flags & ~0x80000000)
      END
    END
  END
BUT_ONLY

// =============================================
// 4. Learn Spell effekter - separat og forsiktig
// =============================================

ACTION_IF (~%GelC_list%~ STRING_COMPARE_CASE "" <> 0) BEGIN
  COPY_EXISTING ~GelCLea.spl~ ~override~
    ACTION_FOR_EACH spell IN %GelC_list% BEGIN
      LPF ADD_SPELL_EFFECT INT_VAR opcode = 147 target = 1 timing = 9
      STR_VAR resource = EVAL ~%spell%~ END
    END
  BUT_ONLY
END

ACTION_IF (~%GelD_list%~ STRING_COMPARE_CASE "" <> 0) BEGIN
  COPY_EXISTING ~GelDLea.spl~ ~override~
    ACTION_FOR_EACH spell IN %GelD_list% BEGIN
      LPF ADD_SPELL_EFFECT INT_VAR opcode = 147 target = 1 timing = 9
      STR_VAR resource = EVAL ~%spell%~ END
    END
  BUT_ONLY
END

ACTION_IF (~%GelA_list%~ STRING_COMPARE_CASE "" <> 0) BEGIN
  COPY_EXISTING ~GelALea.spl~ ~override~
    ACTION_FOR_EACH spell IN %GelA_list% BEGIN
      LPF ADD_SPELL_EFFECT INT_VAR opcode = 147 target = 1 timing = 9
      STR_VAR resource = EVAL ~%spell%~ END
    END
  BUT_ONLY
END

PRINT "GelC: %GelC_list%"
PRINT "GelD: %GelD_list%"
PRINT "GelA: %GelA_list%"

Theese ones fails to install as well:
OUTER_SET GelCSpellCount = 0

OUTER_FOR (num = 100; num <= 720; ++num) BEGIN

  OUTER_SPRINT spell ~SPPR%num%~

  ACTION_IF FILE_EXISTS_IN_GAME ~%spell%.spl~ BEGIN

    COPY_EXISTING ~%spell%.spl~ ~override~

      READ_LONG 0x001e excl

      PATCH_IF (excl = 30) BEGIN

        SPRINT newres ~GelC%num%~

        OUTER_SET GelCSpellCount += 1
        OUTER_SPRINT GelCSpell_%GelCSpellCount% ~%newres%~

      END

    BUT_ONLY

    ACTION_IF (excl = 30) BEGIN

      COPY ~%spell%.spl~ ~override/%newres%.spl~

      INNER_PATCH_FILE ~override/%newres%.spl~ BEGIN
        WRITE_BYTE 0x001c 1
        WRITE_LONG 0x001e 0
      END

    END

  END

END
Sign In or Register to comment.