ID:264104
 
Code:
mob/monster
Kamek
icon = 'Kamek.dmi'
hp = 1000
maxhp = 1000
npc = 1
flying = 1
New()
. = ..()
spawn()
Wander()
proc/Wander()
while(src)
step_rand(src)
var/mob/P = locate() in oview(10)
if(P)
if(P.npc == 0)
if(src.dir == WEST||src.dir == NORTH||src.dir == SOUTH)
var/obj/Attack/O = new/obj/Attack(src.x+2,src.y,src.z)
src.icon_state = "magic"
walk(O,P)
sleep(20)
P.hp -= 10
P << "You were hit by Kamek's magic."
src.icon_state = ""
del(O)

if(src.dir == EAST||src.dir == NORTH||src.dir == SOUTH)
var/obj/Attack/O = new/obj/Attack(src.x-2,src.y,src.z)
src.icon_state = "magic"
walk(O,P)
sleep(20)
P.hp -= 10
P << "You were hit by Kamek's magic."
src.icon_state = ""
del(O)

Bump(mob/M)
if(ismob(M))
if(M.npc == 0)
Fight(M)
..()

else
return
proc/Fight(var/mob/M)
var/damage = 10

if(M.hp <= 0)
M.hp -= damage
M << "<font color = white><font face = 'Comic Sans MS'>[src] attacks you for [damage] damage!!"
src<<"<font color = white><font face = 'Comic Sans MS'>You attack [M] for [damage] damage!!"
Death(M)
if(M.hp >= 0)
M.hp -= damage
M << "<font color = white><font face = 'Comic Sans MS'>[src] attacks you for [damage] damage!!"
src<<"<font color = white><font face = 'Comic Sans MS'>You attack [M] for [damage] damage!!"
Death(M)


Problem description:Well, what I'm trying to do is make it so Kamek(the monsters name) wanders around the area and if someone is near her she uses a magic attack by first changing her icon state to magic then shooting the magic. I tried for a long time and couldn't get it working how I wanted it. Any help?

Alright, there is a lot wrong with that code; far more than just your code problem. I'll fix a few things and explain to you what I've done.
mob/monster/Kamek
New()
//New() doesn't have any default return values. I'll
//leave this in on the chance that you've altered it
//somewhere in the parent types, but you can remove
//it if you haven't.
. = ..()

spawn() Wander()

proc/Wander()
while(1)
step_rand(src)

//First problem here: You're not sleep()ing.
//This will be an infinite loop if you don't
//sleep at all.
sleep(rand(5, 10)) //Arbitrary random values.
//Change them if you want.

//Second problem: "No put usr in proc. Ungh". By
//default, oview() has usr as the ref, which is
//bad.
var/mob/m = locate() in oview(src, 10)

//These can all be combined into one if
//statement, but that would leave a decent
//amount of redundancy. This can be changed.

//Note: Don't do if(x == 0) or if(x == 1) unless
//you're checking for a specific value.
//Otherwise, do if(!x) or if(x), which check to
//see if x is false or true, respectively. False
//value are 0, null, and "". True is everything
//else.
if(m && !m.npc)
var
//These two variables will be used to
//get the x and y offsets for the attack.
x_change
y_change

if(dir & EAST)
//If the direction has an east
//component (meaning it's NORTHEAST,
//EAST, or SOUTHEAST), set x_change to
//2.
x_change = 2

else if(dir & WEST)
//If the direction has an west
//component (meaning it's NORTHWEST,
//WEST, or SOUTHWEST), set x_change to
//-2.

if(dir & NORTH)
//If the direction has an north
//component (meaning it's NORTHEAST,
//NORTH, or NORTHWEST), set y_change to
//2.
y_change = 2

else if(dir & SOUTH)
//If the direction has an south
//component (meaning it's SOUTHEAST,
//SOUTH, or SOUTHWEST), set y_change to
//2.
y_change = -2

//Create the attack using the offsets we
//just got.
var/obj/attack/a = new(x + x_change, y + y_change, z)

icon_state = "magic"
//You want to use walk_to() here, not
//walk().
walk_to(a, m)
sleep(20)
m.hp -= 10

m << "You were hit by [src]'\s attack."

icon_state = ""
del a

Bump(mob/m)
//Once again, your if statements can be made into a
//single statement.
if(istype(m) && !m.npc)
Fight(m)

//I don't see any reason this can't return as
//normal, regardless of other situations.
return ..()

proc/Fight(mob/m) //The "var" prefix doesn't need to be
//used for arguments.

var/damage = 10

//Your if statements do the same thing for every
//possible real number, so they're useless. Both
//will also always be called.

m.hp -= damage
//Never put spaces betwen the attribute and the
//value for HTML, as it's bad practice. Close all
//tags, too. Another thing: you probably have this
//setup such that when the other mob bumps src,
//that mob will also damage src. This means only
//one message should be sent, or there will be
//multiple, redundant messages.
m << "<font color=white face='Comic Sans MS'>[src] attacks you for [damage] damage!</font>"

//A death check should only be called when src has
//a chance of dying. Before you use this proc, make
//sure that's the situation for this call.
Death(m)

Make this fixes, and then reply as to whether anything was helped. We can go from there.
In response to Popisfizzy
had a few easy to fix errors but after fixing them up I compiled(0 errors) and when I'm playing and enter the stage that Kamek is on it says m << "You were hit by Kamek'\s attack." but she's invisible..
In response to Popisfizzy
You can change this whole thing:
                var
//These two variables will be used to
//get the x and y offsets for the attack.
x_change
y_change

if(dir & EAST)
//If the direction has an east
//component (meaning it's NORTHEAST,
//EAST, or SOUTHEAST), set x_change to
//2.
x_change = 2

else if(dir & WEST)
//If the direction has an west
//component (meaning it's NORTHWEST,
//WEST, or SOUTHWEST), set x_change to
//-2.

if(dir & NORTH)
//If the direction has an north
//component (meaning it's NORTHEAST,
//NORTH, or NORTHWEST), set y_change to
//2.
y_change = 2

else if(dir & SOUTH)
//If the direction has an south
//component (meaning it's SOUTHEAST,
//SOUTH, or SOUTHWEST), set y_change to
//2.
y_change = -2

//Create the attack using the offsets we
//just got.
var/obj/attack/a = new(x + x_change, y + y_change, z)


to:
                var/obj/attack/a = new(get_step(get_step(src,src.dir),src.dir))


since it's just 2 steps away.
In response to Element Hero creator
Then she needs to be changed to the proper icon state.