mob
Monster
var/MonAtk=1
var/AttackDelay=10
var/MoveDelay=10
var/tmp/Attacking=0
var/MonsterLastAttackedBy=""
var/MType=""
var/ExpG=0
var/GoldG=0
var/SearchRange=10
New()
..()
if(MonsterAI)
spawn(10)
src.AI_Search()
Slug
icon='Monsters.dmi'
icon_state="Slug"
name="Slug"
MType="Slug"
ElfBlock=1
density=1
HP = 15 //Monsters HP
MHP = 15 //Monsters MHP. Don't want them to be healed without this var! Bug abuse! Derp!
MonAtk=50
MDef=90
GoldG=1
ExpG=5
AttackDelay=30
MoveDelay=8
Monster=1
proc/AI_Search()
set background=1
sleep(2)
for(var/mob/M in ohearers(src.SearchRange))
if(M.client)
src.Attacking=M
return src.AI_Chase()
return AI_Search()
proc/AI_Chase()
set background=1
sleep(2)
for(var/mob/M in ohearers(src.SearchRange))
if(M.client&&src.Attacking==M)
sleep(5)
step_to(src,M)
sleep(src.MoveDelay)
if(get_dist(src,M)<=1)
return src.AI_Attack()
else return src.AI_Search()
return src.AI_Search()
proc/AI_Attack()
set background=1
sleep(2)
for(var/mob/M in ohearers(src.SearchRange))
if(M.client&&src.Attacking==M)
var/Dmg=round(src.MonAtk-(M.MDef/3+rand(0,10)))
if(Dmg>1)
M.HP-=Dmg
view(src)<<"[src] attacks [M] for [Dmg] damage."
else
view(src)<<"[src]'s attack misses [M]."
M.DeathCheckProc(M,src)
sleep(src.AttackDelay)
if(get_dist(src,M)<=1)
return src.AI_Attack()
else return src.AI_Chase()
return src.AI_Chase()
Problem description:
Alright, so when the AI is active and running on the server, it tends to crash after 15 ish minutes.
While the AI is disabled, the server runs fine with minimal CPU usage. While the AI is active, the average server CPU is 4 or so.
I would like to so that it's because it's looping repeatedly. I was told to use Forum Account's region library, however I'd like all AI to be able to run constantly anywhere in the world.
I could perhaps have AI disabled until a player moves into range, however then again the server would crash if a player went AFK in that zone leaving the AI active.
Is anyone able to see why the server would crash? What I could do to improve my basic and sloppy AI? Help is very much appreciated.
Let me define server crash. I mean that Dream Daemon, or seeker if ran via client, crashes and stops responding. It's not like a run time crash, and there are no run times being produced from what I saw.
Thanks again!
I think the problem was the constant for() proc calls.
Other problem could be the sucessive calls to AI_Check(), AI_Chase() and AI_Attack() procs, you could want to define a lopp with while() defining everything inside it, it is your choice anyways.
As you may see, theres no need to call for() in any proc. locate() sends the closest target in ohearers() to Enemy.Attacking.
You would want to make the AI only activate when there are clients, so why not put an initialiser proc, AI_Start() that is activated when a mob steps in Enemy's ohearers() list. There are plenty options I hope you understand what I am trying to tell you.