AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   server cvar and printing them (https://forums.alliedmods.net/showthread.php?t=162976)

gamer99 07-25-2011 08:38

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 ...

Honors 07-25-2011 08:43

Re: server cvar and printing them
 
Code:
new pCvarMaxRate public plugin_init( ) {      register_clcmd( "say /test" , "cmdTest" )      pCvarMaxRate = get_cvar_pointer( "sv_maxrate" ) } public cmdTest( id ) {      client_print( id , print_chat , "sv_maxrate --> %.0f" , get_pcvar_float( pCvarMaxRate ) ) }

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.

gamer99 07-25-2011 08:57

Re: server cvar and printing them
 
Code:

new g_fRate,g_fUpdate,g_fC4timer,g_fRTime,g_fHostname

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_fHostname=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 iRate=get_pcvar_float("g_fRate")
        new iUpdate=get_pcvar_float("g_fUpdate")
        new iC4timer=get_pcvar_float("g_fC4timer")
        new iRTime=get_pcvar_float("g_fRTime")
        new iHostname=get_pcvar_string("g_fHostname")
        server_cmd("say rate : %0.f ,  Updaterate : %.0f , C4Timer %.0f , RoundTime %.0f , Hostname : %s ",iRate,iUpdate,iC4timer,iRTime,iHostname)
}

Not getting complied :(

Hunter-Digital 07-25-2011 09:09

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_hostname

//...

pCvar_hostname = get_cvar_pointer("hostname")

//...

new szHostname[64]

get_pcvar_string(pCvar_hostname, szHostname, charsmax(szHostname))

- Float variables need to have a tag or they'll give out a warning:
Code:

new pCvar_freezetime

//...

pCvar_freezetime = get_cvar_pointer("mp_freezetime")

//...

new Float:fFreezetime = get_pcvar_float(pCvar_freezetime)

- Variables are NEVER passed surrounded by quotes (meaning get_pcvar_string("g_fHostname") is wrong and get_pcvar_string(g_fHostname) is right)

- 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.

gamer99 07-25-2011 09:32

Re: server cvar and printing them
 
Quote:

Originally Posted by Hunter-Digital (Post 1518082)
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_hostname

//...


pCvar_hostname = get_cvar_pointer("hostname")

//...

new szHostname[64]

get_pcvar_string(pCvar_hostname, szHostname, charsmax(szHostname))[code]

- Float variables need to have a tag or they'll give out a warning:
Code:

new pCvar_freezetime

//...

pCvar_freezetime = get_cvar_pointer("mp_freezetime")

//...

new Float:fFreezetime = get_pcvar_float(pCvar_freezetime)

- Variables are NEVER passed surrounded by quotes (meaning get_pcvar_string("g_fHostname") is wrong and get_pcvar_string(g_fHostname) is right)

- 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.

TY Hunter .. that is a detailed guide ..I am lill bit nood in variables :p ... just learning ......

g_fHostname -- this one is a mistake :D .. it should be g_s :P

Hunter-Digital 07-25-2011 09:40

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.

gamer99 07-25-2011 09:45

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 :(

Hunter-Digital 07-25-2011 09:47

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"

gamer99 07-25-2011 10:05

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

Exolent[jNr] 07-25-2011 10:06

Re: server cvar and printing them
 
Quote:

Originally Posted by Hunter-Digital (Post 1518110)
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"

Those only appear because the forums break lines of text that are too long without spaces.
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.