Avoiding casting a skill on dead enemy.

● ARCHIVED · READ-ONLY
Started by Icenick 5 posts View original ↗
  1. So what im trying to do is have a follow up skill cast on an enemy if there is a state present. However to speed up gameplay, if the enemy dies theres no point in casting the skill and skip the follow up skill.

    Code:
            if (b.isStateAffected(20)) {                     // if state 20                                   
                damage *= 1.5
                if ($gameTroop.aliveMembers().length > 0){
                 }
                else{
                a.forceAction(286, BattleManager._action._targetIndex)    // casts skill
            }
        }

    I tried a few variations;
    $gameTroop.aliveMembers().length > 0) has it so it does not cast at all guess it checks and sees theres an enemy alive.
    (b.isDeathStateAffected()), (b.hp<=0) neither work, it casts the skill on the next available target.
    Any help?
  2. Looking at your code, it appears as though the game will first check for b being in state 20. If it is, the damage will be increased and another check will be performed to determine whether any members of the enemy troop are alive (before any damage has been applied from this action). If all the members of the enemy troop are already defeated, a will execute the forced casting skill.
    My understanding is that the damage is applied to the target in a separate function called after the one under discussion, so the code doesn't yet know whether the action has resulted in the enemy's defeat.
  3. I think that the death break command line in Yanfly's action sequences does something similar. I'll double-check this later to make sure. But those plugins are worth a try regardless.
  4. Well, looking at your code it seems like the code is run before the damage is actually dealt (since you even have a damage*=1.5 there), which also explains why checking if b.hp<=0 doesnt stop the action since technically, the enemy isnt even damaged yet before that code is checked so he cant be dead too

    Following that logic, one possible solution is to check if damage >= b.hp, if its is, skip the force action since the damage of the first skill will kill the target already. That should be enough in most cases, and only not work in cases that your target has something that might prevent it from dying.
  5. Engr. Adiktuzmiko said:
    Well, looking at your code it seems like the code is run before the damage is actually dealt (since you even have a damage*=1.5 there), which also explains why checking if b.hp<=0 doesnt stop the action since technically, the enemy isnt even damaged yet before that code is checked so he cant be dead too

    Following that logic, one possible solution is to check if damage >= b.hp, if its is, skip the force action since the damage of the first skill will kill the target already. That should be enough in most cases, and only not work in cases that your target has something that might prevent it from dying.

    Ah cool, this did work. I did not test it fully but the few times I did it worked as intended. Basically as long as the enemy does not have immortal state they should die without triggering the skill?
    A death break is what im looking for but I don't know the code to create it.