ents.GetAll() not returning anything

So I’m trying to write a script that removes Traitor testers from TTT maps. Of course, at the moment the script only supports versions of ttt_67thway. Line 5 should be printing to the console every time it finds ‘e’ in ents.GetAll() but doesn’t, and line 14 should be printing the number of entities in the map but prints “0 in all!”
Anyone know what the problem is?

Thanks in advance!

The problem may be you call function before entities spawn. Try to use InitPostEntity hook, and i believe you have typo in line 9.

[lua]
local debugNumOfEnts = 0

function CheckMap_Testers()
if ( string.find( string.lower( game.GetMap() ), “ttt_67thway” ) ) then
Msg("Tester present in map!
")
for _, e in pairs(ents.GetAll()) do
debugNumOfEnts = debugNumOfEnts + 1
Msg(“Found” … tostring(e:GetClass()) … "!
")
if e:GetClass() == “func_breakable” and ValidEntity(e) then
e:Fire(“break”)
end
end
Msg("Done!
")
Msg(debugNumOfEnts … " in all!
")
end
end

hook.Add( “InitPostEntity”, “Check_Map_Testers”, CheckMap_Testers )
[/lua]

Try this aswell:
Edited:
[lua]
Use the TTTBeginRound hook because most entities are respawned on a new round start.
–lua/autorun
local function RemoveTTTTesters()
if SERVER then
for _, ent in ipairs( ents.FindByClass(“ttt_logic_role”)) do
if ent:IsValid() then
ent:Remove()
end
end
end
end
hook.Add(“TTTBeginRound”, “CheckTheMap”, RemoveTTTTesters)
[/lua]

Should also test that its actually detecting you are on the right map.

ie: put an else on the conditional statement and be liek MsgN("/n/n Not on 67th way /n/n")

Ah! It never occurred to me to hook it (probably because I started this script at about 4:30 AM) - thanks a billion!
(-snip- Actually, turns out that’s not the name. Don’t know why ent_text told me its name was “func_breakable”.)

I actually don’t want to remove all ttt_logic_role entities like that, because that could potentially break certain parts of some maps. Thanks for the advice, though!

It does detect map since it says it finds 0 ents, which is in if statement checking for map.

[editline]22nd August 2012[/editline]

Ah, was thinking it’s class if func_breakable, which would be weird idea since every breakable thing would get removed. Anyways glad to see it works.

Oddly enough, I can ent_fire it to break via console, but for whatever reason it won’t break from the script.

Maybe try e:Fire(“break”,"",0)

Turns out it doesn’t have a proper targetname (I discovered that after decompiling the map to check the targetname), so I decided to just go ahead and remove the button that activates the tester instead with this code:

[lua]function CheckMap_Testers()
if ( string.find( string.lower( game.GetMap() ), “ttt_67thway” ) ) then
Msg("Tester present in map!
")
for _, e in pairs(ents.GetAll()) do
if(e:GetName() != “”) then
Msg("Found " … string.lower(tostring(e:GetName())) … "!
")
end
if (string.lower(tostring(e:GetName())) == “scanbutton”) then
e:Remove()
Msg("Deleted scanbutton!
")
elseif(string.lower(tostring(e:GetName())) == “oordoor”) then
e:Remove()
Msg("Deleted oordoor!
")
end
end
end
end

hook.Add( “InitPostEntity”, “Check_Map_Testers”, CheckMap_Testers )[/lua]

However, neither “e:Remove()” works, but the following Msg() does.

Here’s what’s printed to console (removed most of the irrelevant bits)

[editline]22nd August 2012[/editline]

Fixed it! I should’ve heeded brandonj4’s advice from the beginning, haha!
I hooked it to TTTPrepareRound, and now it works perfectly!

Thanks everyone!

Oh yes, i’m not used to TTT’s internal workings. It probably respawned the entity on new round haha.