I am having some problems iterating over the players to get their rates.
First I was just using this:
PHP Code:
for ( i = 1; i <= 32; i++ )
{
if ( !is_user_bot(i) && is_user_connected(i) )
{
// work my magic
}
}
Then I read in a thread here that looping over players this way may lead to unreliable results, like if a client disconnects and leaves an index declared but pointing to "null"/nonexisting player.
Question 1. Doesn't the user_connected() check eliminate events where that could be a real problem?
So I copied some code (thanks) from that thread which I cannot find again, and had:
PHP Code:
new players[32], num, i;
get_players(players, num);
for ( i = 1; i <= num; i++ )
{
new player = players[i];
if ( !is_user_bot(player) && is_user_connected(player) )
{
// work my magic
}
else
{
// woops.
// dumped values: i = 1. player = 0.
}
}
This was pretty much copy+paste, but gave me problems. It triggered the else-clause. I dumped my variables as you can see in the comments. I tried this while I was alone on the server, I had client id 1, and it tried to query client 0.
Question 2. Am I just being a moron here, did I implement the code snippet incorrectly, or was that iterating-players snippet I copied really for other use cases? What would be different?
Current code:
PHP Code:
new lineOut[BIG_BUFF + 1];
new players[MAX_PLAYERS], num, i;
get_players(players, num);
for ( i = 1; i <= num; i++ )
{
if ( !is_user_bot(i) && is_user_connected(i) )
{
new tempNick[MAX_NICKLENGTH + 1];
copy(tempNick, MAX_NICKLENGTH, g_szNicks[i]);
replace_all(tempNick, MAX_NICKLENGTH, "<", "");
replace_all(tempNick, MAX_NICKLENGTH, ">", "");
get_user_info(i, "rate", g_iRates[i], MAX_RATE);
get_user_info(i, "cl_updaterate", g_iClUpdateRates[i], MAX_RATE);
get_user_info(i, "cl_dlmax", g_iDlMax[i], MAX_RATE);
query_client_cvar(i, "cl_cmdrate", "cvarCheck");
query_client_cvar(i, "ex_interp", "cvarCheck");
//query_client_cvar(player, "cl_rate", "cvarCheck");
formatex(lineOut, BIG_BUFF, "rate: %s^tcl_updaterate: %s^tcl_cmdrate: %s^tex_interp: %s^tcl_dlmax: %s^t^t| %s", g_iRates[i], g_iClUpdateRates[i], g_iClCmdRates[i], g_iInterp[i], g_iDlMax[i], tempNick);
client_print(id, print_console, lineOut);
}
else
{
server_print("reported as bot/not connected. Stored nick %s. i=%i. player=%i.", g_szNicks[i], i, player);
}
}
I am currently using this, it seems to work fine in my tests (1-3 players). I am wondering though if this code falls victim of Question 1. The only problem I currently have with this code is that sometimes the values which needs to be ran through query_client.. (like interp) is not reported on the first run of this function, but on all consecutive runs.
Question 3. Why are interp+cmdrate values blank after the first run, what can I do to avoid that?
Question 4. Why does querying for "cl_rate" always yield errors or bad response?
Sample output for the last code:
Code:
] amx_listrates
~~~~~~~~~~~~~~~~~~~~~~~ Listing player rates ~~~~~~~~~~~~~~~~~~~~~~~
rate: 25000 cl_updaterate: 80 cl_cmdrate: ex_interp: cl_dlmax: 100 cc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
] amx_listrates
~~~~~~~~~~~~~~~~~~~~~~~ Listing player rates ~~~~~~~~~~~~~~~~~~~~~~~
rate: 25000 cl_updaterate: 80 cl_cmdrate: 76 ex_interp: 0.013 cl_dlmax: 100 cc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry for such a lengthy post on this, hopefully it is generic enough to be of use to many others.