ID:173747
 
Basically, Im developing a paintball game for byond while I cant use my laptop, what Im trying to do is when you click a person to shoot at them,I want the game to check where the person your shooting at is and if your facing them, i.e. Say Im looking north, I want to fire at a person northwest in my view and Im facing north, I would click them and a paintball would fire at them, now in another example, Im facing south-east and the person I want to attack is again, northwest, when I click them it wouldnt fire because you couldnt actually see that person, so therefore you can not hit them. Unfortunatly, I really have no idea where to begin in even coding this and was wondering if anyone could show me where to start or even code this.
Thanks in advance to those who help.


~ZeroCrash~
ZeroCrash wrote:
Basically, Im developing a paintball game for byond while I cant use my laptop, what Im trying to do is when you click a person to shoot at them,I want the game to check where the person your shooting at is and if your facing them, i.e. Say Im looking north, I want to fire at a person northwest in my view and Im facing north, I would click them and a paintball would fire at them, now in another example, Im facing south-east and the person I want to attack is again, northwest, when I click them it wouldnt fire because you couldnt actually see that person, so therefore you can not hit them. Unfortunatly, I really have no idea where to begin in even coding this and was wondering if anyone could show me where to start or even code this.
Thanks in advance to those who help.


~ZeroCrash~

Sure! This is pretty simple, you just have to know what procedures to use.

mob/Click()
if(get_dir(usr,src)==usr.dir) usr.Shoot(src)


That should do it.

~>Volte
In response to Volte
Thanks so much, that works wonderfully, I have only one question, isn there a way it could work like such:

A = a player northwest of you.
C = a player northwest of you.
T = a player north of you.
O = a player northeast of you.
X = a player southwest of you. Can't shoot player X because hes not seen in front of you.

And of coarse ^ = you as the player facing north.

What I want the process to instead of being able to only shoot a player infront of you like player T. You should be able to shoot players, C, O, T, and player A. I tried messing with the bit of code you showed to get the game to do this but my atempts were unsuccessful.



Edit: There was a map but it didn't turn out correctly.

~ZeroCrash~
In response to Volte
Volte wrote:
mob/Click()
if(get_dir(usr,src)==usr.dir) usr.Shoot(src)

Problem: Facing north, you couldn't hit anyone northwest.

Assuming a nearly 180-degree field of vision, I'd try this:
mob/Click()
var/d = get_dir(usr, src)
// facing diagonal
if(dir & dir-1)
// do nothing if not facing sort of that way
if(!(d & dir)) return
// if facing that general direction, fire
if(d == dir) return usr.Shoot(src)
// if target is directly north/south or east/west in shooter's
// facing direction, fire
if(!(d & d-1)) return usr.Shoot(src)
// more than 45 degrees off; don't allow 90 or more
var/ax = abs(x - usr.x)
var/ay = abs(y - usr.y)
if(ax == ay) // exact diagonal 90 degrees left or right
return
if((d & dir) & (ax > ay ? 12 : 3)) return usr.Shoot(src)
// facing north/south/east/west
else
if(d & dir) return usr.Shoot(src)
I think that should do the trick.

Lummox JR