ID:1183433
 
Keywords: bump, combat, style, ys
I've been playing the Ys series recently, and started working on an engine. I got it to return a message for damage when you hit an enemy in the back, but I've been trying to get it to where attacking an enemy from the back AND sides makes a difference. I know how to do this the tedious and long way, but I wonder if someone knows an easier way.

I was using this for the back attack thing.
I would probably need quite a few if statements for usr.dir and E.dir detection to include more directions.

Code:
mob
Bump(var/mob/enemies/E)
if(usr.attacklock == 0)
if(usr.dir == E.dir)
usr.attacklock = 1
usr << "damage"
sleep(4)
usr.attacklock = 0
E.Deathcheck()
else
usr.attacklock = 1
usr << "minimal damage"
sleep(4)
usr.attacklock = 0
usr.Deathcheck()


Problem description: Need help making a condensed version of a direction detection bump combat. Whether the enemy is being bumped head-on, from the side or from the back.

Thanks in advance!
So Basically you want it if you run into a player/mob/etc you Bump them?
Bump isn't necessarily the best place to be using usr, since it's self-referential.

Also, your assumption that the blockage is going to be an enemy is unsafe.

mob
Bump(var/atom/O)
if(istype(O,/mob/enemies))
src.attack(O)
. = ..(O)
return .

proc
attack(var/mob/enemies/E)
if(E.dir==src.dir)
src << "backstab"
else
src << "damage"
src.attacklock = 1
sleep(4)
src.attacklock = 0
E.DeathCheck()


Remember, Bump() is called on the mob that did the bumping, so calling usr in this case should be src.

Second, I noticed you are calling usr.Deathcheck() when attacking from the side or front, meaning you are never going to actually be able to kill your mobs.

Last, you'll notice I took the liberty of condensing your repeated code, since in this case, both front and side attacks call several of the same functions.

I'm going to assume that you are preventing movement via attacklock, so I'm not going to safety-check whether that's on when calling Bump.

If you have any more questions, let me know.
Sorry for the late reply, I've been visiting the library to post. Thank you, I always got confused when using Bump(). Now, it makes more sense. And thanks for condensing it too. It helps to see it in action.
The easiest way to find out what direction the atom is being hit by is this:
mob/verb/Attack()//Example Attack
var/dmg=Str*0.5//Ex of normal Dmg
dmg+=DirDmg()//Adds the extra dmg of the dir you hit
//...

mob/proc/DirDmg() //Proc to determine which side is hit and how much dmg is dealt
var/DirHit=get_dir(src,E)//This will always come up with the right dir where its hit
var/dmg=10
switch(DirHit)
if(SOUTH) dmg*=2
if(EAST||WEST) dmg+=5
return dmg//Return the calculated dmg to the attack for the dir bonus


There is a small example I made of what would probably be the easiest way to calculate extra damage by determining the direction the mob is hit at. Hope this helps