AI help in Developer Help
|
|
hello,
DM says the code is fine but the game will not start if i have a (con)my ai on the map otherwise the game runs fine
i think the loop is bad but i tried everything
mob var mob/target proc attackloop(var/mob/M) while(target && target ==M) if(target in oview(src, 1)) attackurst(target) sleep(3) attackurst(var/mob/victim) src<<sound('rifle_fire.wav') if(prob(50)) src<<"You get hit by conscript for 5 damage!" src.hp -= 5 if(usr.hp <= 0) src<<"your dead" else src<<"The conscript has missed you!" getTarget(var/mob/M) if(M != src) target = M spawn() attackloop(M) soviet New() ..() spawn() AILoop() proc AILoop() while(!client) if(!target) getTarget(locate(/mob/player/) in oview(5,src)) else if(target in oview(5,src)) step_towards (src, target) else target = null sleep (3) con icon = 'soviet.dmi' icon_state = "con" hp = 30
|
|
while(!client)if(!target)
getTarget(locate(/mob/player/) in oview(5,src))
There needs to be a sleep somewhere within this branch (in fact, the sleep() you already have should just be moved so it always executes). Otherwise, your AI is just searching for a target as often as it can, which means if it can't find a target, it's going to just lock up the game with this loop.
Your attackurst proc is also messed up. src is the mob attacking. victim is the mob being attacked. usr is completely invalid.