Raised This Month: $ Target: $400
 0% 

Printing query_client_cvar values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 06-25-2007 , 23:09   Printing query_client_cvar values
Reply With Quote #1

This one has me bugged. In this test code...
Code:
#include <amxmodx>
#include <amxmisc>
 
#define PLUGIN "Players' Rate CVars"
#define VERSION "1.0"
#define AUTHOR "Vet(3TT3V)"
 
new g_info[256]
new g_pos
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_concmd("amx_rate_info", "cmd_get_rates", ADMIN_CFG, "Get players' rate CVars")
}
 
public cmd_get_rates(id)
{
    static iPlayers[32], info[32]
    new pid, iNum, i
    get_players(iPlayers, iNum, "ch")
    for (i = 0; i < iNum; i++) {
        pid = iPlayers[i]
        get_user_name(pid, info, 31)
        g_pos = format(g_info, 255, "%s ",info)
        query_client_cvar(pid, "rate", "query_results")
        query_client_cvar(pid, "cl_updaterate", "query_results")
        query_client_cvar(pid, "cl_cmdrate", "query_results")
        console_print(id, "Exit info %s", g_info)
    }
    return PLUGIN_HANDLED
}
 
public query_results(id, cvar_name[], cvar_value[])
{
    g_pos += format(g_info[g_pos], 255, "%s=%s ", cvar_name, cvar_value)
    console_print(id, g_info)  // Test info printout
}
The console prints...
Code:
 
Exit info 3TT3V
3TT3V rate=10000 
3TT3V rate=10000 cl_updaterate=45 
3TT3V rate=10000 cl_updaterate=45 cl_cmdrate=45
I put the console_print in the query_results() routine to see what was going on. It shows the info is getting into the g_info array, but the console_print at the end of the cmd_get_rates() prints first and without the query_results() info.

I bet its something ridiculously simple. But I'll be damned if I can find it.
Any ideas???
__________________
=====================================
- My Plugins -
=====================================
Vet is offline
Send a message via MSN to Vet
stupok
Veteran Member
Join Date: Feb 2006
Old 06-26-2007 , 00:27   Re: Printing query_client_cvar values
Reply With Quote #2

It looks like you're trying to store the data for every player in one array, so I fixed your code for you:

Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "Players' Rate CVars" #define VERSION "1.0" #define AUTHOR "Vet(3TT3V)" #define MAX_PLAYERS 32 new g_info[MAX_PLAYERS+1][256] new g_pos[MAX_PLAYERS+1] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("amx_rate_info", "cmd_get_rates", ADMIN_CFG, "Get players' rate CVars") } public cmd_get_rates(id) {     static iPlayers[32], name[32]     new pid, iNum         get_players(iPlayers, iNum, "ch")         for(new i = 0; i < iNum; i++)     {         pid = iPlayers[i]                 get_user_name(pid, name, 31)                 g_pos[pid] = format(g_info[pid], 255, "%s ", name)                 query_client_cvar(pid, "rate", "query_results")         query_client_cvar(pid, "cl_updaterate", "query_results")         query_client_cvar(pid, "cl_cmdrate", "query_results")                 console_print(pid, "Exit info %s", name)     }     return PLUGIN_HANDLED } public query_results(id, cvar_name[], cvar_value[]) {     g_pos[id] += format(g_info[id][g_pos[id]], 255-g_pos[id], "%s=%s ", cvar_name, cvar_value)         console_print(id, g_info)  // Test info printout }

Now, about the console_print(id, "Exit info %s", g_info[pid]) executing before query_results().

When you query for a client cvar, you are telling the server to call query_results when it receives information about the cvar you tell it to query. This process is not instant, so the "Exit info" prints first and later on, when information about the client's cvar is received, query_results is executed and prints the "%s=%s".
stupok is offline
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 06-26-2007 , 01:04   Re: Printing query_client_cvar values
Reply With Quote #3

Ah, sweet. Good answer. Thanks !
And yes, I am storing all players in the same array. But it gets reset on the next player's info.
My ultimate goal is to enter a command and see all player's rates etc. in the console in a list like...

Code:
 
Name            Rate       Update     CmdRate
----------------------------------------------
3TT3V          10000        45           45
stupok69       15000        50           50
Ven             9999        60           60
teame06        12000        55           45
---------------------------------------------
So is there a way to tell when the query function has gotten the info from the client? Or do you just stick in a task and guess at the time?

Thanks again.
__________________
=====================================
- My Plugins -
=====================================

Last edited by Vet; 06-26-2007 at 01:21.
Vet is offline
Send a message via MSN to Vet
stupok
Veteran Member
Join Date: Feb 2006
Old 06-26-2007 , 01:31   Re: Printing query_client_cvar values
Reply With Quote #4

Quote:
Originally Posted by Vet View Post
So is there a way to tell when the query function has gotten the info from the client? Or do you just stick in a task and guess at the time?
I'm not sure if I understand your question, but you can't predict when it will be executed. When the server receives the client's cvar value, that is when the query_results() function will be called.

In this case you could actually record the time it takes to get the client's cvar value if you really wanted, but I don't think that's actually valuable information.

If you'd like to know when the variable contains all the info, or when all of the clients' cvars have been recorded, you can just add another global variable to count how many times query_results() has been executed for each client. Then check if every client has had it executed 3 times (3 different cvars).

Last edited by stupok; 06-26-2007 at 01:34.
stupok is offline
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 06-26-2007 , 10:46   Re: Printing query_client_cvar values
Reply With Quote #5

Got it figured out. After you 'schooled' me on the workings of query_client_cvar(), I figured all that I had to do was make the last cvar query produce the desired output. So I pointed the last query to a separate routine and it seems to work.
Code:
#include <amxmodx>
#include <amxmisc>
 
#define PLUGIN "Players' Rate CVars"
#define VERSION "1.0"
#define AUTHOR "Vet(3TT3V)"
 
new g_info[256]
new g_pos
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_concmd("amx_rate_info", "cmd_get_rates", ADMIN_CFG, "Get players' rate CVars")
}
 
public cmd_get_rates(id)
{
    static iPlayers[32]
    new pid, iNum, i, info[32]
    get_players(iPlayers, iNum, "ch")
    for (i = 0; i < iNum; i++) {
        pid = iPlayers[i]
        get_user_name(pid, info, 31)
        g_pos = format(g_info, 255, "%s ",info)
        query_client_cvar(pid, "rate", "query_results")
        query_client_cvar(pid, "cl_updaterate", "query_results")
        query_client_cvar(pid, "cl_cmdrate", "out_results")
    }
    return PLUGIN_HANDLED
}
 
public query_results(id, cvar_name[], cvar_value[])
{
    g_pos += format(g_info[g_pos], 255, "%s=%s ", cvar_name, cvar_value)
}
 
public out_results(id, cvar_name[], cvar_value[])
{
    g_pos += format(g_info[g_pos], 255, "%s=%s ", cvar_name, cvar_value)
    console_print(id, "Exit info %s", g_info)
}
Thanks!
__________________
=====================================
- My Plugins -
=====================================
Vet is offline
Send a message via MSN to Vet
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:34.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode