ID:174460
 
How would I make it so you have to be facing the monster to attack it? Here is my orgial combat code:

mob/verb/Attack(mob/M in oview(1))
if(usr.sword == "no")
return
else
flick("attack",usr)
if(M)
var/damage = str
damage -= M.def
if(damage <= 0)
return
else
M.hearts -= damage
M.DEATH()
return
Shades wrote:
How would I make it so you have to be facing the monster to attack it?

Here's how I'd do it:
mob/verb/Attack(mob/M in oview(1))
if(usr.sword == "no")
return
else
if(getdir(M,src)==src.dir)
flick("attack",usr)
var/damage = str
damage -= M.def
if(damage <= 0)
return
else
M.hearts -= damage
M.DEATH()
return

Hope that helps, Cadence.
Try using the mob's built in dir variable. The dir (direction) variable can be quite useful as it can define the users direction.

--Make sure to use Directional Words and not "Up" and "Down".
In response to Cadence
Byond has informed me that getdir is a undefined proc
In response to Shades
I tried to alter the code a bit, but it wont work, no erros, but it just wont work.:

mob/verb/Attack(mob/M in oview(1))
if(usr.sword == "no")
return
else
if(get_dir(src,usr)==M.dir)
flick("attack",usr)
var/damage = str
damage -= M.def
if(damage <= 0)
return
else
M.hearts -= damage
M.DEATH()
return

mob/verb/Attack(mob/M in get_step(usr,usr.dir))
if(usr.sword == "no")
return
else
flick("attack",usr)
if(M)
var/damage = str
damage -= M.def
if(damage <= 0)
return
else
M.hearts -= damage
M.DEATH()
return
In response to Shades
Shades wrote:
I tried to alter the code a bit, but it wont work, no erros, but it just wont work.:

if(get_dir(src,usr)==M.dir)
I don't know where you got usr from

change that to if(get_dir(M,src)==src.dir) and it should work, it works for me in the exact same situation.

Cadence
In response to Cadence
Sorry Can your code just will not work for me.
In response to Shades
Kashell's code does though, good job, thanks guys!