• A lua question
    14 replies, posted
I want the "NORMAL" classic zombie corpses to when i shoot it will go away after 4 seconds. Here is my code. BUT it doesn't seem to work since i dont know if model/zombie/classic.mdl is the right one i tried it but it didn't work SO it may have something to do with the code.... timer.Create("timer2",4,0,function() for k,v in pairs(ents.GetAll()) do if ValidEntity(v) && v:GetClass() == "prop_physics" && v:GetModel() == "models\Zombie\Classic.mdl" then v:Remove() end end end)
1. I think you should do models/zombie/classic.mdl But I can't tell you exactly whats wrong there. But try what I said.
Please use the [noparse][lua][/noparse] tags. Its class is a prop_ragdoll, not a prop_physics. [QUOTE=Persious;27519236]1. I think you should do models/zombie/classic.mdl But I can't tell you exactly whats wrong there. But try what I said.[/QUOTE] The path is correct, and its not case-sensitive.
You will get more help in Questions subform. Please use lua tags when posing code.
[QUOTE=bennyg;27519240]Please use the [noparse][lua][/noparse] tags. Its class is a prop_ragdoll, not a prop_physics. The path is correct, and its not case-sensitive.[/QUOTE] Hm still aint working..
[lua] if v:GetClass() == "npc_zombie" then -- do stuff end [/lua]
[QUOTE=NicklasNW;27519336]Hm still aint working..[/QUOTE] Are you trying to remove clientside (the default death ragdolls) or serverside ones? The code needs to be executed on either side accordingly.
[QUOTE=zzaacckk;27519447][lua] if v:GetName() == "npc_zombie" then -- do stuff end [/lua][/QUOTE] timer.Create("timer2",4,0,function() for k,v in pairs(ents.GetAll()) do if ValidEntity(v) && v:GetClass() == "prop_ragdoll" && v:GetModel() == "models/Zombie/Classic.mdl" then v:Remove() end end end) and how do i put that in there :<
[QUOTE=NicklasNW;27519517]timer.Create("timer2",4,0,function() for k,v in pairs(ents.GetAll()) do if ValidEntity(v) && v:GetClass() == "prop_ragdoll" && v:GetModel() == "models/Zombie/Classic.mdl" then v:Remove() end end end) and how do i put that in there :<[/QUOTE] You don't because the code he gave you doesn't really make sense. I assume you are just trying to get rid of the default corpses created on death, which are only created on the client. Those can't be fetched using ents.GetAll(), but theres a different method on retrieving them. [lua] for k,v in pairs(player.GetAll()) do if (v:GetRagdollEntity():GetModel() == "models/player/Classic.mdl") then v:GetRagdollEntity():Remove() end end [/lua]
Oops typed the wrong thing. I updated my code.
[QUOTE=bennyg;27519581]You don't because the code he gave you doesn't really make sense. I assume you are just trying to get rid of the default corpses created on death, which are only created on the client. Those can't be fetched using ents.GetAll(), but theres a different method on retrieving them. [lua] for k,v in pairs(player.GetAll()) do if (v:GetRagdollEntity():GetModel() == "models/player/Classic.mdl") then v:GetRagdollEntity():Remove() end end [/lua][/QUOTE] Timer Error: [gamemodes\mygamemode\gamemode\init.lua:86] attempt to index a nil value timer.Create("timer2",4,0,function() for k,v in pairs(player.GetAll()) do if (v:GetRagdollEntity():GetModel() == "models/Zombie/Classic.mdl") then v:GetRagdollEntity():Remove() end end end) :<
[QUOTE=NicklasNW;27519707]Timer Error: [gamemodes\mygamemode\gamemode\[b]init.lua[/b]:86] attempt to index a nil value [/QUOTE] That's the Serverside Lua file, you gotta execute the code Clientside.
[QUOTE=bennyg;27519736]That's the Serverside Lua file, you gotta execute the code Clientside.[/QUOTE] and how do i do that?
Fuck ignore this I fail @ reading.
[lua] hook.Add("OnEntityCreated","remove zombies",function(ent) if ((SERVER and ent:GetClass() == "prop_ragdoll") or (CLIENT and ent:GetClass() == "class C_ClientRagdoll")) then if (ent:GetModel() == "models/zombie/classic.mdl") then ent:Remove() end end end) [/lua] Put the file in lua/autorun
Sorry, you need to Log In to post a reply to this thread.