Thread: Distance?
View Single Post
  #1  
Old 10-08-2011, 03:49 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Distance?

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(13232);
  
setTimer(0.05);
}

function 
onTimeout() {
  
temp.np findnearestplayer(this.xthis.y);
  
temp.dx this.player.x;
  
temp.dy this.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);


Last edited by pig132; 10-08-2011 at 03:59 AM..
Reply With Quote