Jump to content

How to check that a zombie (IsoZombie) is dead ?


Kyun

Recommended Posts

Hi,

 

I'm messing around with zeds and haven't succeded at checking if a zed is dead. Here's what i'm doing :

-- spawning of a zedlocal zed = getVirtualZombieManager():createRealZombieNow(fromx, fromy, fromz);	zed:setFakeDead(false);zed:setForceFakeDead(false);zed:PathTo(tox, toy, toz, true);table.insert(zedTable, zed);

And to check if one have been killed :

for _,v in pairs(zedTable) do    if v:isDead() then        print(v:toString() .. " is dead");        -- other stuff    endend

v:isDead() never returns true (of course I killed the zombie before triggering the function).

 

I tried to check the objects on the IsoZombie square to find a IsoDeadBody, but it is not on the same square (it's also an ugly way to solve the problem :P).

 

Thanks,

Kyun

 

EDIT : if I don't kill the zombie with my axe and use v:Kill(nil) instead then v:isDead() do return true. Weird.

Link to comment
Share on other sites

I think the problem might come from this:

  public void Hit(HandWeapon weapon, IsoGameCharacter wielder, float damageSplit, boolean bIgnoreDamage, float modDelta)  {    super.Hit(weapon, wielder, damageSplit, bIgnoreDamage, modDelta);    this.target = wielder;    if (this.Health <= 0.0F)    {      if (!this.bDead)      {        DoZombieInventory();        LuaEventManager.triggerEvent("OnZombieDead", this);        this.bDead = true;      }    }    this.TimeSinceSeenFlesh = 0;  }
As it only sets the bDead variable of the IsoZombie and not the one of the superclass (no guarantee that this is correct, as I didn't spend too much time on reading through the java code).


Why not use an alternative approach?

[...]-- spawning of a zedlocal zed = getVirtualZombieManager():createRealZombieNow(fromx, fromy, fromz);zed:setFakeDead(false);zed:setForceFakeDead(false);zed:PathTo(tox, toy, toz, true);-- mark zombielocal md = zed:getModData();md.id = "SpecialZombieICreated";[...]-- called when zombie is killedlocal function check(_z)	local z = _z;	local md = z:getModData();	-- see if it is one of our marked zombies	if md.id == "SpecialZombieICreated" then		doAwesomeStuff();	else		return;	endendEvents.OnZombieDead.Add(check);
Link to comment
Share on other sites

Hi,

 

Thanks a lot, you're both right, the super is not the same so ... (I also think a zed can have 0 health and not be dead; at 0 health if I gently push it bare handed, it dies on ground).

 

 

OnTick is good but OnZombieDead is less ressource heavy :D The modData trick worked perfectly !

 

btw where did you find this event ?! I have this list :

Event reference - Project Zomboid mods & tutorials

 

EDIT : thanks a lot, got them all now :)

 

Thanks again,

Kyun

Link to comment
Share on other sites

Yeah I use your mod, that "don't push it" really bugged me, I clicked, and died painfully :), really usefull to play with stuff and test custom mods :D

 

Looking forward to the parsing of custom items.txt (maybe you could use the receipes, and the items needed, to store almost all game items ?)

Link to comment
Share on other sites

Hm, I'm don't think it's necessary to make another thread so I'll ask here :D

 

Yeah, still me and my beloved zeds : they don't want to spawn :(

It works using coordinates close to the player, but not far way :

local zed = getVirtualZombieManager():createRealZombieNow(fromx, fromy, fromz);zed:setFakeDead(false);attempted index: setFakeDead of non-table: null

Coordinates were (9511, 11204, 0).

 

This is odd, my guess is I have to explore the world before being able to spawn stuff ?

Thanks again :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...