Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 10-08-2011, 04:03 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
PHP Code:
function getDistance(temp.x1temp.y1temp.x2temp.y2) {
  return ((
temp.x1 temp.x2) ^ 2) + ((temp.y1 temp.y2) ^ 2)) ^ 0.5;

__________________
Reply With Quote
  #3  
Old 10-08-2011, 04:21 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
EDIT: Scratch that didn't need to use it.

Ran into another problem. It works great, but its pretty much doing the opposite. I've messed with the math in temp.done but its still not right. The closer I am to the player, the lower the alpha. Which is the opposite and I'm not sure how I can flip it? Also I think the distance needs to be converted to less than 1 (decimals under 1) but i'm stumped!

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
}

function 
onTimeout() {
  for (
temp.plallplayers) {
    if (
pl.level.name == null) continue;
    
//define distance formula
    
temp.= (pl.player.x) ^ 2;
    
temp.= (pl.player.y) ^ 2;
    
temp.= (temp.temp.b) ^ 0.5;
    
    
temp.done temp.c;
    
    
player.chat temp.done;
    
temp.pl.alpha temp.done;
  }
  
setTimer(0.05);

Sorry!

There's got to be an easier way of doing this:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
setTimer(0.05);
  
player.alpha 1;
}

function 
onTimeout() {
  for (
temp.plallplayers) {
    if (
pl.level.name == null) continue;
    
//define distance formula
    
temp.= (pl.player.x) ^ 2;
    
temp.= (pl.player.y) ^ 2;
    
temp.= (temp.temp.b) ^ 0.5;
    
    
temp.done temp.c;
    
    
//player.chat = temp.done;
    
    
if (temp.5) {
      
pl.alpha 1;
    }
    
    if (
temp.&& temp.<= 10) {
      
pl.alpha 0.75;
    }
    
    if (
temp.10 && temp.<= 15) {
      
pl.alpha 0.5;
    }
    
    if (
temp.15 && temp.<= 20) {
      
pl.alpha 0.25;
    }
    
    if (
temp.20) {
      
pl.alpha 0;
    }
  }
  
setTimer(0.05);


Last edited by pig132; 10-08-2011 at 04:39 AM..
Reply With Quote
  #4  
Old 10-08-2011, 04:49 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
something like...

PHP Code:
temp.range 20// 20 tiles away would be 0 alpha
pl.alpha max(0, (temp.range temp.done) / temp.range); 
You should probably also just use players instead of allplayers for this.
__________________
Reply With Quote
  #5  
Old 10-08-2011, 05:07 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Awesome! Thank you that works so much better & smoother.

To use just 'players' would it be:

PHP Code:
for (temp.plplayers
?
Reply With Quote
  #6  
Old 10-08-2011, 05:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by pig132 View Post
Awesome! Thank you that works so much better & smoother.

To use just 'players' would it be:

PHP Code:
for (temp.plplayers
?
Yes.
__________________
Reply With Quote
  #7  
Old 10-08-2011, 06:58 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Okay cool, thank you very much for your help
Reply With Quote
  #8  
Old 10-08-2011, 07:21 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You can also use vectordist() to calculate distance. I.e:

temp.distance = vectordist({player.x, player.y, player.z}, {pl.x, pl.y, pl.z});
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.