General > Developers Corner

New Zombie Idea ( help )

<< < (3/3)

MrPresident:
victim is a variable passed by the hook...

the way the OnNPCKilled hook works is whenever ANY NPC is killed it fires that hook and passes 3 variables..
1. victim = the NPC that was killed
2. killer = what killed it.. can be a player, or another NPC or an entity
3. weapon = the weapon used if applicable


what you will need to do to only make it work with npc_antlionguard is to add a check into the function.


--- Code: ---if victim:GetClass() == "npc_antlionguard" then
    code here
end

--- End code ---

or you could exit the hook on all other accounts by having this line...


--- Code: ---if not victim:GetClass() == "npc_antlionguard" then return end

--- End code ---

Also.. I would advise against using the GM:OnNPCKilled function.. instead hook it...





--- Code: ---function MyNPCKilledFunction(victim, killer, weapon)
     if not victim:GetClass() == "npc_antlionguard" then return end
     your code here
end
hook.Add( "OnNPCKilled", "MyNPCKilledFunction", MyNPCKilledFunction )

--- End code ---

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version