Get Entity From Position From Table

I am trying to set certain entities networked variables from their position via a table. I am not sure what to turn the string into so that I can use v.Entity like I would use trace.Entity when looking at the entity.

local function SetDoor()
local ClosedDoors = { “107.0000 0.0000 56.2813” }

for k, v in pairs( ClosedDoors ) do
	if v.Entity:IsDoor() then
		v.Entity:SetNWInt( "Type", 0 ) 

concommand.Add( “SetDoors”, SetDoor )

You can’t, you should just store the entity’s object in the table rather than it’s position.

You could, just it would be exceptionally pointless.

Example? I am trying to make it easy to add doors to the table. Basically so I can auto lock doors on map load and other things with doors.

By looping through every door and comparing it’s position with the position in the table?

You would get rounding errors.


You could do it by rounding the position to the same number of decimal places as stored in the table, but as you said, would be pointless.

I’d personally compare it and give a scope of one or two degrees offset from the position. But yeah, completely pointless

[lua]local doors = {}

table.insert(doors , ent)[/lua]

Just have “ent” as the door entity.

These are map doors not like lua created doors.

/Door detection code/

local DoorTypes = – A list of all entities we recognize as doors



function IsADoor(ent) --A function which returns true if we pass it a door entity

for k, v in pairs( DoorTypes ) do

    if( v == ent:GetClass() ) then return true end


return false


Doors = {}

for k,v in ipars(ents.GetAll()) do
if IsADoor(v) then

There is no difference, they all work exactly the same and can be interacted with using lua.

[lua]function _R.Entity:IsDoor() return string.find(self:GetClass() , “door”) end[/lua]


Of course that’s the best way which everyone should use. I copy pasted that code from an example meant to a newbie which I wanted to keep as simple as possible.

Is there not a way to select specific doors so I can set their type like in this picture.



Type the following in your client console whilst looking at a door.

lua_run_cl PrintTable( LocalPlayer():GetEyeTrace().Entity:GetTable() )

It should print the entity ID. This is exactly the same each time the map loads, so simply store the ID ( also retrievable by Entity:EntIndex(), you can convert it back to an entity with Entity( id ).

Exactly what I was looking for, thanks.