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
Level: Smitemaster
Rank Points: 1856
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
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 |

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