Code:
mob FollowNPC name = "Generic FollowNPC" icon = 'base.dmi' var/mob/target = 0 var/mode = "Total Retaliation" var/weapontype = "" New() ..() serp if(mode == "Attack") var/mob/D = locate() in oview(src,8) world << "It's in attack mode!" if(!src.target) world << "It doesn't have a target!" if(D) world << "It found someone!" if(!target && src.owner != D) target = D else world << "It isn't finding anyone." if(src.target != 0 && src.target) if(get_dist(src,target) <= 8) step_towards(src,target) else src.target = 0 src.canattack = 1 else if(src.target != 0) src.target = 0 src.canattack = 1
|
Problem description: This is the code for an NPC that follows you around and fights for you. I cut out irrelevant pieces of code and did not include everything necessary to make it function, but this should give you the gist of what I'm trying to do. The problem I'm having is that when Mode is set to Attack it doesn't find any mobs so target never gets set and therefore it doesn't attack them. Any suggestions?