• Why would this code crash?
    4 replies, posted
[CODE] local function DisableClientsideRagdoll(ply,ragdoll) if GetConVarNumber("sv_bgo_enabled") == 1 then if !IsValid(ply) then return end if ply:GetNWBool("BGORagdollCreated",false)==true then return end local tmprag = ragdoll if ply.GetRagdollEntity then tmprag = ply:GetRagdollEntity() else tmprag = ( ragdoll and ragdoll or tmprag ) end if !IsValid(tmprag) then tmprag = ply end if ( ply:IsNPC() ) then tmprag:Remove() end if ply:IsPlayer() then if !tmprag:IsPlayer() then tmprag:Remove() end end end end hook.Add("CreateClientsideRagdoll", "BGODisableClientsideRagdollsNPC", DisableClientsideRagdoll) hook.Add("PlayerDeath", "BGODisableClientsideRagdollsPLY", DisableClientsideRagdoll) hook.Add("OnNPCKilled","BGORagdollsConvertNPC",function(ply) DisableClientsideRagdoll(ply) end) [/CODE]
try replacing tmprag:Remove() with SafeRemoveEntity(tmprag)
Thanks, will check it out in the morning. Also, is there a good way to set the force of a player's death ragdoll? Getting the damageinfo force only returns a small number on the z-axis.
Use this [url]http://wiki.garrysmod.com/page/Entity/SetShouldServerRagdoll[/url]. For npcs there's a console command. ai_ragdollserver or something like that. I think the reason your code crashes is because you are using Remove() on something you shouldn't. Probably a parameter passed from the PlayerDeath hook.
Edit: I've traced this issue back to an infinite loop of metatable backups when you reload the game. Doesn't seem to be related to something wrong being removed. Thanks, guys!
Sorry, you need to Log In to post a reply to this thread.