Finding an Entity

What I’m having problems with is that I just can’t ‘find’ the entity near the player.

My current code:


function checkforEnt()

    if ents.FindInSphere() == "item_ammo_357" then 
	    
		print( "TRUE" )
		
	else
	
	    print( "FALSE" )
		
	end
	
end
hook.Add( "Think", "checkforCar", checkforEnt )

I’m attempting to make it that if an entity is in the Sphere then do something, can anyone help?

I don’t know much about this, but to me it looks like you’re using ents.FindInSphere() completely wrong. Might want to give this a check.

ents.FindInSphere() returns a table of found entities.

You need to use it like this:



function checkForEnt()
    for k, v in pairs(ents.FindInSphere(position, radius)) do
        if (v:GetClass() == "item_ammo_357") then
            -- do whatever you want here
        end
    end
end


‘position’ and ‘radius’ are things you’ll have to set, please don’t just copy and paste the code into a file and tell me it doesn’t work.

Ah thanks for that, I’ll try it now. :smiley: