Return true end end - We found nothing so we will set our enemy as nil (nothing) and return false self: SetEnemy( nil) Here we loop through every entity the above search finds and see if it's the one we want for k,v in ipairs( _ents ) do if ( v: IsPlayer() ) then - We found one so lets set it as our enemy and return true self: SetEnemy(v) FindInSphere( self: GetPos(), self.SearchRadius ) ents.FindInCone() to replicate eyesight local _ents = ents. Search around us for entities - This can be done any way you want eg. If the enemy is dead( we have to check if its a player before we use Alive() ) elseif ( self: GetEnemy():IsPlayer() and !self: GetEnemy():Alive() ) then return self: FindEnemy() - Return false if the search finds nothing end - The enemy is neither too far nor too dead so we can return true return true else - The enemy isn't valid so lets look for a new one return self: FindEnemy()Įnd end - ENT:FindEnemy() - Returns true and sets our enemy if we find one - function ENT: FindEnemy() If our current enemy is valid if ( self: GetEnemy() and IsValid( self: GetEnemy()) ) then - If the enemy is too far if ( self: GetRangeTo( self: GetEnemy():GetPos()) > self.LoseTargetDist ) then - If the enemy is lost then call FindEnemy() to look for a new one - FindEnemy() will return true if an enemy is found, making this function return true return self: FindEnemy() ENT:Get/SetEnemy() - Simple functions used in keeping our enemy saved - function ENT: SetEnemy(ent)Įnd - ENT:HaveEnemy() - Returns true if we have an enemy - function ENT: HaveEnemy()
0 Comments
Leave a Reply. |