Author Topic: Get clients in server  (Read 1086 times)

I need a script to list all clients in a server - the script itself is clientsided.

clientGroup.getCount() isn't working, so i assume that's server sided.

Can someone tell me what to do here? Thanks.

listClients(); if it has what you're looking for.

ok

Code: [Select]
for(%i = 0; %i < serverConnection.getCount(); %i++)
{
  %b = serverConnection.getObject(%i);
  if(%b.getClassName(); $= "Player")
    echo(%b.getShapeName());
}

edit: This of course only gets players that are spawned.

listClients(); if it has what you're looking for.

According to my console, that's not a function.

It needs to be client-sided, and get the number of clients on the server.
This is what i have so far:
Code: [Select]
%count=clientGroup.getCount(); //Does not work
for(%i=0;%i<%count;%i++)
{
%obj=%c.getObject(%i); //Also does not work because the first one doesn't
                                                     //blah blah blah stuff here
}


Quoterefafterpost: otto-san, that returns the players, which i assume is spawned players. This needs to cover all clients in the server, even the dead or non-spawned ones.
« Last Edit: March 25, 2011, 08:28:46 PM by ThinkInvisible »

I tried experimenting with that, I never got it to work.

ok

Code: [Select]
for(%i = 0; %i < serverConnection.getCount(); %i++)
{
  %b = serverConnection.getObject(%i);
  if(%b.getClassName(); $= "Player")
    echo(%b.getShapeName());
}

edit: This of course only gets players that are spawned.

Correction :
Code: [Select]
for(%i = 0; %i < serverConnection.getCount(); %i++)
{
  %b = serverConnection.getObject(%i);
  if(%b.getClassName() $= "Player") //No ; after functions in If structures
    echo(%b.getShapeName());
}

I keep making that mistake! D:

It's only with getClassName(). It's annoying.

So long as you caught it, haha.

The problem still stands. We needs Badspot, or Xalos, or Bauklotz, or SOMEBODY.
« Last Edit: March 25, 2011, 09:18:01 PM by ThinkInvisible »

What exactly are you trying to do? You can get the names from the Player List:
Code: [Select]
for(%i=0;%i<NPL_List.rowCount();%i++)
{
   %name = getField(NPL_List.getRowText(%i),1);
   //Do stuff with name?
}

What exactly are you trying to do? You can get the names from the Player List:
Code: [Select]
for(%i=0;%i<NPL_List.rowCount();%i++)
{
   %name = getField(NPL_List.getRowText(%i),1);
   //Do stuff with name?
}
Oh lol.

What exactly are you trying to do? You can get the names from the Player List:
Code: [Select]
for(%i=0;%i<NPL_List.rowCount();%i++)
{
   %name = getField(NPL_List.getRowText(%i),1);
   //Do stuff with name?
}

THANK YOU.

THANK YOU SO MUCH.

Wait, Think... You were really looking for that? This is what I use:

Code: [Select]
function findNameByPLID(%id) {
for(%i = 0; %i < NPL_List.rowCount(); %i++) {
%list = NPL_List.getRowText(%i);
%name = getField(%list,1);
%pid = getField(%list,3);
if(%id == %pid)
return %name;
}
return false;
}

function findIDByPLName(%name) {
for(%i = 0; %i < NPL_List.rowCount(); %i++) {
%list = NPL_List.getRowRext(%i);
%pname = getField(%list, 1);
%id = getField(%list, 3);
if(strStr(%pname, %name) > -1 && strLen(%name))
return %id SPC %pname;
}
return -1;
}

function findNameByEither(%either) {
%PLID = findNameByPLID(%either);
%PLName = findIDByPLName(%either);
if(%PLName == 0 && %PLID != -1)
return %PLID;
else if(%PLID == -1 && firstWord(%PLName) != 0)
return restWords(%PLName);
else
return -1;
}

The either check, I was planning to use so I could enter either into some chat command and the name from both. That way, I could either use part of the name or an ID for full name. Mostly for people with odd characters in their name, although the they make their name 100% odd characters.
« Last Edit: March 26, 2011, 05:21:08 AM by MegaScientifical »

-gianteffingsnip-

...Just look at my code and you'll understand what i needed.
Code: [Select]
function returnPlayers(%IDname) {                                                                                     //Blah blah blah
if(!%IDname $= "ID" && !%IDname $= "name") {                                                                 //If %IDname isn't the proper value...
echo("Error running returnPlayers : Please enter ID or Name.");                                             //Notify the user
return;                                                                                                                               //End command
}                                                                                                                                       //Moarblahblahblah
%count = NPL_list.rowCount();                                                                                             //Get the number of players
for(%i=0;%i<%count;%i++)                                                                                               //For loop.
{                                                                                                                                       //Blah
    %listname = %listname@" "@strReplace((getField(NPL_List.getRowText(%i),1))," ","_"); //Append this to listname
  %listid = %listid@" "@(getField(NPL_List.getRowText(%i),3));                                       //Append this to listID
}                                                                                                                                      //asf.
if(%IDname $= "ID") {                                                                                                      //If the case is ID...
if(!%listID) {echo("ERROR : No players can be found.");}                                                     //Uh oh.
return(%count@%listID);                                                                                                   //Append the count to the start for tagging purposes. Return ID list.
}                                                                                                                                     //Fasf.
if(%IDname $= "name") {                                                                                                 //If the case is name...
if(!%listname) {echo("ERROR : No players can be found.");}                                                //Oh noes!
return(%count@%listname);                                                                                              //Return this thing.
}                                                                                                                                     //Stuff.
}                                                                                                                                             //Stuffy stuff.


Edit : Added comments and stuff. And stuffy stuff.
Editedit : Woo. Pagestretch.
« Last Edit: March 26, 2011, 11:03:03 AM by ThinkInvisible »

Code: [Select]
function returnPlayers(%IDname) {
switch$(%IDName) {
case "ID":
%field = 1;
case "name":
%field = 3;
default:
echo("\c3Error running returnPlayers : Please enter ID or Name.");
return;
}

%count = NPL_list.rowCount();
for(%i = 0; %i < %count; %i++)
%list = %list SPC strReplace(getField(NPL_List.getRowText(%i), %field), " ", "_");
if(strLen(trim(%list)))
return %count @ %list;
else
echo("\c3Error running returnPlayers : No players can be found.");
}

Simplified it. Probably can be simplified more.
« Last Edit: March 26, 2011, 05:35:29 PM by MegaScientifical »

Late by a few days, but the two %fields defined should be reversed: You have it set up to return the IDs for "name" and the names for "ID".