ID:1681476
 
Keywords: moster, npc, pet
Code:

mob
var
owner = ""
list
killlist = list()
pets
Licker
icon = 'Licker.dmi'
icon_state = "normal"

New()
..()
spawn() StartPetAI()
proc/StartPetAI()
var/gottarget = 0
for(var/mob/M in oview())
if(src.owner == M.key)
walk_to(src,M,1,5)
for(var/mob/H in oview())
if(H in src.killlist)
if(gottarget == 0)
gottarget = 1
walk_to(src,H,1,5)
if(H in oview(1))
step_towards(src,H)
spawn(5) StartPetAI()
verb
Pet_Attack(var/mob/M in oview())
set category = "Pet"
if(M.owner == src.key)
src<<"[M]: That's me, silly master!"
else
for(var/mob/H in oview())
if(H.owner == src.key)
H.killlist.Add(M) </b>


Problem description:I do not want to choose who to attack, the pet should know who to attack (zombies or other), and automatically after the enemy dies, he chooses another, and when I tell him to stop attacking, he follows me around

You create a pet loop proc, that performs behavior based on various settings.

mob/pets
var/getTarget = FALSE
var/target

proc/Targets()
. = list()
for(var/mob/monster/monster in oview())
if(target.IsDead()) continue
. += monsters

proc/GetNewTarget()
target = null
var/targets = Targets()
while(targets.len>0)
var/mob/selection = pick(Targets())
targets -= selection
if(!selection.IsDead())
target = selection
break

proc/PetLoop()
set background = 1
while(src)
if(getTarget && (!target || target.IsDead()))
GetNewTarget()

if(!target)
GoToMaster()

else
AttackTarget()

sleep(petDelay*world.tick_lag)