• Searchable Brush entity
    3 replies, posted
Hello, I've been looking for a way to make a brush entity made in hammer usable in lua code but I've not been able too. Basically I need help on my way to creating an entity that can be created in hammer editor and then I can use in lua for when the user presses 'e' (use) because it will be a searchable point. Any help on how to go about doing this would be greatly appreciated. Thank you.
The first part of this would most likely be: [CODE] hook.Add("InitPostEntity", "getentities", function() allbrushes = {} for k,v in pairs(ents.GetAll()) do if v:GetClass() == "func_brush" then allbrushes:insert(v) else return end end) -- This will get called once at complete initialization and can be inserted anywhere in the code's free area function GM:KeyPress(u,k) if k == "IN_USE" then for k,v in allentities do if ((v:GetClass() == "func_brush") and (v:GetName() == "Your brush's name")) then -- GetName should only be used if you gave your brush a name. -- rest of code here, for instance: u:ChatPrint("Brush is at" .. v:GetPos().x .. v:GetPos().y ..v:GetPos().z) -- I think you should also be able use tostring(v:GetPos()) else return end end else return end end [/CODE] I'm not too sure about using GetPos() with brushes, which would render this answer incomplete.
[QUOTE=gertoja;32608965]The first part of this would most likely be: [CODE] hook.Add("InitPostEntity", "getentities", function() allbrushes = {} for k,v in pairs(ents.GetAll()) do if v:GetClass() == "func_brush" then allbrushes:insert(v) else return end end) -- This will get called once at complete initialization and can be inserted anywhere in the code's free area function GM:KeyPress(u,k) if k == "IN_USE" then for k,v in allentities do if ((v:GetClass() == "func_brush") and (v:GetName() == "Your brush's name")) then -- GetName should only be used if you gave your brush a name. -- rest of code here, for instance: u:ChatPrint("Brush is at" .. v:GetPos().x .. v:GetPos().y ..v:GetPos().z) -- I think you should also be able use tostring(v:GetPos()) else return end end else return end end [/CODE] I'm not too sure about using GetPos() with brushes, which would render this answer incomplete.[/QUOTE] GetPos() on a brush entity returns its position as it would on other entities, as it goes off the origin of the brush entity.Though depending if the original poster decides to run it on the client versus the server can affect it if the brush trying to be found is one that the client doesn't load from the bsp, such as trigger_teleports.
Also allentites in GM:Keypress should be allbrushes
Sorry, you need to Log In to post a reply to this thread.