Permanently remove entities from map

Hello!

I would like to know how can I remove some entities from map permanently, for example, gas pumps and dors from evocity map. but I can’t find out how to do it.

I hope you can help me guys

Thanks :slight_smile:

I’d recommend running a delete ents script on InitPostEntity. Alternatively, some entities can be removed from the map by using entspy ( if I recall the name of the program correctly ) however you can only remove certain entities before actually changing the structure of the map meaning the server and client both need the same map.

The ideal solution is to, as Acecool said, have a small autorun script that adds an InitPostEntity hook that then deletes whatever entities you want deleted.

Oh! That’s great! I’m so so noob with that things. Could you tell me how to use that hook? xP

Thank you guys! I really really appreciate your help!

I use it in a file called map_content.lua in essentially what is lua/autorun/server/

Here’s the portion relevant to you - I run two passes on mine to account for auto-refresh. The first pass is to remove constraints and the second cleans up entities - I’ll only show what the second pass looks like:
[lua]hook.Add(“InitPostEntity”, “acecools_map_content”, function( )
// Loop through all of the entities in the map.
for k, ent in pairs( ents.GetAll( ) ) do

	// Test for the class which we are going to remove
	if ( ent:GetClass( ) == "prop_physics"
		|| ent:GetClass( ) == "prop_vehicle_prisoner_pod"
		|| ent:GetClass( ) == "phys_constraint"
		|| ent:GetClass( ) == "phys_constraintsystem"
		|| ent:GetClass( ) == "item_healthcharger"
		// And many more...
	) then
		// Exceptions
		if ( ent:GetClass( ) == "func_brush" && ent:GetModel( ) == "*19" ) then continue; end // *19 == bathroom window subs

		// Remove the above listed entity classes...
		ent:Remove( )
		ent = nil;

	end
end

end );[/lua]

Keep in mind that this is only a very small segment of the code; I do constraint passes, spawn map-entities, and other things in this file; but this serves the purpose of removing entities and sets up a pattern you can follow you add to it. You don’t need to keep the formatting of how I formatted the code, you could put all the || s on one line instead of one per line, you could even do that entirely differently!

Why are you setting ent = nil after removing it?

I’d wager it’s a “safety precaution” but I can’t tell what it’s supposed to prevent…

Even worse your entire “exception” line is never going to run unless you add “func_brush” to the list of classes you want deleted (which is ridiculous).

[editline]3rd March 2014[/editline]

It doesn’t work as a safety precaution though, ent is a local variable. It goes out of scope and is automatically deleted, the line does literally nothing. It’s pointless.

[editline]3rd March 2014[/editline]

Here’s a better, simpler example for the OP (going with the same assumption that Acecool did (which is kinda silly if you ask me) that he wants to delete specific entities based on their class solely):

[lua]
local blacklist = {
[“prop_physics”] = true,
[“prop_whatever”] = true,
}

hook.Add( “InitPostEntity”, “wat”, function()
for _, ent in pairs( ents.GetAll() ) do
if blacklist[ ent:GetClass() ] then ent:Remove() end
end
end )
[/lua]

Woah! Nice way to check values on a table (I’m a bit new on keyvalues)

func_brush is in the list for the full script; I left it in to show other more specific exclusions can be done.

Yes, you can remove entities that way; it is shorter and looks neater; depending on how much control you may or may not need that may be the ideal solution for you.

[editline]3rd March 2014[/editline]

I am used to other languages where memory management plays a larger role and so I put some of those techniques to use in my code; even though the scope of ent only exists in the loop, it’s there so if/when I port the code over to another language that all of the logic will be implemented.

It shouldn’t be the way to handle exclusion though, it’s silly and you’ll just end up with a hundred times this if something == “blah” or something == “hue” or something == “resdsadsa”…

Yeah, the key access would be faster plus exclusions if needed although those O( 1 ) operators strung together won’t have a huge impact on performance, especially since it’s only executed once on map-load. The code is dated over a year ago too when I wrote that. I have since changed some ways of how I do things in Lua:

Benchmarking, and using key-access for Should HUD Paint, etc. I update the code as I go and am turning a lot into their own libraries!
https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua

As for the exclusion for the window; it needs to be there as all other func_brushes on the map are removed, but that one needs to stay as it keeps people from jumping through the window into a house.

In what possibly relevant language do stack allocations not delete them self when they fall out of scope?
By relevant I mean (mostly) imperative languages, for example you’d never port something like this directly to a primarily functional language.

Regardless, a method specifically designed to remove an object (ent:Remove()) would in most circumstances also deallocate the memory that it used.

Your notion of making code with portability in mind is insane if you ask me, no code written in one language would never be optimal in another.
You’d always have to modify the code regardless, I don’t see what makes ent = nil so special.

[editline]3rd March 2014[/editline]

This isn’t about performance at all though, it’s about making clean and readable code.

This is so specific that it’s ridiculous.

I agree; it’s old code.

It’s specific because it’s map_content.lua; each map can use their own as there are hook calls - I stripped it down and included that line from the v33 map config as an example ( Op specified evocity - that window would be an important func_brush to not delete if he chooses to remove func_brushes ). There definitely is room for improvement; it’s well over a year old. I’ll get right on it, after I finish other things :slight_smile:

I appreciate you helping people learn, but you shouldn’t use old or outdated code as educational material.

Fair enough, but I believe you should show code for general use, not specifics.

Sorry to be grave-digging this thread, but what would be the simplest way of finding out the names of custom models or entities on the map?

Nevermind.

print(LocalPlayer():GetEyeTrace().Entity:GetModel())
print(LocalPlayer():GetEyeTrace().Entity:GetClass())

also

Guess I’m a little bit late to the party. But just wanted to say thanks to everyone! Espacially EvacX for his nice and clean code.

Lol, “last updated 2005”