Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Question (https://forums.graalonline.com/forums/showthread.php?t=134262968)

MysticalDragon 04-24-2011 11:04 PM

Question
 
temp.pIds = getnearestplayers(this.x, this.y, player.hp > 0);

does getnearestplayers grab a players community name as well. Because it seems like every time a Graal##### account enters the level they stop working, like there confused?

fowlplay4 04-24-2011 11:15 PM

Use findnearestplayers instead.

PHP Code:

// Loops through list of players by distance (closest first)
for (temp.plfindnearestplayers(this.xthis.y)) {
  echo(
temp.pl.account);



MysticalDragon 04-24-2011 11:36 PM

ahh thank you it worked.

MysticalDragon 04-25-2011 12:11 AM

2 Attachment(s)
Well I thought it worked lol. It works better then before, now it grabs the player that's the furthest from the NPC.

Snapshots are attached

cbk1994 04-25-2011 02:04 AM

Quote:

Originally Posted by MysticalDragon (Post 1645358)
Well I thought it worked lol. It works better then before, now it grabs the player that's the furthest from the NPC.

Snapshots are attached

Post your code.

MysticalDragon 04-25-2011 07:41 AM

Quote:

function getTarget() {
temp.bestTarget = null;
temp.bestValue = 0;

for (temp.pl: findnearestplayers(this.x, this.y)) {
temp.pIds = temp.pl.account;
}
//temp.pIds = getnearestplayers(this.x, this.y, player.hp > 0);

for (temp.pId: pIds) {
temp.pl = players[pId];

temp.dx = pl.x - this.x;
temp.dy = pl.y - this.y;
//temp.distance = abs(dx) + abs(dy); // manhattan distance
temp.distance = (dx * dx + dy * dy) ^ 0.5; // Euclidean distance
//pl.chat = distance @ " " @ dx @ " " @ dy;
// Ensure the following are true:
// within maximum distance, in front of us, and not behind a wall

if (distance > this.maxdist) {
continue;
}
Here is the part of the code im having issues with.

cbk1994 04-25-2011 08:15 AM

Use PHP tags for code.

PHP Code:

function getTarget() {
  
temp.bestTarget null;
  
temp.bestValue 0;

  for (
temp.plfindnearestplayers(this.xthis.y)) {
    
temp.pIds temp.pl.account;
  }
  
//temp.pIds = getnearestplayers(this.x, this.y, player.hp > 0);

  
for (temp.pIdpIds) {
    
temp.pl players[pId];

    
temp.dx pl.this.x;
    
temp.dy pl.this.y;
    
//temp.distance = abs(dx) + abs(dy); // manhattan distance
    
temp.distance = (dx dx dy dy) ^ 0.5// Euclidean distance
    //pl.chat = distance @ " " @ dx @ " " @ dy;
    // Ensure the following are true: 
    // within maximum distance, in front of us, and not behind a wall

    
if (distance this.maxdist) {
      continue;
    } 

findAreaPlayers returns an array of players, therefore you want to do this in order to loop through them:

PHP Code:

function getTarget() {
  
temp.bestTarget null;
  
temp.bestValue 0;

  for (
temp.plfindnearestplayers(this.xthis.y)) {
    
temp.dx pl.this.x;
    
temp.dy pl.this.y;
    
    
//temp.distance = abs(dx) + abs(dy); // manhattan distance
    
temp.distance = (dx dx dy dy) ^ 0.5// Euclidean distance
    //pl.chat = distance @ " " @ dx @ " " @ dy;
    // Ensure the following are true: 
    // within maximum distance, in front of us, and not behind a wall

    
if (distance this.maxdist) {
      continue;
    } 

Not sure if you're using this in a player class or a monster or so, but if it's not working make sure you meant to use this.x and this.y.

MysticalDragon 04-25-2011 08:39 AM

Thank you so much Jerret and Chris it works like a charm.
REP + REP but unfortunately I can only do 1 every 24 hours. :(


All times are GMT +2. The time now is 07:02 AM.

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