ID:157470
 
How would I go about checking if there is a mob within 1 space away from my direction or in the same exact place as me. I would like to know how to do this so that I can create many attacks in this way. Thanks for any help! Oh, here is a start of what I was thinking about doing, but I'm not sure if it was the best way to go about it or if it is going to work.

mob
verb
punch()
if(src.dir == NORTH)
if(usr in src.loc + (src.y + 1))
usr.HP--

mob/var/HP = 10
var/mob/m = locate()in view(1,src)
if(m) src << "[m] is nearby!"
else src << "No target found!"
In response to Kaiochao
so...is this good?
var/mob/m = locate(src.x, src.y + 1, src.z)in view(1,src)
if(m) src << "[m] is nearby!"
else src << "No target found!"
In response to Darkjohn66
No.
var/mob/m = locate()in oview(1, get_step(src,dir))
if(m) src << "[m] is nearby!"
else src << "No target found!"
Darkjohn66 wrote:
How would I go about checking if there is a mob within 1 space away from my direction or in the same exact place as me. I would like to know how to do this so that I can create many attacks in this way. Thanks for any help! Oh, here is a start of what I was thinking about doing, but I'm not sure if it was the best way to go about it or if it is going to work.

That you second-guessed this method was definitely a good instinct. There is a better way. The turf 1 space away in your current direction is get_step(src,src.dir).

mob/verb/punch()
var/mob/M
// check usr.loc first
for(M in usr.loc)
if(M != usr) break
// check in front of usr
if(!M)
for(M in get_step(usr,usr.dir))
if(M != usr) break
// anything found?
if(M)
M.TakeDamage(usr,1)


Lummox JR
In response to Lummox JR
cool, I am going to test this out right now.

client
Click(mob/M)
if(istype(M))
usr<<"[src]'s HP = [usr.HP]. [M]'s HP = [M.HP]"
mob/verb/punch()
var/mob/M
// check usr.loc first
for(M in usr.loc)
if(M != usr) break
// check in front of usr
if(!M)
for(M in get_step(usr,usr.dir))
if(M != usr) break
// anything found?
if(M)
M.HP--//(usr,1)

mob/var/HP = 100



The next thing I am going to try out is checking if I can have a limited randomization with coordinate change on an object bumping a mob