From 1ba3f0673f0ff6e2419b0bb0f6718e09d042bb13 Mon Sep 17 00:00:00 2001 From: Kiri Date: Sat, 15 Oct 2022 13:04:52 -0700 Subject: [PATCH] Fixed crash when tossing plushie while cacodemon is spawned. --- caco_summon.zs | 69 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/caco_summon.zs b/caco_summon.zs index 19492ba..91c1dbe 100644 --- a/caco_summon.zs +++ b/caco_summon.zs @@ -253,21 +253,25 @@ class KiriCacodemonPlushie : HDWeapon { { // Refuse to feed active monsters. if(invoker.spawned_creature || invoker.spawned_spawnball) { - invoker.owner.A_Log( - String.format( - "Cannot feed blood to %s when they're not in their plushie!", - invoker.getMonsterName()), - true); + if(invoker.owner) { + invoker.owner.A_Log( + String.format( + "Cannot feed blood to %s when they're not in their plushie!", + invoker.getMonsterName()), + true); + } return; } // Refuse to feed monsters that don't need any more. if(invoker.getMonsterHealth() == invoker.getMonsterMaxHealth()) { - invoker.owner.A_Log( - String.format( - "%s doesn't need any more food for now.", - invoker.getMonsterName()), - true); + if(invoker.owner) { + invoker.owner.A_Log( + String.format( + "%s doesn't need any more food for now.", + invoker.getMonsterName()), + true); + } return; } @@ -457,9 +461,12 @@ class KiriCacodemonPlushie : HDWeapon { if(spawned_creature) { spawned_creature.A_SpawnItemEx("TeleFog"); spawned_creature.destroy(); - owner.A_Log( - String.format("%s has returned to the plushie.", getMonsterName()), - true); + + if(owner) { + owner.A_Log( + String.format("%s has returned to the plushie.", getMonsterName()), + true); + } } // Adjust help text because the context changed. Now we can @@ -527,7 +534,9 @@ class KiriCacodemonPlushie : HDWeapon { if(fainted_monster_despawn_countdown == KIRI_CACOPLUSHIE_FAINTED_MONSTER_COOLDOWN) { - owner.A_Log(String.format("%s has fainted!", getMonsterName()), true); + if(owner) { + owner.A_Log(String.format("%s has fainted!", getMonsterName()), true); + } } // After some number of frames, actually despawn the @@ -549,11 +558,13 @@ class KiriCacodemonPlushie : HDWeapon { // Shields were totally broken. Extremely low chance // to restore shields each frame. if(frandom(0, 100) < 0.1) { - owner.A_Log( - String.format( - "%s's shields have started charging.", - getMonsterName()), - true); + if(owner) { + owner.A_Log( + String.format( + "%s's shields have started charging.", + getMonsterName()), + true); + } setMonsterShield(0); } @@ -587,11 +598,13 @@ class KiriCacodemonPlushie : HDWeapon { // spawn. if(invoker.getMonsterFainted()) { - invoker.owner.A_Log( - String.format( - "%s has fainted and cannot manifest yet.", - invoker.getMonsterName()), - true); + if(invoker.owner) { + invoker.owner.A_Log( + String.format( + "%s has fainted and cannot manifest yet.", + invoker.getMonsterName()), + true); + } spawn_ball.A_SpawnItemEx("TeleFog"); @@ -754,9 +767,11 @@ class KiriCacodemonPlushie : HDWeapon { } else { // Tell the player we failed. - invoker.owner.A_Log( - String.format("Failed to summon %s: Not enough room.", invoker.getMonsterName()), - true); + if(invoker.owner) { + invoker.owner.A_Log( + String.format("Failed to summon %s: Not enough room.", invoker.getMonsterName()), + true); + } } }