I have a table for my entity like this:
[CODE]local orgin_ents = ents.FindInSphere(self:GetLocalPos(),128)[/CODE]
The table contains entities that are surrounding my entity. I want code that will detect if theres a certain entity within the table.
To do this I have made a for loop like so:
[CODE]
for name1 = 1, count do
print(orgin_ents[name1])
end
[/CODE]
The issue with that is, there is no way of selecting a row with the right entity because each row is different on length meaning I wouldnt be able to seek through the row.
This is an example of what the whole table looks like:
[CODE]
Entity [64][info_player_start]
Player [1][[PLEX RP] Chizbang]
Entity [69][predicted_viewmodel]
Entity [90][predicted_viewmodel]
Entity [91][predicted_viewmodel]
Weapon [74][lockpick]
Weapon [75][unarrest_stick]
Weapon [93][keys]
Weapon [94][weapon_physcannon]
Weapon [95][gmod_camera]
Weapon [96][gmod_tool]
Weapon [97][pocket]
Weapon [98][weapon_physgun]
Weapon [99][weapon_keypadchecker]
Weapon [100][door_ram]
Weapon [101][arrest_stick]
Weapon [102][stunstick]
Weapon [103][weaponchecker]
Entity [104][physgun_beam]
Entity [76][my_entity]
Entity [77][durgz_alcohol]
Entity [77][durgz_alcohol]
[/CODE]
What I want to do is find a specific entity within that table... How would I do this? All I want is to get JUST the name and nothing else. (At the moment the Entity name is wrapped in Entity [77] [drugz_alcohol] I just want the drugz_alcohol part)
Do you mean something like this?
[code]
local classToFind = "drugz_alcohol"
local found
for _, ent in pairs( theTableOfManyThings )
if ent:GetClass() == classToFind then
found = ent
break
end
end[/code]
[lua]
function FindEntityInTable( tbl, class )
for _,entity in pairs( tbl ) do
if ( entity:GetClass() == class ) then
return entity;
end;
end;
end;
[/lua]
Sorry, you need to Log In to post a reply to this thread.