Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   problem with the players array o.0 (https://forums.graalonline.com/forums/showthread.php?t=78968)

coreys 03-09-2008 05:54 AM

problem with the players array o.0
 
For some odd reason (I don't know if this is restricted to just Maloria, or what) the built in players array which holds objects for the players on the server (as opposed to allplayers, which has their accounts) is not working serverside. I've tried just making a test NPC to do something like this:
PHP Code:

for (plplayers) {
  echo(
pl.account);


But nothing happens...I've tried restarting the NPC Server several times, and now I'm at a loss...

cbk1994 03-09-2008 06:03 AM

players is for players in the level, you need to use allplayers.

PHP Code:

for ( temp.allplayers )
{
  echo( 
temp.i.account );



coreys 03-09-2008 06:06 AM

...uh...
I've always used players serverside as far as I can remember...never had trouble with it before.
And for some reason when I use allplayers it goes through twice.

cbk1994 03-09-2008 06:20 AM

Quote:

Originally Posted by coreys (Post 1378488)
...uh...
I've always used players serverside as far as I can remember...never had trouble with it before.
And for some reason when I use allplayers it goes through twice.

Well you've always done it wrong ... players means the players in a level, may have worked for a DB NPC in a level with players ...

allplayers should only be going through once. I would try echoing at the beginning of the function to make sure it isn't being called twice.

coreys 03-09-2008 06:26 AM

Quote:

Originally Posted by cbkbud (Post 1378494)
Well you've always done it wrong ... players means the players in a level, may have worked for a DB NPC in a level with players ...

No. It's worked for every NPC I've done using it. I'm not stupid, I would've figured it out by now if it never worked.
Quote:

Originally Posted by cbkbud (Post 1378494)
allplayers should only be going through once. I would try echoing at the beginning of the function to make sure it isn't being called twice.

No ****.
I even did this:
PHP Code:

temp.list = new[0];
for (
plallplayers) {
  if (!(
pl in temp.list)) {
    
temp.list.add(pl);
    echo(
pl);
  }


And it echoed twice.

Chompy 03-09-2008 06:27 AM

Why it's going 'twice' is because it contains IRCs, RC's and players..

to filter those out use obj.isexternal and/or check if their level is 0 or something

coreys 03-09-2008 06:29 AM

Quote:

Originally Posted by Chompy (Post 1378497)
Why it's going 'twice' is because it contains IRCs, RC's and players..

to filter those out use obj.isexternal and/or check if their level is 0 or something

Yeah, I've checked for NULL level as well, and it still does it o.o

cbk1994 03-09-2008 06:30 AM

Quote:

Originally Posted by coreys (Post 1378496)
No. It's worked for every NPC I've done using it.

Then your NPC-Server really is screwed up ;o

That or I'm just ignorant.

coreys 03-09-2008 06:38 AM

Quote:

Originally Posted by cbkbud (Post 1378499)
That or I'm just ignorant.

I prefer the term "misinformed," although they technically mean the same thing.

cbk1994 03-09-2008 07:17 AM

Quote:

Originally Posted by coreys (Post 1378501)
I prefer the term "misinformed," although they technically mean the same thing.

Just tried it, players does not work for me on my server ...

napo_p2p 03-09-2008 09:32 AM

Quote:

Originally Posted by coreys (Post 1378498)
Yeah, I've checked for NULL level as well, and it still does it o.o

Odd...

Doing something like:
PHP Code:

for (temp.pallplayers) {
  if (
temp.p.level != null) {
    echo(
temp.p.account);
  }


Will only show the accounts of the player not on RC.

And, yes, Chris is correct. 'players' is an array of player objects in the level, while 'allplayers' is the array of player objects on the server.

zokemon 03-09-2008 10:19 AM

players will not work in all cases serverside in a WNPC because it does not always have the scope of a player which is required to have the level variable not be NULL. If the level variable is NULL, logically the players variable would be empty.

coreys 03-09-2008 05:58 PM

Quote:

Originally Posted by zokemon (Post 1378519)
players will not work in all cases serverside in a WNPC because it does not always have the scope of a player which is required to have the level variable not be NULL. If the level variable is NULL, logically the players variable would be empty.

Yeah, I was sending player.level, which is an object and cannot be passed serverside, instead of player.level.name.

Edit:
I just tested, and when doing:
PHP Code:

if (players != NULL)
  echo(
"test"); 

in the triggeraction I've been trying to use this in, it echoes "test." Meaning players is not null. However, I still can't use it. o.O

coreys 03-09-2008 06:37 PM

Sorry to double-post, but I've got the weirdest ****ing problem with this now...
When both an RC and a client for an account is on, no matter what you do, when you loop through allplayers it will go to that account twice.
PHP Code:

temp.list = NULL;
for (
plallplayers) {
  if (
pl in temp.list)
    continue;
  
temp.list.add(pl);
  
temp.player findPlayer(pl);
  if (
temp.player.level.name != NULL && temp.player.level.name != "level") {
    if (
temp.player.level.name == params[3])
      echo(
pl);
  }


Will still echo my name twice if I am on both client and RC.

Crow 03-09-2008 06:51 PM

Quote:

Originally Posted by coreys (Post 1378572)
Sorry to double-post, but I've got the weirdest ****ing problem with this now...
When both an RC and a client for an account is on, no matter what you do, when you loop through allplayers it will go to that account twice.
PHP Code:

temp.list = NULL;
for (
plallplayers) {
  if (
pl in temp.list)
    continue;
  
temp.list.add(pl);
  
temp.player findPlayer(pl);
  if (
temp.player.level.name != NULL && temp.player.level.name != "level") {
    if (
temp.player.level.name == params[3])
      echo(
pl);
  }


Will still echo my name twice if I am on both client and RC.

You dont have to do the findPlayer() stuff. Something like this will work:

PHP Code:

for (temp.plallplayers) {
  
pl.addWeapon("xyz");
  
pl.hearts 5;
  
pl.client.foo bar;



coreys 03-09-2008 06:57 PM

Quote:

Originally Posted by Crow (Post 1378573)
You dont have to do the findPlayer() stuff. Something like this will work:

PHP Code:

for (temp.plallplayers) {
  
pl.addWeapon("xyz");
  
pl.hearts 5;
  
pl.client.foo bar;



Doesn't change anything though. I figured since it...you know, returned a string, that it wasn't an object.
Also, that DOESN'T work.

zokemon 03-09-2008 07:05 PM

Try something like this:

PHP Code:

echo("I am generating a list now!");
for (
temp.allplayers) {
  if (!
p.isexternal && p.level != "") {
    echo(
" - " p);
  }


Also: allplayers is not an array of strings but is in fact an array of TServerPlayer's and such.

zokemon 03-09-2008 07:12 PM

Turns out the error was in fact with the line
PHP Code:

temp.player findPlayer(pl); 

In doing this, you are setting temp.player to the client pl.
If I had zokemon in all players twice, one for my client and one for my RC, using findplayer() for both of those would give my client.

Inverness 03-09-2008 07:26 PM

When you display object as a string it is using the name of the object. Like doing any string operations on player.level such as player.level.starts() would be doing player.level.name.starts()

Though it doesn't appear to do that with custom objects. I would like it if there was a tostring() function for objects that Graal would call. Which would return this.name by default and could be overridden by scripts.


All times are GMT +2. The time now is 10:14 PM.

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