ID:2144432
 
Code:
mob/proc
AI()
var/mob/Monster/M = src
if(active)
return
active=1
var/fighter = 1
spawn()
while(fighter)
if(!target)
active = 0
fighter = 0
break
if(!froze)
if(is_coward)
if(target in view(Attack_View, src))
step_away(src,target,5)
else
target=null
active=0
fighter=0
break
else
if(target in view(Attack_View, src))
walk_to(src, target, 1, move_delay)
if(target in view(1))
dir = get_dir(src, target)
step_towards(src, target)
else
if(!ishome())
target=null
active=0
fighter=0
walk_back=1
M.WB()
break
else
walk(src, 0)
sleep(move_delay)
ishome()
var/home = 0
if(x == start_x)
if(y == start_y)
if(z == start_z)
home=1
return home
mob/Monster
proc
set_start()
start_x = x
start_y = y
start_z = z
start_dir = dir
AI_walk()
spawn()
while(src)
var/skip=0
if(!IS_STARTED) skip = 1
if(active) skip = 1
if(walk_back) skip = 1
if(froze) skip = 1
if(!skip)
var/found_target=0
if(Attacks != "None")
var/list/L=list()
for(var/mob/M in view(Attack_View, src))
if(Attacks == M.Karma) L += M
if(Protector)
for(var/mob/Monster/M in view(Attack_View, src))
if(!M.is_coward)
if(M.target)
if(!M.Protector) L += M
if(L.len > 0) //Checks to see if anything is in the list
J_Target(src ,pick(L))// Randomly picks a target
AI()
if(!found_target)
if(auto_movement)
var/list/steps = list(NORTH, SOUTH, EAST, WEST)
step(src, pick(steps))
sleep( rand(15,30) )
Reset()
Health=MaxHealth
// J_update(src)
WB()
var/walked=0
spawn()
while(walk_back)
if(target)
walk_back = 0
walk(src, 0)
break
if(Dead)
walk_back = 0
walk(src, 0)
break
var/atom/T=locate(start_x,start_y,start_z) //finding the starting location
var/locto//a holder varible for the starting point
if(T in view())//checking if the starting point(T) is in view of mob
locto = T//if its true then set locto(holder) to T
if(locto)
if(!walked)
walked=1
walk_to(src, locto, 0, move_delay)
if(ishome())//after moving checking to see if mob is in starting location
walk_back = 0
walk(src, 0)
break
else//if starting point is not in range of mob
tries++
if(tries >= 3)//if tries higher or equal to 3 do the following
tries = 0
loc=locate(start_x, start_y, start_z)
dir = start_dir
walk_back = 0
walk(src, 0)
break
sleep(10)//delay for walking back can be changed to your needs
Bump(atom/O)
if(isobj(O))//if O is a obj
three_steps(O,dir)//make O step in mobs direction
else if(ismob(O))//if not a obj but a mob and mob is active attack
if(active) AttackProc(O)//if active J_Attack O
..()
Move()//for when the NPC moves
..()
if(walk_back)
if(ishome())//if mob is in starting location
dir=start_dir//set direction to starting direction
walk_back=0//set walk_back so it can be used agian when needed
walk(src,0)
Reset()
New()
..()
underlays+=image('icons.dmi',icon_state="shadow",pixel_y=-3)
set_start()//on mob/new set start point
AI_walk()//call walking procedure
J_showbars(src)//show the health meter
J_update(src)//update the health meter
proc/three_steps(atom/O, dir_)
var/steps=0
spawn()while(steps<3)
steps++
step(O,dir_);if(steps>=3) break
sleep(3.8)//set a delay to make it look sick!
mob
Move()
if(froze) return
..()
if(client) Activate_Area(src)

mob/var/tmp/IS_STARTED=0

proc/Activate_Area(mob/maker) //the mob thats activating the mobs arround him
for(var/mob/Monster/M in range(Activated_Range, maker))
if(!M.IS_STARTED)
Start(M)

proc/Start(mob/Monster/M)
if(!M.IS_STARTED)
M.IS_STARTED=1
spawn()
while(M)
if(!M.IS_STARTED)
M.walk_back=1
M.WB()
break
else
var/mob/Player/P = locate(/mob/Player) in orange(Activated_Range, M)
if(!P)
M.IS_STARTED=0
sleep(10)
else
return

mob
Monster
Bunny
Level = 1
name = "Bunny"
Health = 50
MaxHealth=50
Defense=5
EXPGive=15
move_delay=3
is_coward=1
icon = 'Icons.dmi'
icon_state = "Bunny"

Problem description:
Recently I started a new project and I used this same AI system. For some reason on the new project all of my NPCs are frozen until after I attack them and they run away. It's been a few years since I've done any programming. It seems that every single part of this program is working except for the AI Walk. No errors are coming up or anything. I've even attacked to get the npc to move than walked away for it to reset and when it resets it goes back to not moving at all. I've tried editing the frozen variable on the npc code just to try that and it had no effect.
There's a lot of code to go through, but one thing that jumps out at me right away is that Start() is a global proc when it should be a mob proc. The AI belongs to the mob, so it should be a mob proc and never global. (A global loop to manage all the AIs, on the other hand, would be a different story.)