Jump to content

Dynamically create an array (matrix?) at install of filenames


Grammarsalad

Recommended Posts

Okay, here's what I'm trying to do: I want to create an array of filenames of all wands, and then clone an effect in a spell excluding use of that wand using effect 180.
So, the code I have works in that it dynamically patches my spl with only the filenames of wands...but, it copies ALL items into the override folder. Whenever I try BUT_ONLY, weidu returns an error.
Is there a way for me to do this without copying all items into the override folder?
Here's what I have
COPY ~proficiency/data/proficiency/b_wnd01.SPL~ ~override~   //
//Now, only excludes wand of fear, WAND02.  (BE SURE TO EXCLUDE WAND02 here)!!!!Need to add all others...
COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
 PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
 READ_SHORT 0x1c ~itemtype~
   PATCH_IF (~itemtype~ = 35) BEGIN  //only if a wand
            INNER_ACTION BEGIN
            INCLUDE ~proficiency/lib/wand_list.tpa~
   END
 END
END
//clone
ACTION_PHP_EACH use AS block => rock BEGIN
  ACTION_IF (~%rock%~ STRING_EQUAL ~wand~) BEGIN
     COPY_EXISTING ~b_wnd01.SPL~ ~override~
       LPF CLONE_EFFECT INT_VAR multi_match = 1 match_opcode = 180 STR_VAR resource = EVAL ~%block%~ END
  END
END

My wand_list file has this:

 

ACTION_DEFINE_ASSOCIATIVE_ARRAY use BEGIN


~%SOURCE_RES%~ => wand


END

 

Link to comment

I wrote something like that so that my unicorn rider kit can't wear chain mails (but elven ones).

COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
....
            PATCH_IF ("%animation%" STRING_EQUAL_CASE "3A") BEGIN
                LPF ~GW_CHECK_MAIL~ RET GW_Splint_mail GW_Chain_mail END // function defining whether it is a splint or a chain mail (not elven)
                PATCH_IF ("%GW_Chain_mail%" = 1) BEGIN // It is not an elven chain mail
                     DEFINE_ASSOCIATIVE_ARRAY GW_Cant_wear_this_Mail BEGIN "%DEST_RES%" => 0 END
                    END
               END
....
other checks
....
    END        // of PATCH_IF (SOURCE_SIZE > 0x71)
BUT_ONLY


This part does not copy the item files into override.

 

Then

COPY_EXISTING ~GWCL001.spl~ ~override~
    PHP_EACH GW_Cant_wear_this_Mail AS mail => nowear BEGIN
        LPF ADD_SPELL_EFFECT INT_VAR opcode = 180 target = 2 timing = 9 parameter1 = RESOLVE_STR_REF (@7720010) STR_VAR resource = EVAL "%mail%" END    // Item: Can't Use Item [180] - @7720010 = ~Les Chevaucheuses de licorne ne peuvent pas porter de cottes de mailles~ = unicorn riders can't wear chain mails
    END
BUT_ONLY
ACTION_CLEAR_ARRAY GW_Cant_wear_this_Mail

You might be able to adapt it to your needs.

Link to comment

I wrote something like that so that my unicorn rider kit can't wear chain mails (but elven ones).

COPY_EXISTING_REGEXP GLOB ~^.+\.itm$~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
....
            PATCH_IF ("%animation%" STRING_EQUAL_CASE "3A") BEGIN
                LPF ~GW_CHECK_MAIL~ RET GW_Splint_mail GW_Chain_mail END // function defining weither it is a splint or a chain mail (not elven)
                PATCH_IF ("%GW_Chain_mail%" = 1) BEGIN // It is not an elven chain mail
                     DEFINE_ASSOCIATIVE_ARRAY GW_Cant_wear_this_Mail BEGIN "%DEST_RES%" => 0 END
                    END
               END
....
other checks
....
    END        // of PATCH_IF (SOURCE_SIZE > 0x71)
BUT_ONLY


This part does not copy the item files into override.

 

Then

COPY_EXISTING ~GWCL001.spl~ ~override~
    PHP_EACH GW_Cant_wear_this_Mail AS mail => nowear BEGIN
        LPF ADD_SPELL_EFFECT INT_VAR opcode = 180 target = 2 timing = 9 parameter1 = RESOLVE_STR_REF (@7720010) STR_VAR resource = EVAL "%mail%" END    // Item: Can't Use Item [180] - @7720010 = ~Les Chevaucheuses de licorne ne peuvent pas porter de cottes de mailles~ = unicorn riders can't wear chain mails
    END
BUT_ONLY
ACTION_CLEAR_ARRAY GW_Cant_wear_this_Mail
You might be able to adapt it to your needs.

Awesome! Thanks! I'll try it out

Link to comment

Gwendolyne already has you sorted on the important bits, so I'll just hop on this detail:

