I made a glass map for gmod and I want the ability to respawn all the breakable glass on the map and a few other entities using lua without removing everyones spawned props and stuff. Only way I found to do it was using CleanUpMap and this little bit of code:
[CODE]
CurTable = {}
for I=1,table.Count(ents.GetAll()) do
if ents.GetAll()[I]:GetClass() != "func_breakable" && ents.GetAll()[I]:GetClass() != "env_explosion" then
table.insert(CurTable, ents.GetAll()[I]:GetClass())
end
end
game.CleanUpMap(false, CurTable)
[/CODE]
So this works perfectly fine except ONE thing, it removes the jeep if it is spawned, this is the only entity that gets removed that I know of when this code is used. It's making me crazy because I don't know why!
The only reason I can think that the car would get removed is that it shows up as func_breakable for some reason. Check the class of it? I also feel the need to correct you, as what you're doing just looks intentionally unoptimized:
[lua]
local CurTable = {}
for k,v in pairs(ents.GetAll()) do
if v:GetClass() != "func_breakable" && v:GetClass() != "env_explosion" then
CurTable[#CurTable+1] = v
end
end
game.CleanUpMap(false, CurTable)[/lua]
The looping problem is obvious, but what kind of speed increase do you get from manually inserting instead of using table.insert?
[QUOTE=.\\Shadow};43198224]The only reason I can think that the car would get removed is that it shows up as func_breakable for some reason. Check the class of it? [/QUOTE]
Thanks for the tip on the loop, I was wondering that too but the entity class shows up as "prop_vehicle_jeep" everything else works fine ex. prop_vehicle_air doesn't get deleted.. :\
[QUOTE=Bletotum;43198270]The looping problem is obvious, but what kind of speed increase do you get from manually inserting instead of using table.insert?[/QUOTE]
The main problem besides the loop was that the OP was declaring the table as a global, which is more expensive than a local. I don't know for sure, but I think indexing with brackets is less expensive than using a function.
[QUOTE=Pumahawk;43198898]Thanks for the tip on the loop, I was wondering that too but the entity class shows up as "[B][U][I]prop_vehicle_jeep[/I][/U][/B]" everything else works fine ex. prop_vehicle_air doesn't get deleted.. :\[/QUOTE]
AHA
That's what it was!
The classname is ACTUALLY prop_vehicle_jeep_[B][I]old[/I][/B]
prop_vehicle_jeep_old is for HL2 Jeep.
prop_vehicle_jeep is for EP2 Jalopy.
prop_vehicle_airboat if for the Air Boat.
Just FYI.
[QUOTE=BFG9000;43203826]AHA
That's what it was!
The classname is ACTUALLY prop_vehicle_jeep_[B][I]old[/I][/B][/QUOTE]
But the look at the code, the name shouldn't matter because its copy every entity class on the map to the table EXCEPT "func_breakable" and "env_explosion"
[U][B]EDIT[/B][/U]
BFG you actually are right! I added a "prop_vehicle_jeep[B][I]_[/I][/B]old" to the table and it worked, thanks :D so is this like a bug im guessing because it would come up as "prop_vehicle_jeep" when I checked the class? One more thing I'm wondering is what other entities this happens for so people's stuff doesn't get deleted :s
[QUOTE=Pumahawk;43204616]
BFG you actually are right! I added a "prop_vehicle_jeep[B][I]_[/I][/B]old" to the table and it worked, thanks :D [/QUOTE]
Great! :D
To answer your question though, not that I'm aware of. prop_vehicle_jeep_old is the only entity which I believe has this naming convention.
Sorry, you need to Log In to post a reply to this thread.