Make you the owner of an npc?

Well i was looking at the npc tasks and stuff and noticed that entities have setOwner and wanted to know how to use that on a SNPC.

A NPC is an entity so it would work, though you should actually read the wiki page, it’s not what you think it is.
**[Entity.SetOwner

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.SetOwner)**

wellim wanting to make the npc have a schedule to follow the player that spawned it so how would i go about that?

This could be of some help.

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

ENT.HitSound = “”
ENT.NPCModel = “models/error.mdl”
ENT.DeathNoise = Sound( “” )
ENT.HitDist = 0
ENT.HitViewP = 0
ENT.HitViewY = 0
ENT.HP = 0
ENT.Damage = 0

local schdSearch = ai_schedule.New( “AIFighter Chase” )
local schdChase = ai_schedule.New( “AIFighter Chase” )
local schdAttack = ai_schedule.New( “AIFighter Chase” )

schdSearch:EngTask( “TASK_GET_PATH_TO_ENEMY”, 0 )
schdSearch:EngTask( “TASK_RUN_PATH_TIMED”, 0 )
schdSearch:EngTask( “TASK_WAIT”, 0 )
schdSearch:AddTask( “SearchForPlayer”, 0 )

schdChase:EngTask( “TASK_GET_PATH_TO_ENEMY”, 0 )
schdChase:EngTask( “TASK_RUN_PATH_TIMED”, 0 )
schdChase:EngTask( “TASK_WAIT”, 0 )
schdChase:AddTask( “FindEnemyPlayer”, 0 )

schdAttack:EngTask( “TASK_STOP_MOVING”, 0 )
schdAttack:EngTask( “TASK_FACE_ENEMY”, 0 )
schdAttack:AddTask( “EnemyAttackSurvivor”, 0 )

function ENT:TaskStart_SearchForPlayer( ) end
function ENT:TaskStart_FindEnemyPlayer( ) end
function ENT:TaskStart_EnemyAttackSurvivor( ) end

function ENT:Task_SearchForPlayer( )

