So i'm having this problem where a bot that i'm working on doesn't seem to die properly.
I set it's health to 50.
If i Spawn one of them, i can kill it just fine.
But if i spawn two or more of them, it doesn't seem to be able to be killed, even though it registers as "dead"; It prints that it has 0 health, it plays it's death sound, and the other bots acknowledge that it has been killed, yet it keeps running as if it isn't at 0 (or sometimes negative) health, running at me and attacking me, and even continuing to play hitsounds if i damage it further.
No Errors or anything else.
Heres the "OnKilled" Function, if it may help:
[CODE]function ENT:OnKilled( damageinfo )
local cpdeaths = {"npc/metropolice/die1.wav", "npc/metropolice/die2.wav","npc/metropolice/die3.wav","npc/metropolice/die4.wav"}
self:EmitSound(cpdeaths[math.random(#cpdeaths)])
if(self.Weapon == stick and self.Weapon ~= nil) then
wep= ents.Create("weapon_stunstick")
att = self:GetAttachment(5)
wep:SetPos(att.Pos)
wep:Spawn()
self.Weapon:Remove()
else
return
end
self:BecomeRagdoll( damageinfo )
print("ded")
end[/CODE]
any ideas as to what may cause this?
Sadly, I don't know anything about Nextbots to help you with your problem, but I do have some recommendations about your code.
[CODE]
local cpdeaths = {"npc/metropolice/die1.wav","npc/metropolice/die2.wav","npc/metropolice/die3.wav","npc/metropolice/die4.wav"} -- This is defined outside our function, it is more optimised this way, as otherwise it would be redefined every time the nextbot died.
function ENT:OnKilled( damageinfo )
self:EmitSound(cpdeaths[math.random(#cpdeaths)])
if(self.Weapon == stick and self.Weapon ~= nil) then -- We are going to indent all the code in this function, makes it easier to read.
wep= ents.Create("weapon_stunstick")
att = self:GetAttachment(5)
wep:SetPos(att.Pos)
wep:Spawn()
self.Weapon:Remove()
else
return
end
self:BecomeRagdoll( damageinfo )
print("ded")
end[/CODE]
It's not necessarily required that you write code like this, but it makes it easier to read.
Get rid of the "return", it stops the code from being executed if the bot doesn't have self.Weapon.
Sorry, you need to Log In to post a reply to this thread.