ID:142967
 
Code:
mob/Monster/butterfly
icon = 'hellbutterfly.dmi'
icon_state = ""
health = 25
atk = 7
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
var/Found = 0
for(client in oview(5,src))
step_towards(src,client)
Found = 1
break
if(Found != 1)
step_rand(src)
sleep(10)
sleep(5)
Bump(mob/M)
if(istype(client))
Attack(client)
proc/Attack(mob/M)
flick("attack",src)
sleep(2)
var/damage = rand(1,atk)
M.health -= damage
view(src) << "[src] attacks [M]!"
view(src) << "[damage] damage!"


Problem description:

So I took this from a library thing I found and it didn't quite work so I started tweaking it a bit and apparently I jacked up the code. Problem is, I'm not quite sure where I screwed it up. It's probably where I replaced his "player" variable with "client", but the player thing wasn't working. Anyway, here's the original code, which works on his game but not mine >_>

mob/var
Found = FALSE
//now its time to make monsters :(....
mob/Monster/Goblin
icon = 'Monsters.dmi'
icon_state = ""
HP = 25
Power = 7// its power
expplus = 7//ow much exp it gives
var/mob/player/P // it is way easyer it type P then to type mob/player all the time :)
New()
. = ..()
spawn()//starts to do the next command
Wander()
proc/Wander()
while(src)//makes sure it is doing it
var/Found = FALSE// flase is the same as 0 and ture means 1, just did diferent for a while XD
for(P in oview(5,src))//if the player is within 5 steps.
step_towards(src,P)//steps towards the player
Found = TRUE
break // makes it so it wont just leave the person it is chasing and go after something else
if(Found != TRUE)
step_rand(src)//steps randomly for a while
sleep(10)
sleep(5)
Bump(mob/M)
if(istype(M,/mob/player))
Attack(M)
proc/Attack(mob/M)
flick("attack",src)//shows the mnster attacking. OPTION :)
sleep(2)
var/damage = rand(1,Power)
M.HP -= damage
view(src) << "[src] attacks [M]!"//tell people who and what got attacked
view(src) << "[damage] damage!"// says how much damage
M.Death()

world
mob = /mob/player


I'm such a failure at AI -_-
It is most definitely your use of client that screwed things up, since it's really not used in the right way, nor is client what you're looking for in that situation. First things first, I want to help you get this clean and efficient, so whatever you do, don't copy and paste your wander/bump/attack for every single mob, make a monster subtype and go from there. Something like this is much more suitable:
mob/Monster
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
var/Found = 0
for(var/mob/M in oview(5,src)) //Looks for mobs in view
if(!M.client) continue //If the mob has no client, it's not a player, so skip it
step_towards(src,M)
Found = 1
break
if(!Found)
step_rand(src)
sleep(10)
sleep(5)
Bump(mob/M)
if(ismob(M)&&M.client)//Make sure it bumped a mob with a client, meaning a player
Attack(M)
proc/Attack(mob/M)
flick("attack",src)
sleep(2)
var/damage = rand(1,atk)
M.health -= damage
view(src) << "[src] attacks [M]!"
view(src) << "[damage] damage!"
//Enemies go below here
butterfly
icon = 'hellbutterfly.dmi'
icon_state = ""
health = 25
atk = 7
example_monster
icon = 'Example.dmi'
icon_state="example"
health = 1
atk = 1


This way, all you need to do to add enemies is set their icon, icon state, health, and attack, instead of re-doing the AI procs for every single monster.
In response to Detnom
Ah! I see. Yes, this is much simpler ^_^. I actually understand how this works.

Thank you ^_^
In response to Detnom
I don't get why all these crappy AI procs decide to use a for() loop.

Actually, no. I don't get why Kunark decided to use a for() loop. I get why everybody copied him.

What you can do is this:

while(src)
//find a /mob/player in oview(src,5) and assign it to target
var/mob/player/target = locate() in oview(src,5)
//if we found a target
if(target)
step_towards(src,target)
else
step_rand(src)
sleep(10)