So, the code I have works in that it dynamically patches my spl with only the filenames of wands...but, it copies ALL items into the override folder. Whenever I try BUT_ONLY, weidu returns an error.


Given your original code, I'm guessing you're trying a BUT_ONLY like so

COPY ~proficiency/data/proficiency/b_wnd01.SPL~ ~override~   //
//Now, only excludes wand of fear, WAND02.  (BE SURE TO EXCLUDE WAND02 here)!!!!Need to add all others...
COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
 PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
 READ_SHORT 0x1c ~itemtype~
   PATCH_IF (~itemtype~ = 35) BEGIN  //only if a wand
            INNER_ACTION BEGIN
            INCLUDE ~proficiency/lib/wand_list.tpa~
   END
 END
END
//clone
ACTION_PHP_EACH use AS block => rock BEGIN
  ACTION_IF (~%rock%~ STRING_EQUAL ~wand~) BEGIN
     COPY_EXISTING ~b_wnd01.SPL~ ~override~
       LPF CLONE_EFFECT INT_VAR multi_match = 1 match_opcode = 180 STR_VAR resource = EVAL ~%block%~ END
  END
END
BUT_ONLY

The problem is that ACTION_PHP_EACH is, at the name implies, an action. Once you use it, it means WeiDU is done with the previous action, which in this case is your all-item COPY_EXISTING_REGEXP. The right place for a BUT_ONLY would be right before the ACTION_PHP_EACH,as that is the end of the C_E_R action. The error message from WeiDU is because ACTION_PHP_EACH, unlike the various flavors of COPY_EXISTING, doesn't support 'when' clauses such as BUT_ONLY, IF_EXISTS, etc.

Link to comment

Gwendolyne already has you sorted on the important bits, so I'll just hop on this detail:

 

So, the code I have works in that it dynamically patches my spl with only the filenames of wands...but, it copies ALL items into the override folder. Whenever I try BUT_ONLY, weidu returns an error.

Given your original code, I'm guessing you're trying a BUT_ONLY like so

COPY ~proficiency/data/proficiency/b_wnd01.SPL~ ~override~   //
//Now, only excludes wand of fear, WAND02.  (BE SURE TO EXCLUDE WAND02 here)!!!!Need to add all others...
COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
 PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
 READ_SHORT 0x1c ~itemtype~
   PATCH_IF (~itemtype~ = 35) BEGIN  //only if a wand
            INNER_ACTION BEGIN
            INCLUDE ~proficiency/lib/wand_list.tpa~
   END
 END
BUT_ONLY
//clone
ACTION_PHP_EACH use AS block => rock BEGIN
  ACTION_IF (~%rock%~ STRING_EQUAL ~wand~) BEGIN
     COPY_EXISTING ~b_wnd01.SPL~ ~override~
       LPF CLONE_EFFECT INT_VAR multi_match = 1 match_opcode = 180 STR_VAR resource = EVAL ~%block%~ END
  END
END
END
The problem is that ACTION_PHP_EACH is, at the name implies, an action. Once you use it, it means WeiDU is done with the previous action, which in this case is your all-item COPY_EXISTING_REGEXP. The right place for a BUT_ONLY would be right before the ACTION_PHP_EACH,as that is the end of the C_E_R action. The error message from WeiDU is because ACTION_PHP_EACH, unlike the various flavors of COPY_EXISTING, doesn't support 'when' clauses such as BUT_ONLY, IF_EXISTS, etc.
That's actually where i tried to put it (i.e. at the end of the C_E_R). I forget the exact error, but it was driving me crazy as that normally works (i copied the code from another working instance only adding the INNER_ACTION (with begin) and INCLUDE ~path~) Maybe I miffed something else up. I can't try it again at the moment as i don't have my computer available

 

Edit: edited the code to what gave me the error(by my recollection)

Link to comment

COPY ~proficiency/data/proficiency/b_wnd01.SPL~ ~override~ //
//Now, only excludes wand of fear, WAND02. (BE SURE TO EXCLUDE WAND02 here)!!!!Need to add all others...
COPY_EXISTING_REGEXP - GLOB ~.*\.itm~ ~override~ // notice the minus sign "-" to prevent actual copying
PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
READ_SHORT 0x1c ~itemtype~
PATCH_IF (~itemtype~ = 35) BEGIN //only if a wand
SET $wand_list("%SOURCE_RES%") = 1 // $ adds the variable to array
END
END


OUTER_SPRINT $wand_list("WAND02") = 0
OUTER_SPRINT $wand_list("wand02") = 0 // WeiDU is on my hate list (C) Ardanis

//clone
ACTION_PHP_EACH wand_list AS block => legit BEGIN
ACTION_IF legit BEGIN
COPY_EXISTING ~b_wnd01.SPL~ ~override~
LPF CLONE_EFFECT INT_VAR multi_match = 1 match_opcode = 180 STR_VAR resource = EVAL ~%block%~ END
END
END
Link to comment

