• Removing entity from map in deathrun
    7 replies, posted
Hi all, I have a bugged entity on the deathrun map crash_medievil. I want to remove the entity but for some reason this is not going well... [lua]hook.Add("ShowTeam", "enityid", function( ply, ent ) print( ply:GetEyeTrace().Entity ) ply:GetEyeTrace().Entity:Remove() end) [/lua] ^ If I use that it works fine, it deletes the enity with index 183. But when I try to remove it with the InitPostEntity hook, it says it's a nill value. How do I remove this entity on map load? I also tried using [url=http://pastebin.com/9bKPwZ3a]this[/url] entity remover script but it gives the same result. It does find entity with id 183, but it won't delete it on map load. Image of entity: [img]http://cloud-4.steamusercontent.com/ugc/38620959940542136/492D8D2C8EFBEC561F690760006260499E98F80A/[/img] If I aim at the blade, the whole thing gets removed.
Use your concmd to get the map creation ID of the entity: [url]http://wiki.garrysmod.com/page/Entity/MapCreationID[/url] The in InitPostEntity, use this to retrieve the entity object: [url]http://wiki.garrysmod.com/page/ents/GetMapCreatedEntity[/url] and call Remove() on the object. Keep in mind that for rounds in deathrun, you should also remove the entity from this hook: [url]http://wiki.garrysmod.com/page/GM/PostCleanupMap[/url]
[QUOTE=Robotboy655;47569230]Use your concmd to get the map creation ID of the entity: [url]http://wiki.garrysmod.com/page/Entity/MapCreationID[/url] The in InitPostEntity, use this to retrieve the entity object: [url]http://wiki.garrysmod.com/page/ents/GetMapCreatedEntity[/url] and call Remove() on the object. Keep in mind that for rounds in deathrun, you should also remove the entity from this hook: [url]http://wiki.garrysmod.com/page/GM/PostCleanupMap[/url][/QUOTE] I tried this aproach. The thing is, the map creation ID is different with each map load. I tried multiple times(server restarts) and got different numbers for the entity I was aiming at each time This is strange, the wiki quotes [quote]Returns entity's map creation ID. Unlike Entity:EntIndex or Entity:GetCreationID, it will always be the same on same map, no matter how much you clean up or restart it.[/quote] So why does the value change each time I load the map? Code I used: [lua] hook.Add("ShowTeam", "enityid", function( ply, ent ) print( ply:GetEyeTrace().Entity:MapCreationID() ) end) hook.Add("InitPostEntity", "remover", function() ents.GetMapCreatedEntity(1419):Remove() <- nill value because the value changes each map end) [/lua]
You could find the entities within a box, and discriminate against class.
[QUOTE=James xX;47572154]You could find the entities within a box, and discriminate against class.[/QUOTE] Could you elaborate?
In the InitPostEntity hook, do a loop of the table returned by the ents.FindInBox() function, where you specify the vectors of the box within which the entities you want to remove are, and check the class of the entity within the loop so you don't remove other entities. If the class is the class of the entity you want to remove, then do so.
If the entity index is shifting, then entities are being spawned PRIOR to InitPostEntity... If this is the case then map creation id is your best bet, and it shouldn't change at all.... EntIndex can also shift based on your server max-players. I wrote a simple system which gives you a new function _ent:GetID( ) which returns the EntIndex if the server was at 128 players. It also comes with a conversion function so you can save the GetID value, then to delete you SafeRemoveEntity( EntityFromGetID( id ) ); on InitPostEntity... [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/entities/entity_getid_mapping_system.lua.html[/url] - remove .html to view .lua BUT, what Robot posted is your best option because it is server only. My system is better suited for preventing the need to network the EntIndex to the client for every door on the map just to display text on the door, and other similar situations...
I got them removed for now. But one question: the entity swings and players have to pass without getting hit. For some reason the speed varys to almost zero. Making the trap OP and you can't get past it. Is there a way to set the speed so that it does not vary?
Sorry, you need to Log In to post a reply to this thread.