Okay i'm going to start working on something and it requires a distance formula between a player and another player(or npc). When I mess around with one distances come up as negatives sometimes depending where the player is. I have ran into one a few times a while back but I can't seem to find it.
Any help would be appreciated, thank you
EDIT: I did a quick mockup of what my end goal is to be (with players only. npc was just to test)
Pretty much the further a player is from another player the less alpha the player has. I just have no idea how I could accomplish this. GANIs? Add a weapon to everyone that has it?
PHP Code:
//#CLIENTSIDE
function onCreated() {
setshape(1, 32, 32);
setTimer(0.05);
}
function onTimeout() {
temp.np = findnearestplayer(this.x, this.y);
temp.dx = this.x - player.x;
temp.dy = this.y - player.y;
this.chat = temp.np @ ": " @ temp.dx @ "," @ temp.dy;
if (temp.dx && temp.dy <= 3) {
this.alpha = 1;
}
if (temp.dx && temp.dy > 3) {
if (temp.dx && temp.dy <= 6) {
this.alpha = 0.75;
}
}
if (temp.dx && temp.dy > 6) {
if (temp.dx && temp.dy <= 9) {
this.alpha = 0.5;
}
}
if (temp.dx && temp.dy > 9) {
if (temp.dx && temp.dy <= 12) {
this.alpha = 0.25;
}
}
if (temp.dx && temp.dy > 12) {
if (temp.dx && temp.dy <= 15) {
this.alpha = 0;
}
}
setTimer(0.05);
}