ScareCrow kills not being passed on to other plugins.No Thanks

So I use another plugin called XPerience which adds an RPG system to the game.  I recently requested of the author to track scarecrow kills and player auto turret kills which they graciously added.  Priot to that I had temporarily modded NigthtZombies to pass the scarecrow kill data over to the XPerience plugin via the OnEntityDeath event handler in order to get it to work while he was making changes.  Well, testing his changes just a little bit ago and reverting my changes to NZ resulted in no scarecrow or auto turret kills be tracked.  Now, I had an idea of what it might be and I was able to correcrt the problem

In the OnPlayerDeath hook you just need to always return null instead of true so that the event will be passed on to other plugins, which means you can remove the calls to Quests and DeathNotes as well.

Your respawning logic should really be inside the OnEntityDeath hook as well not OnPlayerDeath.

wow that worked! thank you!

gZ97IC8bBCWIdPS.jpg Covfefe

wow that worked! thank you!

No problem at all!  Glad to help.

This would actually break the the plugin to an extent. I return true because I'm pooling the zombies, so when one dies it is healed and teleported to another location instead of killing it and creating a new one each time. It wouldn't cause any errors because I implemented checks for that edge case but you would likely see a steadily reducing number of zombies until more are created next spawn time.

Secondly I use OnPlayerDeath to avoid lots of unneccessary hook calls, since ScarecrowNPC inherits from BasePlayer so I only need to check for player deaths.

wXLxOgFUEnSjh1r.png 0x89A

This would actually break the the plugin to an extent. I return true because I'm pooling the zombies, so when one dies it is healed and teleported to another location instead of killing it and creating a new one each time. It wouldn't cause any errors because I implemented checks for that edge case but you would likely see a steadily reducing number of zombies until more are created next spawn time.

Secondly I use OnPlayerDeath to avoid lots of unneccessary hook calls, since ScarecrowNPC inherits from BasePlayer so I only need to check for player deaths.

How often are the spawn cycles? I noticed when players fly away from their night zombies, it takes a good while until the plugin updates the player's new location
gZ97IC8bBCWIdPS.jpg Covfefe
How often are the spawn cycles? I noticed when players fly away from their night zombies, it takes a good while until the plugin updates the player's new location
Would depend on what you set in the config though by default it's every night.

I see what you mean about the teleporting and I did notice at one point some really crazy stuff where the zombies would die, but their corpses were stretched all over the place due to the teleporting.  If you're interested I reworked some stuff in the plugin so they don't have to be teleported around and instead when the zombie dies it will be removed from the global list and another one respawned.  Also cleaned up the remove zombies function when it's time to kill them all.  One of the major changes was no longer needing the CreateCorpse function and instead calling the Die() method of the zombie entity if the option to leave the corpses is turned on.  The Die() method kills them normally with a death animation and leaves the corpse and allows them to be looted.

3CYHHwd7CXVvlbt.jpg CodeJunkie

I see what you mean about the teleporting and I did notice at one point some really crazy stuff where the zombies would die, but their corpses were stretched all over the place due to the teleporting.  If you're interested I reworked some stuff in the plugin so they don't have to be teleported around and instead when the zombie dies it will be removed from the global list and another one respawned.  Also cleaned up the remove zombies function when it's time to kill them all.  One of the major changes was no longer needing the CreateCorpse function and instead calling the Die() method of the zombie entity if the option to leave the corpses is turned on.  The Die() method kills them normally with a death animation and leaves the corpse and allows them to be looted.


This was how things worked in previous versions of the plugin, It was a conscious decision to implement pooling and move away from creating and destroying zombies in the interest of performance so it's probably not something I would consider changing for the time being unless there were major issues.

From what I can tell at the moment there is no performace impact (runs the same as far as I can tell...maybe a little better), but there was a lot of code cleanup.  Allowing the game engine to handle things like the death of the zombies and what not probably has a little to do with lack of a performance change.

There isn't likely to be an improvement in terms of execution time, it's mainly to reduce pressure on the garbage collector and avoid frequent allocations and deallocations.

Also I forgot to mention before that the CreateCorpse method is basically a copy paste of the game code so that code would still be used if you were to let zombies die normally, so removing it from the plugin wouldn't necessarily be an optimisation.

Interesting.  I'll keep this in mind.  Thanks!

You can leave NightZomie code fully entact and just add the reference to XPerience at the top and in the OnPlayerDeath hook:

        [PluginReference("Kits")] private Plugin _kits;
        [PluginReference("DeathNotes")] private Plugin _deathNotes;
        [PluginReference("Quests")] private Plugin _quests;
        [PluginReference("XPerience")] private Plugin _xperience;
        [PluginReference("XPerienceAddon")] private Plugin _xperienceaddon;


     private object OnPlayerDeath(ScarecrowNPC entity, HitInfo info)
        {
            if (_spawnController.IsNightZombie(entity) && _spawnController.IsSpawnTime)
            {
                _spawnController.Respawn(entity);
                _deathNotes?.Call("OnEntityDeath", entity as BasePlayer, info);
                _quests?.Call("OnEntityDeath", entity, info);
                _xperience?.Call("OnEntityDeath", entity, info);
                _xperienceaddon?.Call("OnEntityDeath", entity, info);
                return true;
            }

            return null;
        }

Do the same for XPerience Addon if you use it so you can get the distance bonus and records to acknowledge the kill

Locked automatically