Author Topic: Checking every player on the server for a variable  (Read 1300 times)

Well, first off:
My purpose is to check if there is an admin online, but i do remember seeing a for loop to check through every player on the server, so the answer could be an useful addition to my large, expanding folder of reference functions and others of the sorts.


I'm contemplating asking not to be spoonfed, but I know i will regret it, so make the decision yourself i suppose.

Make a for statement to go through clientGroup. Use clientGroup.getObject(); to get the client. Check if they're an admin.

You're going to have to go through each object in ClientGroup and see if they have the isAdmin variable in a for loop.

Make a for statement to go through clientGroup. Use clientGroup.getObject(); to get the client. Check if they're an admin.
Dangit beat me to it, was fixing to just post.

Code: [Select]
function listplayers()
{
for(%a=0; %a<clientGroup.getCount(); %a++)
{
%client = clientGroup.getObject(%a);
talk(%client.name);
}
}

So using this, I got it to list my name, being the only player on the server, but I'll assume it works for time being. Thanks for the help!

Code: [Select]
function listplayers()
{
for(%a=0; %a<clientGroup.getCount(); %a++)
{
%client = clientGroup.getObject(%a);
talk(%client.name);
}
}

So using this, I got it to list my name, being the only player on the server, but I'll assume it works for time being. Thanks for the help!
Yep. That'll work.
No problem.

I don't feel like this question deserves it's own topic so I'll just ask it here.
How to properly password a server with code?
I tried changing the pref for it and webcom_postserver();
Surfed the RTB mod, but eventually getting jammed at places like RTBSC_cacheServerPref, or serverCmdRTB_setServerOptions .
There must be a simple function to do this that I am missing, hence why i decided that this question did not deserve it's own topic.

$Pref::Server::Password = ...; is enough to actually password the server. WebCom_PostServer(); will immediately update the server list so that clients know that they need a password instead of just getting kicked for `empty string` being the wrong password repeatedly.

When i tried changing the pref and them PostServer, it did not update the master server like it did when i changed it using RTB prefs under the exact same circumstance.


With some help from Crown, it turns out that you need to export the pref and then update master list.

So exact code would be:

$Pref::Server::Password = "asdf"; export($Pref::Server::Password,"config/server/prefs.cs"); webcom_postserver();

That export function would actually ONLY export the password variable and not any other server pref.
You can use the character * to denote all variables matching this pattern, aka $Pref::Server::*

With some help from Crown, it turns out that you need to export the pref and then update master list.

So exact code would be:

$Pref::Server::Password = "asdf"; export($Pref::Server::Password,"config/server/prefs.cs"); webcom_postserver();

No, you don't need to export the prefs there. Just change the variable and post the server.

It didn't work for me and neither did it for Crown on a clean installation, but he discovered, looking at the RTB code, that exporting the pref works.
Doing the method i mentioned worked like clockwork.

Considering that code as shown will not export any useful preferences1, I suspect it's a scoping issue.  Try using schedule(0, 0, "webcom_postserver"); instead.

1Unless you deliberately set your password to $Pref::Server::*.

Okay, not sure exactly what the problem was, but

function changeserverpassword(%password){$Pref::Server::Password = %password; schedule(0, 0, "webcom_postserver");}

seems to work for me so I'll consider this case closed.