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.

[lua]
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 ) 
	end
end

end
concommand.Add( “SetDoors”, SetDoor )
[/lua]

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.

[editline]09:25PM[/editline]

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.

[lua]/////////////////////
/Door detection code/
/////////////////////

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

"func_door",
"func_door_rotating",
"prop_door_rotating"

}

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

end

return false

end

Doors = {}

hook.Add(“InitPostEntity”,function()
for k,v in ipars(ents.GetAll()) do
if IsADoor(v) then
table.insert(Doors,v)
end
end
end)[/lua]

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]

-snip-

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.

http://www.darkflaw.com/images/doors.png

Yes.

EntIndex()

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.