Removing Entity Problems

Hey. I have been having troubles while trying to make a script that will remove specific entities by class on InitPostEntity.

I have been getting some strange issues and I’m not sure why, but it is most likely due to my lack of experience with both tables and loops.

[lua]if CLIENT then return; end

local BadEnt = {
[“cs_desperados”] = { ‘prop_physics_multiplayer’, ‘info_node’ },
[“ttt_whitehouse_b2”] = { ‘trigger_multiple’, ‘env_explosion’ },
[“de_westwood”] = { ‘func_physbox’, ‘func_dustcloud’ },
}

function RemoveBadEnt()
local map = game.GetMap()
for k,v in pairs(BadEnt) do
if k == map then
entblacklist = v
for k,v in pairs(ents.GetAll()) do
if v:GetClass() == entblacklist[1] or v:GetClass() == entblacklist[2] then
v:Remove()
end
end
end
end
end

hook.Add( “InitPostEntity”, “Entity Remover”, RemoveBadEnt )[/lua]

When I started up cs_desperados and had it set to print out the values stored in entblacklist[1] and [2], for some reason where the prop_physics_multiplayer should have been, it was only returning “Prop”

Its embarrassing having to make a thread just for this, but I have been fiddling with it for over an hour and just cant figure out the problem :suicide:

Try something like this? (untested)
[lua]
local BadEnt = {
[“cs_desperados”] = { ‘prop_physics_multiplayer’, ‘info_node’ },
[“ttt_whitehouse_b2”] = { ‘trigger_multiple’, ‘env_explosion’ },
[“de_westwood”] = { ‘func_physbox’, ‘func_dustcloud’ },
}

function RemoveBadEnt()
local map = game.GetMap()

if badEnt[map] then
	for k, v in pairs(badent[map]) do
		for _, ent in pairs(ents.FindByClass(v)) do
			ent:Remove()
		end
	end
end

end

hook.Add( “InitPostEntity”, “Entity Remover”, RemoveBadEnt )
[/lua]

Still nothing, I dont even get any errors with either of those, not sure whats up.

EDIT

I’m using this with TTT, I dont know if it’s any different, but things like props dont seem to spawn until after the first player has spawned, could this be why it is reaching the first loop but not actually removing any entities?

EDIT2

That does seem to be the problem, putting a 15 second timer on the function so it runs after the first spawn works.

I think TTT uses game.CleanUpMap at the beginning of every round, and I’m not sure if InitPostEntity is called after that, although come to think of it, I’m not sure if those entities, such as the triggers can be removed via Lua?

Try adding some debug prints to the script I posted above. You may have to hook to TTT’s begin round event.

Yeah I will have to TTTBeginRound, entities appear on round start and reset after each round.

Thanks though, that code was much cleaner than mine, I learned some things about tables that I didnt know.