Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   findNearestPlayers(x, y) (https://forums.graalonline.com/forums/showthread.php?t=134262343)

cbk1994 03-07-2011 02:05 AM

findNearestPlayers(x, y)
 
Serverside, in a DB NPC,

PHP Code:

this.level.findNearestPlayers(3232);
this.findNearestPlayers(3232);
findNearestPlayers(3232); 

Only the last one works. What object is findNearestPlayers a method of?

WhiteDragon 03-07-2011 02:15 AM

It could just be a global function.

cbk1994 03-07-2011 02:33 AM

Quote:

Originally Posted by WhiteDragon (Post 1635002)
It could just be a global function.

If so, it should be moved to TServerLevel so that it can be used in conjunction with findLevel.

fowlplay4 03-07-2011 02:53 AM

It'd be cool if we could do something like..

PHP Code:

function onCreated() {
  
TServerPlayer.test = function () {
    echo(
this.account);
  };
  for (
aallplayersa.test(); // Result: RC Spammed with Accounts


I guess the above doesn't really apply here but being able to extend functionality of a built-in Graal class/object without joining a class would be cool.

cbk1994 03-07-2011 02:59 AM

Quote:

Originally Posted by fowlplay4 (Post 1635008)
It'd be cool if we could do something like..

PHP Code:

function onCreated() {
  
TServerPlayer.test = function () {
    echo(
this.account);
  };
  for (
aallplayersa.test(); // Result: RC Spammed with Accounts


I guess the above doesn't really apply here but being able to extend functionality of a built-in Graal class/object without joining a class would be cool.

Adding methods to default objects would indeed be great. In JavaScript, you can edit object "prototypes":

PHP Code:

// from http://www.flzone.com/go?7678
String.prototype.replace = function(patternreplacement) {
  return 
this.split(pattern).join(replacement);


Another idea which I think would work better for GScript would be if you could create a class with the name "TServerPlayer" and all TServerPlayer objects would inherit those methods. This can already be done by joining classes to the player, but for stuff like TServerLevel and TGraalVar (for strings) it would be invaluable. I would love to be able to add string.replace(a, b).

Admins 03-07-2011 04:00 AM

findnearestplayers() is operating on players[] instead of level.players, that's why it cannot simply made to be a level function. The players[] array is only containing players from the nearby 3x3 levels, while level.players[] can contain thousands of players.


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

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