if ( #player.GetAll( ) < 1 ) then return end

local pl	 = player.GetAll( )[ math.random( 1, #player.GetAll( ) ) ]

if ( pl:IsPlayer( ) && pl:Alive( ) && pl:Team( ) == TEAM_SURVIVOR ) then
	
	self:SetEnemy( pl, true )
	self:UpdateEnemyMemory( pl, pl:GetPos( ) )
	
	self:StartSchedule( schdChase )
	self:TaskComplete( )

end

end

function ENT:Task_FindEnemyPlayer( )

if ( !self:GetEnemy( ) || !self:GetEnemy( ):Alive( ) || self:GetEnemy( ):Team( ) != TEAM_SURVIVOR ) then self:StartSchedule( schdSearch ) self:TaskComplete( ) return end

local Enemy	= self:GetEnemy( )

self:UpdateEnemyMemory( Enemy, Enemy:GetPos( ) )

if ( Enemy:GetPos( ):Distance( self:GetPos( ) ) < self.HitDist ) then
	
	self:SetEnemy( Enemy, true )
	self:UpdateEnemyMemory( Enemy, Enemy:GetPos( ) )
	
	self:StartSchedule( schdAttack )
	self:TaskComplete( )
		
elseif ( Enemy:GetPos( ):Distance( self:GetPos( ) ) > ( self.HitDist -1 ) ) then
		
	self:StartSchedule( schdChase )
	self:TaskComplete( )
		
end

end

function ENT:Task_EnemyAttackSurvivor( )

if ( !self:GetEnemy( ) || !self:GetEnemy( ):Alive( ) || self:GetEnemy( ):Team( ) != TEAM_SURVIVOR ) then self:StartSchedule( schdSearch ) self:TaskComplete( ) return end

local Enemy	= self:GetEnemy( )
local tr	= util.QuickTrace( self:GetPos( ) + Vector( 0, 0, 32 ), self:GetForward( ) * 83, self )

if ( ValidEntity( tr.Entity ) && tr.Entity == self:GetEnemy( ) ) then

	self:EmitSound( self.HitSound )
	
	self:SetSequence( self:LookupSequence( "Melee" ) )

	if ( Enemy:Armor( ) > 0 ) then
	
		Enemy:SetArmor( Enemy:Armor( ) - self.Damage )
		
		if ( Enemy:Armor( ) < 0 ) then Enemy:SetArmor( 0 ) end
		
	else
	
		Enemy:SetHealth( Enemy:Health( ) - self.Damage )

		if ( Enemy:Health( ) < 1 ) then

			Enemy:Kill( )

		end
		
	end

	local Random1	= math.Rand( -self.HitViewP, self.HitViewP )
	local Random2	= math.Rand( -self.HitViewY, self.HitViewY )

	Enemy:ViewPunch( Angle( -Random1, Random2, 0 ) )

	GAMEMODE:PlayerHurt( Enemy, nil, self )
		
	self:StartSchedule( schdChase )
	self:TaskComplete( )
	
else
	
	self:StartSchedule( schdChase )
	self:TaskComplete( )
	
end

end

function ENT:Initialize( )

self:SetModel( self.NPCModel )

self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal( )

self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )

//self:SetCollisionGroup( COLLISION_GROUP_ALL )

self:CapabilitiesAdd( CAP_MOVE_JUMP | CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_MOVE_CLIMB )

self:SetMaxYawSpeed( 5000 )

self:SetHealth( self.HP )

end

function ENT:OnTakeDamage(dmg)
local damagePosition = dmg:GetDamagePosition()
local damageAmount = dmg:GetDamage()
local damageForce = dmg:GetDamageForce()

self:SetHealth( math.max(self:Health() - damageAmount, 1) )

if (self:Health() > 1) then
	self:DoDeath( dmg:GetAttacker( ) )
else
	self.DamageForce = damageForce
end

BEffect(damagePosition, 1, self, damageForce)

end

function ENT:BEffect(position, decals, entity, force)
if (!force) then
force = VectorRand() * 80
end

local effectData = EffectData()
	effectData:SetOrigin(position)
	effectData:SetNormal(force)
	effectData:SetScale(0.5)
util.Effect("RagdollImpact", effectData, true, true)
	
local effectData = EffectData()
	effectData:SetOrigin(position)
	effectData:SetEntity(entity)
	effectData:SetStart(position)
	effectData:SetScale(0.5)
util.Effect("BloodImpact", effectData, true, true)
	
for i = 1, decals do
	local trace = {}
		trace.start = position
		trace.endpos = trace.start
		trace.filter = entity
	trace = util.TraceLine(trace)
		
	util.Decal("Blood", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
end

end

function ENT:FakeDamageInfo(damage, inflictor, attacker, position, damageType, damageForce)
local damageInfo = DamageInfo()
local realDamage = math.ceil( math.max(damage, 0) )

damageInfo:SetDamagePosition(position)
damageInfo:SetDamageForce(Vector() * damageForce)
damageInfo:SetDamageType(damageType)
damageInfo:SetInflictor(inflictor)
damageInfo:SetAttacker(attacker)
damageInfo:SetDamage(realDamage)

return damageInfo

end

function ENT:DoDeath( attacker )

_NPCLIST = _NPCLIST - 1

if ( attacker && attacker:IsPlayer( ) ) then

	attacker:AddCash( self.KillCash )
	
	attacker:AddFrags( 1 )
	
end

self:EmitSound( self.DeathNoise )

local Ragdoll	= ents.Create( "prop_ragdoll" )

Ragdoll:SetPos( self:GetPos( ) )
Ragdoll:SetAngles( self:GetAngles( ) )

Ragdoll:SetModel( self:GetModel( ) )

Ragdoll:Spawn( )
Ragdoll:Activate( )

Ragdoll:Fire( "kill", 1, 10 )

Ragdoll:SetCollisionGroup( COLLISION_GROUP_DEBRIS )

//self:CreateRagdoll( )

timer.Simple( 5, function( ) if ( Ragdoll ) then Ragdoll:Remove( ) end end )

//self:SetSchedule( SCHED_DIE_RAGDOLL )

self:Remove( )

end

function ENT:Think( )

if ( !self:GetEnemy( ) ) then return end

local Enemy	= self:GetEnemy( )

self:UpdateEnemyMemory( Enemy, Enemy:GetPos( ) )

end

function ENT:SelectSchedule( )

self:StartSchedule( schdSearch )

end
[/lua]

This is not my code.

well i still dont know how to just make a schedule that has them following the player that spawned them not just someone on their team.