This is what I'm using at the moment.
Works fine until theres about 6 npcs or players moving about.
I didn't expect miracles, knew it would be slow, but I'm hoping one of you assist me in tweaking it.
function findtargets(predid)
if (checkpredator(predid)) then
local startvector = _PlayerGetShootPos(predid)
targs = _EntitiesFindInSphere(startvector, radius )
for i = 1,table.getn(targs) do
if (string.find (_EntGetType(targs[i]),"npc_",1,true) ~= nil) or
(_EntGetType(targs[i]) == "player") then
if (predid ~= targs[i]) then
local dist = vecLength( vecSub( startvector, _EntGetPos( targs[i] ) ) )
local Xco = (width/dist)*co
local Yco = (height/dist)*co
_GModRect_Start( targetmaterial )
_GModRect_SetPos( -(Xco/2), -(Yco/2), Xco, Yco )
_GModRect_SetColor( 200, 0, 150, matalpha )
_GModRect_SetTime( .5, 0, 0 )
_GModRect_SetEntity( targs[i] )
_GModRect_Send( predid, predid + (2*i) )
end -- if targ is self
end -- if entype is npc or player
end -- for loop sphere table
end -- if connected
end --function
Never could get decent 'onThink' results, so, Im using the timer megiddo originally used.
I just rewrote it so that more than one player can use it. PredUser[predid].visiontimer = AddTimer blah
Tweak Idea, that I don't know how to impliment.
Tips and Advice appreciated.
targs = _EntitiesFindInSphere(startvector, radius )
That looks for all entities in a 360 sphere around me the player (startvector = playergetshootpos)
Which, for rectangles, is useless. They can only be drawn in the FOV.
I believe if I could get what is in my current view it would help speed things up. (I could be wrong)
From the wiki, theres a _Util.EntsInBox(vert1,vert2)
http://gmwiki.garry.tv/index.php/Util.EntsInBox Anyone know if that would be quicker.
I presume we could use PlayerGetShootAng to set vert2, PlayerGetShootPos to set vert1, but, how do we add in extra height/distance. I understand vecAdd could be used, but, if Im facing any direction, is -1,0,0 behind, +1, 0,0 in front? I somewhat grasp the 3d points, I'm just trepid about them.
And how do I tell how many points there are?
Thanks!