temnix Posted August 9, 2020 Share Posted August 9, 2020 I need to add a casting of a special spell to all instances in dialogues where the NPC turns hostile in the end or commands others to turn hostile. I'm using this code: COPY_EXISTING_REGEXP GLOB ~.*\.DLG~ ~override~ DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~DO %Enemy() % EXIT~ ~DO %ApplySpellRES("REPOFF_#",Myself) Enemy()% EXIT~ REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~DO %Enemy() %~ ~DO %ApplySpellRES("REPOFF_#",Myself) Enemy() %~ REPLACE_TEXTUALLY ~,Enemy())~ ~,Enemy()) ReallyForceSpellRES("REPOFF_#",Myself))~ END BUT_ONLY The second one includes a space near the end in case Enemy() is not the last action in the sequence, though it usually is. The last one is for ActionOverride, for cases where, say, Hobgoblin 1 does ActionOverride("hob2",Enemy()). Starting from the comma should cover all script names. But either I'm not writing these correctly or it's some funkiness with REPLACE again. Ideas? Quote Link to comment
Guest Gob Oafenplug Posted August 9, 2020 Share Posted August 9, 2020 Percentage signs by themselves are just string delimiters; inside of other string delimiters they %EVALUATE_THE_VARIABLE%. In neither case are they doing anything for you in this code. Also, depending on what you intend this REPOFF_# to do, you may want to apply it to the creature going hostile rather than repeatedly applying it to the creature performing the ActionOverride(). You'll need a regular expression match to do this. Something like this may be closer to what you're intending to do. COPY_EXISTING_REGEXP GLOB ~^.+\.DLG$~ override COUNT_REGEXP_INSTANCES ~Enemy()~ enemy_num PATCH_IF enemy_num > 0 BEGIN DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY "~Enemy()" %~Enemy() ApplySpellRES("REPOFF_#",Myself)% REPLACE_TEXTUALLY "^Enemy()" %Enemy() ApplySpellRES("REPOFF_#",Myself)% REPLACE_TEXTUALLY ~ActionOverride("\([^"]+\)",Enemy())~ ~ ReallyForceSpellRes("REPOFF_#","\1") ActionOverride("\1",Enemy())~ END END BUT_ONLY Quote Link to comment
temnix Posted August 10, 2020 Author Share Posted August 10, 2020 This will be perfect if it works. Where do you get the "\1," though? Isn't the string being replaced just an expression for "any word"? Quote Link to comment
temnix Posted August 13, 2020 Author Share Posted August 13, 2020 (edited) Now I'm having trouble replacing an action. This bit of code should insert a special block before all StealFailed([ANYONE]) lines in scripts, and I put backslashes before the brackets, but it won't compile. REPLACE_TEXTUALLY ~StealFailed(\[ANYONE\])~ ~IF StealFailed(\[ANYONE\]) THEN RESPONSE #1 ApplySpellRES("REPPR2_#",Player1) Continue() END IF StealFailed(\[ANYONE\])~ Edited August 13, 2020 by temnix Quote Link to comment
DavidW Posted August 13, 2020 Share Posted August 13, 2020 Get rid of the backslashes in the second (replacement) string. They're there to indicated that [ and ] are being quoted directly and not used as special characters, but you don't need to do that in the replacement string because it can't contain special characters anyway. Quote Link to comment
temnix Posted August 13, 2020 Author Share Posted August 13, 2020 Yes, and I had an extra IF in the substituting string, this is why it wasn't compiling. But now I have gotten rid of all that, and compiling happens, only nothing changes in the end. I used an extra bit you have recommended for spaces. Neither of this changes ought: REPLACE_TEXTUALLY "\(%TAB\|%LNL%\|%MNL%\|%WNL%\)" " " REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~IF StealFailed([ANYONE])~ ~IF StealFailed([ANYONE]) THEN RESPONSE #1 ApplySpellRES("REPPR2_#",Player1) Continue() END IF StealFailed([ANYONE])~ And REPLACE_TEXTUALLY "\(%TAB\|%LNL%\|%MNL%\|%WNL%\)" " " REPLACE_TEXTUALLY ~IF StealFailed(\[ANYONE\])~ ~IF StealFailed([ANYONE]) THEN RESPONSE #1 ApplySpellRES("REPPR2_#",Player1) Continue() END IF StealFailed([ANYONE])~ I just gotta love this code. It compiles so smoothly and "successfully installed"! And doesn't change jack shit. Quote Link to comment
InKal Posted August 14, 2020 Share Posted August 14, 2020 dunno if this information is useful to you but I ctrl+Y all motherf... habgoblins. "SPARE NO ONE!!" yeah, rrrright..... Quote Link to comment
DavidW Posted August 14, 2020 Share Posted August 14, 2020 You have replaced all line breaks with spaces, but there is a line break in the line you are matching on. Quote Link to comment
temnix Posted August 14, 2020 Author Share Posted August 14, 2020 Yes, but would I get a match for "IF StealFailed()"? Quote Link to comment
DavidW Posted August 14, 2020 Share Posted August 14, 2020 Try it and find out... Quote Link to comment
temnix Posted August 15, 2020 Author Share Posted August 15, 2020 Yeah, I found out. Quote Link to comment
temnix Posted August 29, 2020 Author Share Posted August 29, 2020 (edited) This has come up again. I'm replacing PartyGold(...) and its LT and GT versions, in dialogues, with CheckStat(LastTalkedToBy,...,GOLD). The private purse instead of the party pool. This is the code I'm using, and nothing is getting changed after it, example: REPLACE_TEXTUALLY ~\bPartyGoldGT(\([.]+\))~ %CheckStatGT(LastTalkedToBy,\1,GOLD)% \b In the beginning, for start of the word, is to prevent replacement of the GivePartyGold action. Why does this fail? The first parenthesis in the matched expression is there, the final paranthesis is also real, between them is a regular expression: \([.]+\) Seems in order to me. With this code Weidu complains of "spurious \\ in regulation expression." Edited Edited August 30, 2020 by temnix Quote Link to comment
temnix Posted August 30, 2020 Author Share Posted August 30, 2020 (edited) @qwerty1234567So you are saying there is no problem? I wish it were so, but Weidu doesn't agree. Or do you mean that . is a literal fullstop? Not in Weidu's code it isn't. See the documentation: . matches any character except newline Edited August 30, 2020 by temnix Quote Link to comment
DavidW Posted August 30, 2020 Share Posted August 30, 2020 Terms in square brackets are interpreted as ordinary characters. It's not somewhere you can put a special character. (And if you could, then [.] would match any single character except newline. But . does that anyway.) 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.