Raised This Month: $ Target: $400
 0% 

server cvar and printing them


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gamer99
Senior Member
Join Date: Jul 2011
Old 07-25-2011 , 08:38   server cvar and printing them
Reply With Quote #1

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 ...
gamer99 is offline
Honors
Member
Join Date: Jul 2011
Old 07-25-2011 , 08:43   Re: server cvar and printing them
Reply With Quote #2

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.

Last edited by Honors; 07-25-2011 at 08:51.
Honors is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 07-25-2011 , 08:57   Re: server cvar and printing them
Reply With Quote #3

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
gamer99 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-25-2011 , 09:09   Re: server cvar and printing them
Reply With Quote #4

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

Last edited by Hunter-Digital; 07-25-2011 at 09:39.
Hunter-Digital is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 07-25-2011 , 09:32   Re: server cvar and printing them
Reply With Quote #5

Quote:
Originally Posted by Hunter-Digital View Post
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 .. it should be g_s
gamer99 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-25-2011 , 09:40   Re: server cvar and printing them
Reply With Quote #6

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.
__________________
Hunter-Digital is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 07-25-2011 , 09:45   Re: server cvar and printing them
Reply With Quote #7

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
gamer99 is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-25-2011 , 09:47   Re: server cvar and printing them
Reply With Quote #8

"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"
__________________
Hunter-Digital is offline
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 00:47.


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