server cvar and printing them
Hi ,
How to get value of server cvar and whats is data type? For example sv_maxrate I did new iRate=get_cvar_pointer("sv_maxrate") and tried to print is through server_cmd("say rate : %f", iRate) but getting problem ... |
Re: server cvar and printing them
Code:
In your code, you show the pointer of cvar sv_maxrate (in RAM Memory) so, the value can be 2, or 598746, or 1475... Look at this picture : http://**************/photo/my-images/69/5158.png/ You should understand with that. Each cvar has his pointer in RAM Memory. So, you have to get the value of the cvar with get_pcvar_num|float|string. |
Re: server cvar and printing them
Code:
new g_fRate,g_fUpdate,g_fC4timer,g_fRTime,g_fHostname |
Re: server cvar and printing them
You didn't fully understand how things work apparently.
First, learn to post all information available, including compile or in-game errors because it may help people to quickly help you without testing the code... which some people might not have time to do. Now... - Strings aren't returned, you need to parse them in the function and they need to be declared as arrays... read the pawn tutorial from AMXX wiki to fully understand variables and their types. Code:
new pCvar_hostnameCode:
new pCvar_freezetime- Don't use that variable notation style (it's called hungarian notation) if you don't understand it... f or fl is for float values, i is for integer/numbers, sz for strings, etc... but you seem to assign them randomly. You don't have to use those prefixes but if you want to, I suggest you learn their meaning first. |
Re: server cvar and printing them
Quote:
g_fHostname -- this one is a mistake :D .. it should be g_s :P |
Re: server cvar and printing them
No, it doesn't need to be f or s, because that's the cvar pointer, not the cvar value... so either use "i" or something else to express that it's a cvar pointer, I personally like to prefix them with "pCvar_<cvar name here>" which is obvious what it is and expecially obvious that it's a global var.
|
Re: server cvar and printing them
new g_fRate,g_fUpdate,g_fC4timer,g_fRTime,g_sHost name
public plugin_init() { register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR) g_fRate=get_cvar_pointer("sv_maxrate") g_fUpdate=get_cvar_pointer("sv_maxupdaterate" ) g_fC4timer=get_cvar_pointer("mp_c4timer") g_fRTime=get_cvar_pointer("mp_roundtime") g_sHostname=get_cvar_pointer("hostname") } public client_putinserver(id) { if(is_user_bot(id)) return PLUGIN_HANDLED set_task(10.0,"server_info",id) return PLUGIN_HANDLED } public server_info(id) { new szHostname[64] new float:fRate=get_pcvar_float(g_fRate) new float:fUpdate=get_pcvar_float(g_fUpdate) new float:fC4timer=get_pcvar_float(g_fC4timer) new float:fRTime=get_pcvar_float(g_fRTime) get_pcvar_string(g_sHostname, szHostname, charsmax(szHostname)) server_cmd("say rate : %0.f , Updaterate : %.0f , C4Timer : %.0f , RoundTime : %.0f , Hostname : %s ",fRate,fUpdate,fC4timer,fRTime,szHostnam e) } [/CODE] Now I am getting argument type mismatch error :( |
Re: server cvar and printing them
"Float" tag is case sensitive, you can't use "float" instead.
You also have a space in a variable: "g_sHost name" and I told you that you still didn't understand what you're storing, just make simple variables because it will confuse people who read your code. You also have a space in the print's arguments: "szHostnam e" |
Re: server cvar and printing them
okie ..got it ..but I dnt have any space in that variable ..donno how it came while pasting
After converting float--> Float now it works fine ... TY hunter :D |
Re: server cvar and printing them
Quote:
If you quote his post, you won't see those spaces. |
| All times are GMT -4. The time now is 00:47. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.