Need help changing up a code


function ENT:FindEnemy()
        -- Search around us for entities
        -- This can be done any way you want eg. ents.FindInCone() to replicate eyesight
    local _ents = ents.FindInSphere( self:GetPos(), self.SearchRadius )
        -- Here we loop through every entity the above search finds and see if it's the one we want
        for k, v in pairs( _ents ) do
                if ( v:IsPlayer() and v:Health() > 0) then
                        -- We found one so lets set it as our enemy and return true
                        self:SetEnemy( v )
                        return true
                end
        end
        -- We found nothing so we will set our enemy as nil ( nothing ) and return false
        self:SetEnemy( nil )
        return false
end

I need help changing this code up a bit for my NextBot NPC. I need to make it find only my other Nextbot entity by it’s class(class is simple_nextbot)
Can anyone help?

try this


function ENT:FindEnemy()
       
        
    local _ents = ents.FindByClass( "simple_nextbot" )
      
        for k, v in pairs( _ents ) do
		if IsValid(v) and v:Health() > 0 then
        		self:SetEnemy( v )
               		return true
		end
        end
        self:SetEnemy( nil )
        return false
end

[lua]
function ENT:FindEnemy()
local ents = ents.FindInSphere(self:GetPos(), self.SearchRadius) // Be sure to define self.SearchRadius
for k,v in pairs(ents) do
if((IsValid(v)) and (v:GetClass()==‘simple_nexbot’) and (v:Health()>0)) then
self:SetEnemy(v)
return true
end
end

self:SetEnemy(nil)
return false

end
[/lua]