• Removing world entities on server startup
    10 replies, posted
Trying to remove a few unneeded entities on world startup, originally I tried using EntSpy, however after I saved and uploaded, "Your map differs from server". So I figured I could delete them using a LUA script when the server starts up(or when the map is loaded). However, I have no clue how to obtain these entities using LUA, I tried looking for an entity name, or anything about them, but it just didn't turn out well. Can someone help?
[lua]local entity_blacklist = { "prop_door_rotating", "env_fire", } hook.Add("InitPostEntity","RemoveEntities",function() for _,v in pairs(entity_blacklist) do for _,ent in pairs(ents.FindByClass(v)) do ent:Remove() end end end)[/lua] That's a basic script that removes every entity of a certain class. Just insert the class into the table.
I don't know how to find the class of this specific entity, and I might not want to remove all of these entities, since I believe it's a button, and some of the buttons on the map open doors. I want to remove specific buttons, but I'm not sure how.
Well, there's two main ways to identify an entity: by its class and by its name. If you don't want to remove everything in a certain class, then you have to know the name of the entity you want to remove.
Welp, do you have any idea on how to find the entity name? I've tried a bunch of stuff, nothing really worked. What if the entity doesn't have a name?
All entities have names (classes). It's what they're referred to by. If you want get an entities class, that's really easy. Take this code, and put it in a lua file and run it. Anything you grab with your Physgun will tell you it's class and model. Enter the CLASS into that table you were provided with exactly, in quotations and with a comma after each item. [lua]local function ModelPrinter( ply, ent ) ply:PrintMessage(HUD_PRINTTALK, "Entity Model: ".. ent:GetModel() ) ply:PrintMessage(HUD_PRINTTALK, "Entity Class: ".. ent:GetClass() ) end hook.Add("PhysgunDrop", "ModelPrinter", ModelPrinter)[/lua]
Alright. Well I'm trying to delete the gun spawning weapons on rp_downtown_v2, using a LUA script. Using EntSpy, I got two things. func_button(Which I assume is the entity class) and gunshop_gunmaker_buttons(This was for all 3 buttons, either a group or names?) Anyways, I tried deleting it using gunshop_gunmaker_buttons in the table, however, it didn't work. I'm unsure what caused this, but I can reasonably assume it's because it's not finding anything to delete, since I'm just putting in the wrong information for it. Like I've already stated, I don't want to delete all of the func_button on the map, since a lot of them are used for other doors, etc. I'm very inexperienced with Lua, and I just want to remove the gunshop buttons, since they are very annoying. Running your physgun script, I find that the entities I want to remove output this information: [CODE] Entity Model: *162 Entity Class: class C_BaseEntity Entity Model: *163 Entity Class: class C_BaseEntity Entity Model: *164 Entity Class: class C_BaseEntity [/CODE] However, so do all of the other buttons in the map, but with different models. If there is an alternative for removing the buttons automatically, without requiring the end-user to redownload the map, then I would be able to use that too.
You could make Entoros' script a bit more complicated and index the buttons you want to remove by their class name, and put the data in that index the vector of those buttons, then remove the buttons if they're only at that specific vector.
Okay, I think I'll be able to handle the rest if I knew how to get the vector of the entities, any help there?
[QUOTE=ANiChowy;22104423]Okay, I think I'll be able to handle the rest if I knew how to get the vector of the entities, any help there?[/QUOTE] Don't remove entities by their position. First type Picker in the console to be able to see invisible entities and look directly at the one you want to have removed. Type the following : lua_run print(Entity(1):GetEyeTrace().Entity) In single player of course. You will get a class name and a number. You can then use this number to uniquely identify the entity, as long as the server has the same amount of players. So then you can do Entity(number):Remove()
I am retarded.
Sorry, you need to Log In to post a reply to this thread.