Don't spoon feed a newbie without explaining how things work
Step by step how to make what you were asking for
for ( initialization ; condition ; update ) { body }
the initialization usually starts with %i = 0, for several reasons, in this case, because the first object in the ClientGroup can be referenced by ClientGroup.getObject(0);
the condition is a boolean statement, or a true/false statement, here we use %i < ClientGroup.getCount() so we can loop from 0 to the number of clients, minus one. We do the "minus one" because the first object is referenced by 0, so everything else is shifted down.
the update here is %i++, which just increments the %i value by 1
There are several ways of adding one (%i=%i+1 OR %i+=1 OR %i++) but we use %i++ because it's fast (I'm not so sure if it's any faster in TorqueScript)
The reason %i++ SHOULD be fast is because it's Just one single line of assembly code, so it's efficient. %i+=1 is actually about 7 lines of assembly code (unless the compiler fixes those things), which is 7 times slower than you actually need.
Right now, you have this code
for(%i=0;%i<ClientGroup.getCount();%i++){ body }
The ClientGroup contains a list of Objects that hold information about the clients connected to the server
To reference these objects, you would use the ClientGroup.getObject() method, and if we wanted to get the "%i"th object in the ClientGroup, we would use ClientGroup.getObject(%i)
Let's say we want to store this Object in a variable.
We would use %client = ClientGroup.getObject(%i); to set the variable %client to hold that certain object (an ID that points to the object)
Now, we want to get their BL_ID and print it out
the "print out" method is called echo();
and the BL_ID variable can be accessed through the new "%client" we have, so to print out the BL_ID of %client, we would use
echo(%client.BL_ID);
Now, our full code is:
for(%i=0;%i<ClientGroup.getCount();%i++)
{
%client = ClientGroup.getObject(%i);
echo(%client.BL_ID);
}
And thus, you can now read each client's bl_id
Creating a function:
function functionName(arguments) { body }
the function name is what you are calling, make sure that if you want a /command, you will start your function with:
function servercmdFunctionName ( for /FunctionName )
each servercmd function has 1 default optional argument, the client (Remember from above?)
function servercmdListPlayers(%client){body}
This is the header for a function to list the information, all we need is a body
The body can be the code from before:
function servercmdListPlayers(%client)
{
for(%i=0;%i<ClientGroup.getCount();%i++)
{
%newClient= ClientGroup.getObject(%i);
echo(%newClient.BL_ID);
}
}
However, this is lacking protection, anyone on the server can call this /command, so let's make it Admin only
To see if a client is admin, you simply need to check their isAdmin variable, also see isSuperAdmin
We want to put this in an if statement
if ( condition ) { body }
the condition we will put here is %client.isAdmin
We also want the client's name, which happens to be %client.name
When joining parts of a "String" or line of characters, you can use these symbols:
SPC - Join and add a space
@ - Join without space
SPC acts the same as @" "@
function servercmdListPlayers(%client)
{
if(%client.isAdmin == true)
{
for(%i=0;%i<ClientGroup.getCount();%i++)
{
%newClient= ClientGroup.getObject(%i);
echo(%newClient.name SPC %newClient.BL_ID);
}
}
}
That there is what you were asking for
Try to use the %client.chatMessage( words ); function to print out into the client's chat