• Ammo and Weapons help.
    4 replies, posted
Well, I want to make a script so it can delete all the NPC dead bodies left over and all the ammo and waepons they leave behind. I've searched ammo on the wiki and can't find anything that I can work with to even try. I'm trying it would be something like this. [lua]function DeleteAmmo() for k, v in pairs(ammo.GetAll()) v:RemoveAll() end[/lua] Please help me with this in the weapons. The problem is all the ammo and weapons laying around causes lag a bit and the bodies same. Thanks, Th3SiNz
Hmm I don't remember the exact class name for ragdolls but I do believe these have to be deleted clientside. Someone will probably post. For ammo you could do this : [lua]local KeyWords = {"item","ammo"} -- Keywords to find in item classnames function DeleteAmmo() for k, v in pairs(ents.GetAll()) --Looping trough all entities for _,word in pairs(KeyWords) do -- And all keywords if string.find(v:GetClass(), word) then -- checking the class name of the entity against all keywords v:Remove() break end end end end[/lua] Not tested. :3: Or you could use console commands on the server to ent_remove_all all entities too.
Also what about decals and stuff? Because our server has the "cum bomb" and when it explodes it shoots white paint all over. Then eventually we have to remove it with the paint tool splash large
Have each client run this : [lua]RunConsoleCommand("r_cleardecals")[/lua]
Complete solution, put in autorun/npccleaner.lua. It will automatically delete all corpses and dropped weapons/ammo once a minute. [lua]--[[ ~ NPC Cleanup ~ ~ Lexi ~ --]] if SERVER then AddCSLuaFile"autorun/npccleaner.lua" timer.Create("Cleanup Dropped Weapons",60,0, function() for _,v in ipairs(ents.GetAll()) do if (v:GetClass():find"weapon" and IsValid(v:GetPhysicsObject()) and not IsValid(v:GetOwner())) or v:GetClass():find"item" then v:Remove() end end end) else timer.Create("Cleanup Dropped Corpses",60,0, function() for k,v in ipairs(ents.GetAll()) do if v:GetClass() == "class C_ClientRagdoll" then v:Remove() end end end) end[/lua]
Sorry, you need to Log In to post a reply to this thread.