ID:2222499
 
(See the best response by Kaiochao.)
Code:
atom/Click(atom/o)
usr.dir = o.dir
o = src
if(o.z != 0)
if(o!=null && o != usr.loc)
usr.attack()


Problem description:
I'm trying to make player turn into the mouse direction(like north,northeast,...) but the mob only turns to south,theres a way to do that?
Theres a way to player always turn into mouse direction then controlling the mouse on game screen?
Your problem is that o might not be facing the direction between src and o -- you want get_dir.

atom/Click(atom/o)
var/mob/m = usr // define usr as a typecasted mob because I don't know the type path of your clients
m.dir = get_dir(m,o) // get the direction from m to o and assign it to m's dir
if(o.z) // this is the same as != 0
if(!isnull(o) && o != m.loc) // !isnull() is the same as != null. I don't know why exactly you're checking that o is not m's loc, but I guess it's a roundabout way of seeing if it's a turf? I feel like there is a better way to handle this
m.attack()


Also, never, ever use usr for any reason, ever. Typecast instead.
Actually,
if(o.z != 0)

would be:
if(o.z)


Not really sure whats going on with that check, but there you go.
Thanks for the help everyone,I understand it now!

the if(!o.z) is for prevent people clicking on the black space of map(like im in 1,1,1 and want to click one click left)
In response to Flick
You're right, my mistake.
In response to Ataos
Best response
That black space isn't actually clickable, so that's not exactly the issue.

The first argument to Click() isn't always an atom, so you should make sure it is in the body of the proc, like so:
atom
Click(location, control, params)
if(isturf(location))
usr.dir = get_dir(usr, location)
usr.attack()

It's important that you validate the type (if you don't already know what the type is) BEFORE you treat it as that type.

Also, it might help to use a "get direction" proc that's a bit more intuitive:
http://www.byond.com/forum/?post=195151
(full explanation here: http://www.byond.com/forum/?post=195152 )
Basically, get_dir() returns a diagonal if the objects are not perfectly aligned horizontally or vertically. This "general direction" proc returns the actual "closest" direction instead.
In response to Kaiochao
Wow that's advanced and simple,thanks everyone.