ID:139936
 
Code:
        New()
..()
for(var/mobs in view(src))
if(istype(mobs,/mob)&&icon!='zombie.dmi')
walk_towards(src,mobs,1)
if(mobs in range(1))
mobs:health-=5
if(mobs:health<=0)
mobs:loc=locate(/area/playerStart,/area/playerStart,/area/playerStart)
mobs << "You've been killed."
else
mobs << "You've been injured!"
else
walk_rand(src,12)


Problem description:
THe problem is I can't seem to get them to do anything. When they spawn, they don't even walk in a random direction.
That only runs once, for each mob in view when it is created
Use spaces to make your code more readable, and then stop using ":" completely.
In response to Falacy
Ah thanks, how do I get it to do it continually then?
In response to CodeWeasel22
Can't anyone help?
In response to CodeWeasel22
You infinitely loop it with either "for()" (like that) or using while(1) (or src, etc.)

Don't forget to put a sleep() in there to halt the procedure otherwise you will have the loop using all of your computer's resources.
In response to GhostAnime
I think I'm beginning to understand, but I'm still going to need help, please add me to pager, and can I talk to you about this tomorrow?
In response to CodeWeasel22
        New()
..()
for(var/mobs in view(src))
while(src)
sleep 1
//tab everything below this once.
if(istype(mobs,/mob)&&icon!='zombie.dmi')
walk_towards(src,mobs,1)
if(mobs in range(1))
mobs:health-=5
if(mobs:health<=0)
mobs:loc=locate(/area/playerStart,/area/playerStart,/area/playerStart)
mobs << "You've been killed."
else
mobs << "You've been injured!"
else
walk_rand(src,12)
In response to Boygm8
No. Like this:

mob/whatever
New()
spawn() AI()
proc/AI()
while(src)
var/mob/target
for(target in oview(src))
// Acquire any target which has a key (is a player)
if(M.key) break
// Once we've found a target, keep on chasing them
if(target)
while(get_dist(src, target) < 8)
// Attack them if we're in range
if(get_dist(src, target) < 1)
src.attack(target)
// Move closer otherwise
else
step_towards(src,target)
// Delay between actions:
sleep(5)
// If we can't find a target, wander randomly
else
step_rand(src)
sleep(5)
In response to Garthor
Wow, that's very nice of you all, thank you.
In response to Garthor
Garthor wrote:
No. Like this:

mob/whatever
> New()
> spawn() AI()
> proc/AI()
> while(src)
> var/mob/target
> for(target in oview(src))
> // Acquire any target which has a key (is a player)
> if(M.key) break
> // Once we've found a target, keep on chasing them
> if(target)
> while(get_dist(src, target) < 8)
> // Attack them if we're in range
> if(get_dist(src, target) < 1)
> src.attack(target)
> // Move closer otherwise
> else
> step_towards(src,target)
> // Delay between actions:
> sleep(5)
> // If we can't find a target, wander randomly
> else
> step_rand(src)
> sleep(5)


Actually I tried that, didn't work. Please try again? Thanks for the help though.
In response to CodeWeasel22
It's your job to adapt what I wrote for your game, not mine.
I wrote a tutorial on enemy AI, you might find it useful: http://www.byond.com/developer/Forum_account/EnemyAI