How do you check if an NPC is alive clientside without using Entity.Health (doesn’t work on NPCs clientside).
- . and : are different.
You write . when you’re talking about the function (but not in the actual script, don’t ask me why), and Entity:Alive() is only for players.
If an npc is dead, i think its no longer existent. (I think) So, you would have to get the entity before it dies and then do ent:IsValid()
NPC’s are removed a second or so after they die, as stated above. You can also use usermessages to send NPC health whenever its changed.
Also, you should use ValidEntity. It makes sure the entity isn’t nil first.
About the valid entity stuff, both work, but [lua]if entity and entity:IsValid() then[/lua]
can be written as [lua]if ValidEntity(entity) then[/lua] to save you a few lines of code, making your code look ‘nicer’.
[editline]25th February 2012[/editline]
But because you will most likely call your entity e or ent it won’t really save you any space at all.
function IsValid( object )
return object and object.IsValid and object:IsValid()
Except it’s the same. Then yes, It’s all about what you prefer to look at.