Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Returning players clientside (https://forums.graalonline.com/forums/showthread.php?t=134268064)

devilsknite1 04-08-2013 04:22 PM

Returning players clientside
 
PHP Code:

for ( temp.players ) {
  echo( 
temp.);


This is only returning one player in the same level on the clientside, and I want it to return all of the players in the level; or in the players[] array case, 3x3 levels, which is also fine.

Tim_Rocks 04-08-2013 04:30 PM

PHP Code:

for ( temp.pl allplayers ) { //This will get you all the current players on the server.
  
if (temp.pl.level.name != player.level.name) { //And this will filter out the players that aren't in your level.
    
continue;
  }

  echo( 
temp.pl );



devilsknite1 04-08-2013 04:31 PM

Quote:

Originally Posted by Tim_Rocks (Post 1715931)
PHP Code:

for ( temp.pl allplayers ) {
  echo( 
temp.pl );



Doesn't work, I've tried this method. It also isn't what I'm wanting to go for. I want to create a custom hit detection system.

Tim_Rocks 04-08-2013 04:33 PM

Sorry, I was making some changes.

Quote:

Originally Posted by Tim_Rocks (Post 1715931)
PHP Code:

for ( temp.pl allplayers ) { //This will get you all the current players on the server.
  
if (temp.pl.level.name != player.level.name) { //And this will filter out the players that aren't in your level.
    
continue;
  }

  echo( 
temp.pl );




devilsknite1 04-08-2013 04:34 PM

No dice :s

If it makes a difference, I'm trying to do this on a gmap, so that may cause some problems. Just in case that changes anything that I'm not catching

EDIT: tried it in a singular level. No luck there either

DustyPorViva 04-08-2013 04:38 PM

You shouldn't need allplayers.

Try:

PHP Code:

for (temp.pl players) {
  echo(
temp.pl.account);


Alternatively just try this:

echo(players.size()); and see if it's actually just returning 1. I don't remember if players returns objects or id's.

Tim_Rocks 04-08-2013 04:39 PM

Quote:

Originally Posted by devilsknite1 (Post 1715934)
No dice :s

If it makes a difference, I'm trying to do this on a gmap, so that may cause some problems. Just in case that changes anything that I'm not catching

EDIT: tried it in a singular level. No luck there either

Oh, I'm sorry, I wasn't sure what you were looking for at first.. Try this.

PHP Code:

for (temp.plfindNearestPlayers(this.xthis.y)) {
  echo(
temp.pl);


That should help, you'll need distance checks though.

DustyPorViva 04-08-2013 04:41 PM

Quote:

Originally Posted by Tim_Rocks (Post 1715936)
Oh, I'm sorry, I wasn't sure what you were looking for at first.. Try this.

PHP Code:

for (temp.plfindNearestPlayers(this.xthis.y)) {
  echo(
temp.pl);


That should help, you'll need distance checks though.

Actually ya, I think this may be what he wants. He shouldn't need distance checks if he's looking for all players in the level as this is what I think findNearestPlayers() returns(all loaded players).

Tim_Rocks 04-08-2013 04:45 PM

He said he was making a hit detection system, and in order to do that, he'll need distance checks so it only registers attacks from players within 1-2 tiles.

devilsknite1 04-08-2013 04:47 PM

Quote:

Originally Posted by DustyPorViva (Post 1715935)
You shouldn't need allplayers.

Try:

PHP Code:

for (temp.pl players) {
  echo(
temp.pl.account);


Alternatively just try this:

echo(players.size()); and see if it's actually just returning 1. I don't remember if players returns objects or id's.

players returns an object, and the size is always outputting 1, no matter how many players are in the level.

Quote:

Originally Posted by Tim_Rocks (Post 1715936)
PHP Code:

for (temp.plfindNearestPlayers(player.xplayer.y)) {
  echo(
temp.pl);



Not having any luck with this, it's still only returning one player in the level. I'm doing it through a weapon NPC, so I switched it to what I'm using. Now, I can change where it detects the nearest player(s), but it still only returns one player
I mean that method can work just fine and is probably what I'll end up doing, but I'm trying to figure out why all of the players in the level aren't being returned o_o

Tim_Rocks 04-08-2013 04:55 PM

PHP Code:

for (temp.plfindNearestPlayers(player.xplayer.y)) { //It was this.x, this.y
  
echo(temp.pl);


There ya go, don't forget to check F2 to see the echo's; it's not going to appear on RC.

devilsknite1 04-08-2013 04:56 PM

I really don't think you're reading what I'm writing... :p
I'm well aware where echo() will output. I'm just wondering why I can't return all of the players in a level.

Tim_Rocks 04-08-2013 05:00 PM

I just logged in player to test it; it's working. Sorry didn't realize you fixed my typo. That's what I'm working with, it's hard for me to help if you don't provide code for us to look at.

PHP Code:

findplayer("Tim_Rocks").addweapon(this.name);

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat == ":hiqtpi") {
    
    for (
temp.pl findNearestPlayers(player.xplayer.y)) { 
      echo(
temp.pl); 
    }  
    
    
player.chat "worked?";
  }


Edit: I'm not even exactly sure why your original code isn't work; It should return everyone on the gmap.

devilsknite1 04-08-2013 05:20 PM

Errrrr I was being dumb
I was drawing a circle around all of the players and it was only showing on one, so instead of looking at how I wasn't indexing the image, I deduced that the returning players wasn't working. OOPS
Thanks for the help though guys, sorry about that :p

cbk1994 04-09-2013 05:26 AM

FWIW, I've actually experienced a bug like the one you initially reported in the past:

Quote:

Originally Posted by cbk1994 (Post 1648538)
Has anyone had issues with the players array being empty clientside? It's happening to me both on GMAPs and in single levels randomly on Mac. Reconnecting fixes it.

It was actually empty, though.


All times are GMT +2. The time now is 09:20 AM.

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