Trying to have an entity find entity targets by class. The issue is that finding more than one class causes the ent to select some targets before others,
is there any way to make it so that it does not matter what class is first in the search?
Without this, the ent will always target "melon" first instead of randomly selecting its target ents.
Here is what I mean by this:
[CODE]melontarget = nil
function findatarget()
for k, v in pairs ( ents.FindByClass("melons") ) do --will always target melons first (WANT TO CHANGE)
melontarget = v
--code here
end
if melontarget == nil then
for k, v in pairs ( ents.FindByClass("someothermelons") ) do --will always target second, should be random targeting
melontarget = v
--someothercode here
end
end
end[/CODE]
local t = ents.FindByClass("melons")
t = table.Add( t, ents.FindByClass("someothermelons") )
if table.Count(t) > 0 then
//select a random thing from the "t" table
end
It may be cheaper to use ents.GetAll( ) in a loop and then just have an if statement compare if it is your class. classes = { melons = true; someothermelons = true } then use if ( classes[ k ] ) then melontarget = v; end ...
ents.FindByClass just loops through all of them anyway, if I recall correctly. So instead of doing it twice, may as well just do it once.
Thanks to both of you. :dance:
Sorry, you need to Log In to post a reply to this thread.