Here's an adaptation of what I was using for a while in Refinements:

OUTER_SPRINT $the_wands(~%wand_count%~) ~wand~
COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
  READ_SHORT 0x1c item_type
  PATCH_IF item_type = 35 BEGIN 
    SPRINT $the_wands(~%SOURCE_RES%~) ~wand~
  END
BUT_ONLY

COPY ~your_mod/b_wands.spl~ ~override~
  PHP_EACH the_wands AS wand => bleh BEGIN
    PATCH_IF FILE_EXISTS_IN_GAME ~%wand%.itm~ BEGIN
      LPF ADD_SPELL_EFFECT INT_VAR opcode = 180 parameter1 = (0 - 1) parameter2 = 0 target = 1 timing = 9 STR_VAR resource = EVAL ~%wand%~ END
    END
  END

(Edited to incorporate Ardanis' comment just below. Not tested.)

 

Then, 1) edit wands' usability so that they *can* be used by whichever kit or class; 2) add "AP_b_wands" to the clab file of the kit(s) so that they *cannot* be used; and 3) apply a spell with a 321 effect canceling "b_wands" whenever your condition is met (level-up/feat/HLA/etc.) Bob's your uncle.

 

As I said elsewhere, when I used this for Refinements' Use Scrolls, it brought subsequent SCS installs to their knees, because SCS apparently parses every effect of every spell in every clab table. But in that case, it was applied to several hundred scrolls. For a couple dozen wands, it probably won't be as bad.

 

EDIT - note, there is still a problem with this. Some wands can already be used by most/all classes. Like the Wand of Magic Missiles, or the Wand of Spell Striking. The above code will lump them all together. You should probably edit "b_wands.spl" again afterward:

COPY ~your_mod/b_wands.spl~ ~override~
  LPF DELETE_EFFECT INT_VAR match_opcode = 180 STR_VAR resource = ~wand03~ END // wand of MM
  LPF DELETE_EFFECT INT_VAR match_opcode = 180 STR_VAR resource = ~wand012~ END// another wand of MM
  LPF DELETE_EFFECT INT_VAR match_opcode = 180 STR_VAR resource = ~[spell striking, and other such wands]~ END
Link to comment

 

// notice the minus sign "-" to prevent actual copying

The minus sign does not prevent copying. It copies the files to a location other than your file system. To prevent copies, you'd use BUT_ONLY.

 

Are you sure? I've been using minus for ages to read files, and it never put anything into override.

 

As WeiDU readme says http://www.weidu.org/~thebigg/README-WeiDU.html#optNoBackup

If you put a - here, WeiDU will not copy the file, but only store it as an inlined file (so you can patch a file and then use it for EXTEND_BOTTOM or whatever). This option is not available for COPY_LARGE, MOVE or DELETE.

 

 

SPRINT $the_wands(~%wand_count%~) ~%SOURCE_RES%~

SET ++wand_count

While it works, you don't really need an additional counter, SOURCE_RES serves fine as a key and can be overwritten with different value/result if necessary. Case sensitivity can be an issue, unfortunately.

Link to comment

While it works, you don't really need an additional counter, SOURCE_RES serves fine as a key and can be overwritten with different value/result if necessary. Case sensitivity can be an issue, unfortunately.

Yeah, I was just looking at it again and wondering why the counter was there in the first place! I realized it's because it is the key in the array and the key cannot be a duplicate. But you can just reverse the array and make %SORCE_RES% the key and put any term as the second value, and just switch which one you pull out later in the PHP_EACH block.

Link to comment
COPY ~proficiency/data/proficiency/b_wnd01.SPL~ ~override~   //
//Now, only excludes wand of fear, WAND02.  (BE SURE TO EXCLUDE WAND02 here)!!!!Need to add all others...
COPY_EXISTING_REGEXP - GLOB ~.*\.itm~ ~override~ // notice the minus sign "-" to prevent actual copying
 PATCH_IF (~%SOURCE_SIZE%~ > ~0x71~) BEGIN
 READ_SHORT 0x1c ~itemtype~
   PATCH_IF (~itemtype~ = 35) BEGIN  //only if a wand
     SET $wand_list("%SOURCE_RES%") = 1 // $ adds the variable to array
 END
END


OUTER_SPRINT $wand_list("WAND02") = 0
OUTER_SPRINT $wand_list("wand02") = 0 // WeiDU is on my hate list (C) Ardanis

//clone
ACTION_PHP_EACH wand_list AS block => legit BEGIN
  ACTION_IF legit BEGIN
     COPY_EXISTING ~b_wnd01.SPL~ ~override~
       LPF CLONE_EFFECT INT_VAR multi_match = 1 match_opcode = 180 STR_VAR resource = EVAL ~%block%~ END
  END
