Hello.
Been working on a gamemode (not for the competition) for over a week. I've run into a huge problem that I need to solve. The gamemode requires that the player presses "E" (IN_USE) on a dead NPC (prop_ragdoll) to see what items it had on it. Basically the idea is, that players are doing a sort of "scavenger hunt", and when someone kills the mob that has the keycard, they take it to their base and they win. It's a stupid little gamemode for my friends and I to play LAN. We brainstorm things we'd like to play, and I code them so I can get better at coding.
Anyway, here's my problem. Dead NPC's create ragdolls client-side, which is fine and dandy for sandbox and reducing server lag, but problematic when it comes to installing loot tables onto dead NPC ragdolls. The server needs to have a ragdoll to attach values to. Since you cannot press "E" on a clientside ragdoll as it doesn't exist, it becomes a problem... To confirm this, I did "ent_show_response_criteria" on the dead body and, as expected, there was no response. I made my own dead body ragdoll, and it responsed perfectly. Pressed "E" on the ragdoll that *I* made works excellently, and my keycard code works flawlessly on it. The problem is, now I have two bodies - One I made that works, and one phantom body from when it was killed.
Here is my code thus far.
[lua]
function GM:OnNPCKilled(npc,attacker,inflictor)
local ragdoll = ents.Create("prop_ragdoll")
ragdoll:SetModel(npc:GetModel())
ragdoll:SetVelocity(npc:GetVelocity())
ragdoll:SetAngles(npc:GetAngles())
ragdoll:SetPos(npc:GetPos())
ragdoll:Spawn()
ragdoll.DeathTime = CurTime()
ragdoll.Expired = false
-- Rest of function follows
end
[/lua]
The above code works great! However, spawning two dead bodies... Not so much!! I did some research on [url=http://wiki.garrysmod.com/page/GM/CreateClientsideRagdoll]GM:CreateClientsideRagdoll[/url], but following that, the corpse still spawns. So, I tried to use [url=http://wiki.garrysmod.com/page/GM/CreateEntityRagdoll]GM:CreateEntityRagdoll[/url], and tried to follow that, and use it to delete any ragdoll it creates... Still nothing.
Anyone have any suggestion/assistance?
What I have tried:
[lua]
function GM:CreateEntityRagdoll(owner, ragdoll)
ragdoll:Remove()
end
[/lua]
[lua]
function GM:CreateClientsideRagdoll(ent, rag)
rag:Remove()
end
[/lua]
[lua]
function GM:CreateClientsideRagdoll(ent, rag)
rag:SetSaveValue("m_bFadingOut", true)
end
[/lua]
Could have a timer or something that runs and does this
[code]
for k, v in pairs(ents.FindByClass("class C_ClientRagdoll")) do
if IsValid(v) then
v:Remove()
end
end
[/code]
[editline]1st July 2017[/editline]
Actually this will work
[code]hook.Add("OnEntityCreated", "f", function(ent)
if (ent:GetClass() == "class C_ClientRagdoll") then
ent:Remove()
end
end)[/code]
[QUOTE=Z0mb1n3;52423508]
[code]hook.Add("OnEntityCreated", "f", function(ent)
if (ent:GetClass() == "class C_ClientRagdoll") then
ent:Remove()
end
end)[/code][/QUOTE]
Gamemode's shared.lua file:
[lua]
function GM:OnEntityCreated(ent)
if ent:GetClass() == "class C_ClientRagdoll" then
ent:Remove()
end
end
[/lua]
Still creating two bodies. (I didn't hook it because I overwrote the hook on my gamemode)
I added a print(ent:GetClass()) to see whats going on:
[quote=Console Output]
npc_antlion
npc_antlion << Client
(15.94) input : template_antlion.Spawn()
(16.20) input : template_antlion.Disable()
CBaseAnimating::SequenceDuration( 181 ) out of range
crossbow_bolt << Client
env_sprite << Client
env_sprite << Client
crossbow_bolt
prop_ragdoll
prop_ragdoll
[DEBUG] Ragdoll: Entity [99][prop_ragdoll] belongs to NPC [94][npc_antlion]
env_sprite
prop_ragdoll << Client
prop_ragdoll << Client
[/quote]
[t]https://puu.sh/wzxEg/81740166a0.jpg[/t]
The body on the left is the natural body created when it dies. It doesn't show up on ent_show_response_criteria, and pressing "E" on it does not work.
The body on the right is the one I coded as given above. It shows up on ent_show_response_criteria, and pressing "E" works flawlessly.
[b][Final Edit][/b]
Changing it from an overwrite to a hook made no difference, just as a side note.
Thanks for your response though.
Update:
The 2nd ragdoll (original dead body, not mine) is being created server side. I just tried to add:
[lua]
if CLIENT and ent:IsRagdoll() then
ent:Remove()
end
[/lua]
and it said "Client is attempting to remove server side entity [71]"
So, it's being made server-side... Narrowing it down now finally.
[editline]2nd July 2017[/editline]
[b]SOLVED!!!![/b]
Added:
[lua]
ent:SetServerShouldRagdoll(false)
[/lua]
to the death hook of the NPC, which caused it to be made clientside.
Then I added the class C_Client you said above, and it's gone now.
Thank you!
Sorry, you need to Log In to post a reply to this thread.