mob/npc
proc
AI()
set background=1
var/allset=0
for(var/mob/D in world)
if(D.z==src.z)
if(D.client)
var/ax=src.x-25
var/dx=src.x+25
var/ay=src.y-25
var/dy=src.y+25
if(D.x>=ax&&D.x<=dx&&D.y>=ay&&D.y<=dy)
allset=1
if(D in oview(src))
allset=2
if(allset)
for(var/mob/m in oview(16,src))
if(m.missiontarget==src&&m.mission==src)
walk_away(src,m,8,m.rundelay+1)
if(m.missiontarget==src&&m.mission==4)
if(src.follow==m)
src.Approach(m)
if(!src.combat2)
src.combat2=pick("Rock","Paper","Scissors")
var/didsomething=0
if(allset==2)
if(!src.aggrod)
var/d=rand(1,100)
if(d==1)
var/t=rand(1,42)
src.Speech(t)
if(src.wander)
step_rand(src)
didsomething=1
sleep(rand(20,40))
if(src.hostile&&allset==2)
src.npcHostile()
didsomething=1
if(!didsomething)
sleep(rand(40,60))
if(src.health>0)
spawn()src.AI()
else
sleep(rand(140,160))
if(!src.dead)
spawn()src.AI()
Problem description:
This has been causing lag(I think). It takes up most CPU and has been using more realtime than possible. Within 13 minutes it has an 8 digit number as real time. BTW all enemies call AI proc on New(). Is there a more efficient way to code that.(would a world proc help?)
You would want to only activate that AI() proc when a client is within view, otherwise you are just wasting resources without any logical reason.
If you had only a few of those mobs it wouldn't probably be such a big deal, while in the other hand, with quite a few mobs it will get more and more intense.