END

Thanks everybody, for all of this. This worked, though I got an error at these lines:

OUTER_SPRINT $wand_list("WAND02") = 0
OUTER_SPRINT $wand_list("wand02") = 0 // WeiDU is on my hate list (C) Ardanis

I just opted to delete the one effect. Not terribly efficient, but it worked..

 

COPY_EXISTING ~b_wnd01.SPL~ ~override~
  LPF DELETE_EFFECT INT_VAR multi_match = 1 match_opcode = 180 STR_VAR match_resource = ~WAND02~ END // remove extra wand of fear

Thanks!

 

Btw, I got an error when I tried to replace the last END in the REGEXP with BUT_ONLY:

 

[TEST/SETUP-TEST.TP2] PARSE ERROR at line 41 column 1-8
Near Text: BUT_ONLY
GLR parse error


[TEST/SETUP-TEST.TP2]  ERROR at line 41 column 1-8
Near Text: BUT_ONLY
Parsing.Parse_error
ERROR: parsing [TEST/SETUP-TEST.TP2]: Parsing.Parse_error
ERROR: problem parsing TP file [TEST/SETUP-TEST.TP2]: Parsing.Parse_error


FATAL ERROR: Parsing.Parse_error


WeiDU Timings
load TLK                         0.000
parsing .log files               0.000
loading files                    0.000
Parsing TP2 files                0.031
unmarshal KEY                    0.047
unmarshal TLK                    0.047
stuff not covered elsewhere      0.078
TOTAL                            0.203

Link to comment

 

...

Then, 1) edit wands' usability so that they *can* be used by whichever kit or class; 2) add "AP_b_wands" to the clab file of the kit(s) so that they *cannot* be used; and 3) apply a spell with a 321 effect canceling "b_wands" whenever your condition is met (level-up/feat/HLA/etc.) Bob's your uncle.

As I said elsewhere, when I used this for Refinements' Use Scrolls, it brought subsequent SCS installs to their knees, because SCS apparently parses every effect of every spell in every clab table. But in that case, it was applied to several hundred scrolls. For a couple dozen wands, it probably won't be as bad.

...

I'm doing this with a migraine, so I'm kinda bleary. Subtle, is this code for the stuff we were talking about?

 

Edit; Duh, of course it is. Maybe we should ask about it here(?)

 

 

So, I'm going to ask about it. The idea, as subtle says, is to restrict item use in the clab, but then also have another AP_ that removes the 180/181 effects depending on some condition (using 326 with 321). For example, I was able to tie leather armor use to bastard sword proficiency using this method as a test. That is, if a character had bastard sword proficiency, they could use leather armor, otherwise not.

 

BUT, if you have too many effects, as Refinements did for the scroll use HLA, then SCS takes forever to install (like, days). Any forseeable way around this (I hope I'm being clear. Migraine hurts... :(

Link to comment

Thanks everybody, for all of this. This worked, though I got an error at these lines:

Eh, well, yeah, I can totally see it happening :D Using sprint to set a value, heh.

 

Btw, I got an error when I tried to replace the last END in the REGEXP with BUT_ONLY:

INNER_ACTION requires a closing END too. BUT_ONLY would need to be added after all three of them, not replace the third one.

 

So, I'm going to ask about it. The idea, as subtle says, is to restrict item use in the clab, but then also have another AP_ that removes the 180/181 effects depending on some condition (using 326 with 321). For example, I was able to tie leather armor use to bastard sword proficiency using this method as a test. That is, if a character had bastard sword proficiency, they could use leather armor, otherwise not.

BUT, if you have too many effects, as Refinements did for the scroll use HLA, then SCS takes forever to install (like, days). Any forseeable way around this (I hope I'm being clear. Migraine hurts... :(

 

Maybe you could put everything into secondary 146, but if SCS really does read the clab abilities, then it might as well read what's inside a 146.

Condolences about migraine :(

Link to comment

 

So, I'm going to ask about it. The idea, as subtle says, is to restrict item use in the clab, but then also have another AP_ that removes the 180/181 effects depending on some condition (using 326 with 321). For example, I was able to tie leather armor use to bastard sword proficiency using this method as a test. That is, if a character had bastard sword proficiency, they could use leather armor, otherwise not.

 

BUT, if you have too many effects, as Refinements did for the scroll use HLA, then SCS takes forever to install (like, days). Any forseeable way around this (I hope I'm being clear. Migraine hurts... :(

Maybe you could put everything into secondary 146, but if SCS really does read the clab abilities, then it might as well read what's inside a 146.

 

Wow that is super evil genius. Way too smart and simple for me to have actually thought of on my own. Gonna try it. (Or maybe make kreso try it :devlook: )

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...