Announcement: Be excellent to each other.


Caravel Forum : DROD RPG Boards : RPG Feature Requests : A better way to trigger scripting at the end of a fight
New Topic New Poll Post Reply
Poster Message
kieranmillar
Level: Smitemaster
Rank Points: 2668
Registered: 07-11-2014
IP: Logged
icon A better way to trigger scripting at the end of a fight (+1)  
It seems to me that in the world of RPG scripting there are lots of times you will want something to trigger right at the end of a fight. Maybe you're harvesting souls and want to increment a variable by 1 after each fight regardless of monster. Maybe you want a custom accessory that gives an attack boost but takes away 50 HP after each kill when it is equipped. There's a huge and diverse range of possibilities.

Currently there are 3 different methods that you can use to do this, and unfortunately each one comes with its own limitations and issues. I had once assumed that something like this would be very easy to script, but it turns out that it isn't.

There are three features that you want from such a method:
1) It triggers immediately after the enemy dies, on the same turn and if multiple enemies are fought on the same turn (e.g. mimic) then it triggers after each.
2) The script can be executed in all of the cases you want it to (e.g. certain states or equipment layouts won't make it fail to run when you want it to execute).
3) You don't have to duplicate the same code in lots of different places.

Method 1: Your scripting is specific to a custom Sword.
Swords are different from other equipment in that they allow the use of the Each Attack command. With this you can check on each attack if _EnemyHP is zero, and if so, execute your script. The good news is that this works perfectly, but the bad news is that it only works for Swords. Want this script to work while unarmed or when Swords are disabled? Too bad!

Method 2: Using a global script with Wait for Event Monster Stabbed.
Utterly hopeless. The event cannot be triggered multiple times per turn. Execution is also delayed until the following turn. Even worse, the script won't fire if you kill a monster on the turn after you killed another one! This is because the script gets killed if it tries to trigger the same line of code on the same turn (stuff like Each Attack is an exception) therefore you have to stick a Wait 0 at the end and for some reason (it might be a bug with how the scripts flow here), on the turn after you kill a monster the code is sitting at Wait 0 and so won't check for the Event. This method is only useful if there is one monster in the room and you're checking for death to e.g. trigger a boss kill scorepoint or something.

Method 3: The monster that died runs the script.
Imperative Unkillable allows you to run code after the monster dies, either by using Wait for Defeat, or if the monster is already looping some code every turn, buy using Each Defend that checks for _MyHP to be zero each time it gets hit. This works correctly and works every time, provided that you are exclusively using custom monsters in your hold and not the default monsters. There is an annoying workaround you have to do in that in order to simulate the monster actually dying you can't use Imperative Die because it gets delayed until the next turn, so instead you have to use Disappear followed by using Game Effect Blood Splatter at the monsters location. The major problem with this method is that your end of combat code has to be duplicated inside every single monster, so if you want to make a change you can easily end up having to change the default scripts for over 20 characters. What a pain in the arse.

------------

What would be really nice would be having some sort of "label jump" command like Each Attack that can work inside any character, and triggers when a fight ends due to the enemy dying. Then you can just put the code in a global script and be done with it. Alternatively, might simplify things if Custom Shields and Custom Accessories also worked with the Each Attack command, but this by itself is not enough because sometimes you will want this scripting to work without being tied to a particular piece of equipment.

Of course I have no idea how the code works so I don't know what the best solution would be. Maybe because in RPG using the command key works as a hidden piece of equipment it too could have Each attack and Each Defend work with it? I dunno!
03-25-2016 at 12:33 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (0)  
There is an annoying workaround you have to do in that in order to simulate the monster actually dying you can't use Imperative Die because it gets delayed until the next turn, so instead you have to use Disappear followed by using Game Effect Blood Splatter at the monsters location.
This part has been addressed for 1.2.8.

I'll need to read your request more carefully so I understand what you need delivered to avoid the per-script pain you're describing in Method 3.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 11-03-2020 02:58 AM]
11-03-2020 at 02:58 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (0)  
I've read through the context of your request more carefully and I get the limitations you're describing. Makes sense to me now.
kieranmillar wrote:
What would be really nice would be having some sort of "label jump" command like Each Attack that can work inside any character, and triggers when a fight ends due to the enemy dying.
Yes, this should be possible. It seems like this is the only proposal that covers everything one might want in this space. I'll plan to add this.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 11-10-2020 01:29 AM]
11-10-2020 at 01:28 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (+3)  
I've added the "Each Victory" script command for 1.3. Enjoy!

PR

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 11-10-2020 05:44 AM]
11-10-2020 at 05:44 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
kieranmillar
Level: Smitemaster
Rank Points: 2668
Registered: 07-11-2014
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (+1)  
I've been using Each Victory a fair bit in a hold I have for numerous reasons, and it's perfect and does exactly the job. Brilliant feature.

There is one minor quibble, but probably not an issue with Each Victory itself, but the editable processing sequence migration doesn't have a thread so I'll post it here instead.

I have a global script that uses Each victory to check if your GR is over a certain amount and then tells you you can afford something if it is. This works great, however I also have a weapon that adds an amount to your GR each victory, its a flat amount so doesn't use the MyMonsterGRMult variable. If the extra flat amount of greckles added by this weapon takes you to or over the GR limit checked by the global script, it does not tell you until the next fight. Changing the processing sequences does not help.

My first guess is this is something to do with the processing order of global scripts, which is always happening first.
06-10-2023 at 09:55 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (+1)  
kieranmillar wrote:
There is one minor quibble, but probably not an issue with Each Victory itself, but the editable processing sequence migration doesn't have a thread so I'll post it here instead.

I have a global script that uses Each victory to check if your GR is over a certain amount and then tells you you can afford something if it is. This works great, however I also have a weapon that adds an amount to your GR each victory, its a flat amount so doesn't use the MyMonsterGRMult variable. If the extra flat amount of greckles added by this weapon takes you to or over the GR limit checked by the global script, it does not tell you until the next fight. Changing the processing sequences does not help.

My first guess is this is something to do with the processing order of global scripts, which is always happening first.
You're probably right about this being a processing order issue. I think all the global scripts process, and then the local room ones (or maybe v.v.).

Are you suggesting that, based on processing order, we would want to have a total ordering on both the global and room script execution? I guess that would make sense.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 06-10-2023 10:28 PM]
06-10-2023 at 10:28 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
kieranmillar
Level: Smitemaster
Rank Points: 2668
Registered: 07-11-2014
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (0)  
mrimer wrote: Are you suggesting that, based on processing order, we would want to have a total ordering on both the global and room script execution? I guess that would make sense.
Yeah it would be helpful, oftentimes if you want a global script to be monitoring for something to happen you want it to be the last thing to run in a turn so that you actually catch the thing you're monitoring for on the turn it happens, its not ideal if the check happens first.
06-10-2023 at 10:44 PM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: A better way to trigger scripting at the end of a fight (0)  
kieranmillar wrote:
mrimer wrote: Are you suggesting that, based on processing order, we would want to have a total ordering on both the global and room script execution? I guess that would make sense.
Yeah it would be helpful, oftentimes if you want a global script to be monitoring for something to happen you want it to be the last thing to run in a turn so that you actually catch the thing you're monitoring for on the turn it happens, its not ideal if the check happens first.
Okay, yes, I can get behind that. This change is probably doable, but carefully, so as to not modify the pre-existing default ordering logic.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
06-10-2023 at 10:52 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD RPG Boards : RPG Feature Requests : A better way to trigger scripting at the end of a fight
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.