mob/NPC
Zombie
icon='Zombie.dmi'
Dead=1
var/tmp/Thinking="Wandering"
var/tmp/target
var/tmp/Lastloc
Bump(var/atom/movable/A)
sleep(src.Speed)
flick("attack",src)
if(istype(A,/obj/Corpse))
var/obj/Corpse/C=A
C.Health--
C.Destroy()
New()
Sight=rand(1,8)
Speed=rand(1,8)
ZombieAI()
proc
ZombieAI()
sleep(src.Speed)
if(!target) lookforhuman()
if(!target) lookforbody()
if(target)followtarget()
if(!target) AWander()
spawn() ZombieAI()
AWander()
Thinking="Wandering"
step_rand(src)
spawn(10) AWander()
followtarget()
if(!target)
src.Lastloc=null
return
if(get_dist(src,src.target)<=src.Sight)
if(istype(src.target,/obj/Corpse))
Thinking="Eating"
if(istype(src.target,/mob/NPC))
var/mob/NPC/A=src.target
Thinking="Hunting"
src.followers()
src.Lastloc=A.loc
step_to(src,src.target)
if(get_dist(src,src.target)>src.Sight)
src.Thinking="Searching"
step_to(src,src.Lastloc)
if(get_dist(src,src.Lastloc)<=2)
src.Lastloc=null
src.target=null
followers()
for(var/mob/NPC/Zombie/Z in viewers(src))
if(!Z.target)
Z.acquiretarget(src.target)
lookforbody()
for(var/obj/Corpse/A in oview(src.Sight,src))
src.acquiretarget(A)
break
lookforhuman()
for(var/mob/NPC/A in oview(src.Sight,src))
if(!A.Dead)
src.acquiretarget(A)
break
acquiretarget(mob/NPC/P)
if(!P) return
if(!target)
target=P
Lastloc=P.loc
return
Problem description:
I have been working on this coding for awhile and I have gotten stuck. I need help fixing this coding and making it run smoothly. Basically, When I run my game I get a massive amount of lag. I want to be able to have a large number of these npcs walking around on a map. How should I go about doing that without using up all the CPU? What within my coding is creating all this lag? I appreciate any advice given to me.