Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Finding players in Z range (https://forums.graalonline.com/forums/showthread.php?t=134269256)

i8bit 05-30-2014 06:20 PM

Finding players in Z range
 
PHP Code:

  triggeraction(player.x + 1.5 + vecx(player.dir) * 1.5, player.y + 2 + vecy(player.dir) * 1.5, "Lighthurt", player.dmg); 

How do I also do a check to make sure the player in front is within a certain z-range?

Emera 05-30-2014 07:35 PM

You can use vectorDist()

PHP Code:

vectorDist(
  {
player.x, player.y, player.y},
  {
obj.x, obj.y, obj.z}
); 

Checks the distance from one object to another based on the x, y and z properties of both objects. Failing that, you can use a distance formula (search the forums).

callimuc 05-30-2014 07:50 PM

Quote:

Originally Posted by Emera (Post 1727597)
[...]

I'm sure he ment how to find players within a certain range, not how to get the range. You could do that the following way using findNearestPlayers():

PHP Code:

function attackPlayers(from_x, from_y, distance_max) {
  for (
temp.pl: findNearestPlayers(temp.from_x, temp.from_y) {
    
temp.dx = temp.pl.x - temp.from_x;
    
temp.dy = temp.pl.y - temp.from_y;
    
    
temp.distance = (dx^2 + dy^2) ^ 0.5; //calculate distance
    
echo("Distance to " @ temp.pl.account @ ": " @ temp.distance);

    if (
temp.distance > temp.distance_max) continue; //ignore players that are further away than you want them to be
    //do stuff to the players within the given range
  
}
} 


i8bit 05-30-2014 08:17 PM

Quote:

Originally Posted by callimuc (Post 1727598)
I'm sure he ment how to find players within a certain range, not how to get the range. You could do that the following way using findNearestPlayers():

PHP Code:

function attackPlayers(from_x, from_y, distance_max) {
  for (
temp.pl: findNearestPlayers(temp.from_x, temp.from_y) {
    
temp.dx = temp.pl.x - temp.from_x;
    
temp.dy = temp.pl.y - temp.from_y;
    
    
temp.distance = (dx^2 + dy^2) ^ 0.5; //calculate distance
    
echo("Distance to " @ temp.pl.account @ ": " @ temp.distance);

    if (
temp.distance > temp.distance_max) continue; //ignore players that are further away than you want them to be
    //do stuff to the players within the given range
  
}
} 



I may be doing it wrong.. but the way I did it seems so much simpler...

in the action-
PHP Code:

  triggeraction(player.x + 1.5 + vecx(player.dir) * 4, player.y + 2 + vecy(player.dir) * 4, "Lighthurt", player.dmg, player.z+3, player.z-3); 

in the hurt function-
PHP Code:

if (player.z < params[1]){
if (
player.z > params[2]){ 


callimuc 05-30-2014 10:33 PM

Ah I now get it. You'd need to make a player class (like a health class) to check what the players z value is (inside the onActionLighthurt()) and control any further stuff from there on.

PHP Code:

function onActionLighthurt() {
  if (
player.z in |-3, 3|) { //players Z value goes from -3 to 3
    //same as if (player.z >= -3 && player.z <= 3)
    //Do your stuff inside here
    
player.chat = "'eyy";
  }
} 

for the triggerAction() you'd only need to do triggeraction(player.x + 1.5 + vecx(player.dir) * 4, player.y + 2 + vecy(player.dir) * 4, "Lighthurt", player.dmg); now

i8bit 05-31-2014 12:35 AM

Quote:

Originally Posted by callimuc (Post 1727600)
Ah I now get it. You'd need to make a player class (like a health class) to check what the players z value is (inside the onActionLighthurt()) and control any further stuff from there on.

PHP Code:

function onActionLighthurt() {
  if (
player.z in |-3, 3|) { //players Z value goes from -3 to 3
    //same as if (player.z >= -3 && player.z <= 3)
    //Do your stuff inside here
    
player.chat = "'eyy";
  }
} 

for the triggerAction() you'd only need to do triggeraction(player.x + 1.5 + vecx(player.dir) * 4, player.y + 2 + vecy(player.dir) * 4, "Lighthurt", player.dmg); now

Thanks for input!

I have a little side question though. How do I change the player's location on the screen?

For example, if I want the player a little further down the screen instead of centered?
Is this possible?

BlueMelon 05-31-2014 02:52 PM

Quote:

Originally Posted by i8bit (Post 1727601)
For example, if I want the player a little further down the screen instead of centered?
Is this possible?

Take a look at:
resetfocus();
and
setfocus(x, y);


All times are GMT +2. The time now is 01:20 PM.

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