So I am making a custom NPC, and when I delete it, it say's that it deleted the NPC but the dead ragdoll remains. How do I fix this coding issue?
function ENT:OnRemove()
if IsValid(self.npc) then
self.npc:Remove()
end
end
Any more code? What is the NPC variable stored inside of the entity? What dead ragdoll are you talking about? Does it just fall down like a ragdoll as soon as you remove it?
When the NPC dies, and I press a key to remove the last spawned NPC, the ragdoll doesn't delete. Some custom functions that might be culprit might have something to do with it, but I am not sure.
function ENT:LookForFood(npc)
local npc = self.npc
for _, Rag in pairs ( ents.FindByClass( "prop_ragdoll" )) do
if Rag:GetClass() ~= "prop_ragdoll" then return end
if IsValid(Rag) and !npc:IsCurrentSchedule( SCHED_FORCED_GO ) and npc:GetPos():Distance(Rag:GetPos()) > 30 and self.IHaveValidFood == true and self.IHaveEnemy == false and Rag:WaterLevel() == 0 then
npc:SetSchedule( SCHED_FORCED_GO )
npc:SetSaveValue( "m_vecLastPosition", Rag:GetPos()+Rag:GetForward()*75)
end
if npc:GetEnemy() then return end
if IsValid(Rag) and npc:GetPos():Distance(Rag:GetPos()) <= 30 and self.IHaveValidFood == true then
self.IHaveValidFood = true
timer.Simple(20, function()
self.IHaveValidFood = false
end)
end
end
end
hook.Add("EntityTakeDamage", "FriendlyFire", function(ent, dmginfo)
local attacker = dmginfo:GetAttacker()
if ent:GetName() == "Vultlion" and ent:Disposition(dmginfo:GetAttacker()) == D_NU then
ent:AddEntityRelationship( dmginfo:GetAttacker(), D_HT, 99 )
end
end)
function ENT:SeeEnemyOrNot(npc)
local npc = self.npc
if npc:GetEnemy() then
self.IHaveEnemy = true
if npc:IsCurrentSchedule( SCHED_FORCED_GO ) then
npc:ClearSchedule()
end
else
self.IHaveEnemy = false
end
end
You could create a table containing all the ragdolls returned from this hook: http://wiki.garrysmod.com/page/GM/CreateClientsideRagdoll and then remove them when the NPC is deleted.
Maybe use the entity Ent Index as table index for the ragdoll.
Wouldn't that just create a whole separate ragdoll?
Adding an integer to a table doesn't create an entity, no.
I actually found an easier way, but haven't tested it, try this:
hook.Add("CreateClientsideRagdoll", "AddRagdollToUndo", function(entity, ragdoll)
if(entity:GetClass() == "TheClassYourNPCIs") then
undo.Create("NPC_Ragdoll")
undo.AddEntity(ragdoll)
undo.SetPlayer(entity:GetOwner())
undo.Finish()
end
end)
But that will make you have to undo it twice. But yeah, do this if you don't want to use my suggestion
Sorry, you need to Log In to post a reply to this thread.