Iterating over players to get info
I am having some problems iterating over the players to get their rates.
First I was just using this: PHP Code:
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:
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:
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 |
Re: Iterating over players to get info
1. If you are going to iterate from 1 to X for players then you should use a global var that holds get_maxplayers() instead of using 32. If you use 32 and the server is set to hold a max of, lets say, 20 players then anything above 20 can be used as an entity index..not player id which would result in errors depending on what you're doing.
PHP Code:
PHP Code:
Here's a snippet of your code with corrections made PHP Code:
|
Re: Iterating over players to get info
Quote:
Thanks for such a detailed reply. I have now split this function into a separate plugin, pasted at the end of the post. I am still having the same issues: 1. the values from query_client.. does not show on first run 2. Have yet to get cl_rate to work Code:
Client console:Put a couple of questions in the comments, would appreciate pointers. Am also wondering how I am supposed to know how big buffers I need for things such as the lineOut var (the line printed to console), or the responses from query_client_cvar - where/how would I find out? Ref. my poorly thought out define section.. PHP Code:
|
Re: Iterating over players to get info
1. the values from query_client.. does not show on first run
This is because the way query_client_cvar works. It does the request and then the response is handled by a separate function. In this case, the response has not yet been received from the client at the time that you print to the user. What you can do is make the user notification occur at the final requested cvar value in your handler function. ie, suppose you request cl_rate, cl_updaterate and ex_interp. When ex_interp is received in cvarCheck function, print all your cvar values. 2. Have yet to get cl_rate to work IIRC, this one may not be retrievable. Don't quote me on it but I do recall there being some client values that are not retrievable. Am also wondering how I am supposed to know how big buffers I need for things such as the lineOut var (the line printed to console), or the responses from query_client_cvar - where/how would I find out? You need to know the maximum possible string that will be stored in the buffer and use that + 1. This is why everyone uses 31 or 32 for strings to hold user names. Can Pawn handle a switch here? case "cl_rate" etc? No, you cannot switch a string value formatex(g_iClRates[index], strlen(cvar_value), "%s", cvar_value); ^ also working, but is it copy or format which is the preferable one in this case? If not using format, should one do str_to_num() to assure one has the correct type of data? Any time you are working with an integer value it is always better to use an integer type. As you know, pawn does not have any data types so you will just be using a standard array. [not 2-dimension as you would for string] g_iClRates[index] = str_to_num( cvar_value ); and you have to redimension the array new g_iClRates[MAX_PLAYERS] |
Re: Iterating over players to get info
Thanks for all your help, appreciated!
Quote:
|
Re: Iterating over players to get info
Quote:
Is there something you are having a problem with or are you just curious? |
Re: Iterating over players to get info
Simply trying to learn best practices, so I was wondering if I had missed a field in the function/native reference which indicate the expected return length for the natives that returns strings or multiple values. I see return values are stated for the natives that return a value from an enumerated set, but what about the others? For now I just get on by test/fail.
I think this is kinda related to my previous Q; Where is the nick length limit of ~32 chars set? Somewhere in Half-Life? Maybe a link to some HL docs would answer my questions. Rephrased: If you did not already know for a fact the max length for nicks is 32, how would you proceed to find out? English isn't my first language, so this is as clear as I can define my problem. Thanks for hanging in there :) |
| All times are GMT -4. The time now is 15:44. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.