Raised This Month: $ Target: $400
 0% 

PCvars?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 11-07-2006 , 00:19   PCvars?
Reply With Quote #1

Iv been hearing a lot about 'pcvars'. What exactly is it? Is it better then just normal CVARS?
__________________
Oh yeah

Last edited by Drak; 11-08-2006 at 16:04.
Drak is offline
Send a message via MSN to Drak
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-07-2006 , 00:33   Re: PCvars?
Reply With Quote #2

they work a lot faster than normal get_cvar_* functions because they use pointers (I'm guessing, I know a little bit of C++ and I think I see why using pointers would help here, anyway...). You have to register them to a global variable (unless your only using it once). Heres some example code...
Code:
//i like to make it the same name as the actual cvar
new sv_my_cvar
public plugin_init()
{
    sv_my_cvar = register_cvar("sv_my_cvar","0")
}
my_function()
{
    client_print(0, print_chat, "wow, my cvar = %d", get_pcvar_num(sv_my_cvar))
}
*note that there is no set_pcvar_string
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Drak
Veteran Member
Join Date: Jul 2005
Old 11-07-2006 , 00:55   Re: PCvars?
Reply With Quote #3

So, pretty much in any case, it's always best to use them?
Drak is offline
Send a message via MSN to Drak
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 11-07-2006 , 02:04   Re: PCvars?
Reply With Quote #4

Yeah, unless you want to support versions of AMX Mod X that don't support pcvars
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
The Specialist
BANNED
Join Date: Nov 2006
Old 11-07-2006 , 03:44   Re: PCvars?
Reply With Quote #5

a pcvar is basicly amxmodx's verrsion of a pointer . hooking a varaible directly to cvars . the only time you need to use them is if you use a get_cvar_num("whatever") more then once. if you only use the cvars once in a script theres no need to make a varaible to handle it . becasue everytime a varaible is declared , memory is alocated to handle the variable. so if you use the same cvar more then once , you can use a "pointer" to get and find the varaibles easyier .
The Specialist is offline
Send a message via AIM to The Specialist
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 11-07-2006 , 09:14   Re: PCvars?
Reply With Quote #6

Quote:
Originally Posted by The Specialist View Post
a pcvar is basicly amxmodx's verrsion of a pointer . hooking a varaible directly to cvars . the only time you need to use them is if you use a get_cvar_num("whatever") more then once. if you only use the cvars once in a script theres no need to make a varaible to handle it . becasue everytime a varaible is declared , memory is alocated to handle the variable. so if you use the same cvar more then once , you can use a "pointer" to get and find the varaibles easyier .
Not really. Your sacrificing memory for speed. set/get_pcvar_* is a lot faster than set/get_cvar_*.

Code:
#include <amxmodx> new pHello; public plugin_init() {     register_forward(FM_PlayerPreThink, "_FM_PlayerPreThink");     pHello = register_cvar("Hello", "1"); } public _FM_PlayerPreThink(player) {     if(!get_pcvar_num(pHello)     {     }     return FMRES_IGNORED; }

Even if this was all the code. I would still use pcvar in this situation. It also depends on the situation to. Even though the cvar is only use once in this situation. I would do this even though it only use once in this plugin.

Code:
#include <amxmodx> public plugin_init() { } public plugin_cfg() {     new host[64], db[64], user[64], pass[64];         get_cvar_string("host", host, 63);     get_cvar_string("db", db, 63);     get_cvar_string("user", user, 63);     get_cvar_string("pass", pass, 63);         // Do db connection. }

I would not use pcvar here if your not going to use it more than once. Since this is only start of the plugin. Other than that I would only use normal set/get_cvar_* in plugin_init or plugin_cfg.
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 11-07-2006 , 11:33   Re: PCvars?
Reply With Quote #7

teame06, he obviously meant that if you are going to save the cvar in a variable, thus reading it only once, it is not neccessary to use a pcvar.
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 11-07-2006 , 12:10   Re: PCvars?
Reply With Quote #8

Quote:
Originally Posted by MaximusBrood View Post
teame06, he obviously meant that if you are going to save the cvar in a variable, thus reading it only once, it is not neccessary to use a pcvar.
There really is no necessary reason, it's just better. Lately I've seen a lot of beginers to intermidiate scripters worrying about code effiencecy; you don't need to concern yourself with this unless/until you know 100% about what's going on with your code and/or if a plugin is extremely CPU intensive. It's good to have good, clean, efficent code; it's just that some people go over board with it.

Quote:
Originally Posted by The Specialist View Post
a pcvar is basicly amxmodx's verrsion of a pointer . hooking a varaible directly to cvars . the only time you need to use them is if you use a get_cvar_num("whatever") more then once. if you only use the cvars once in a script theres no need to make a varaible to handle it . becasue everytime a varaible is declared , memory is alocated to handle the variable. so if you use the same cvar more then once , you can use a "pointer" to get and find the varaibles easyier .
Bad/invalid description, on many levels.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 11-07-2006 at 12:12.
Zenith77 is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 11-07-2006 , 12:22   Re: PCvars?
Reply With Quote #9

Quote:
Originally Posted by Zenith77 View Post
Lately I've seen a lot of beginers to intermidiate scripters worrying about code effiencecy; you don't need to concern yourself with this unless/until you know 100% about what's going on with your code and/or if a plugin is extremely CPU intensive.
Thats very far from the truth.
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
The Specialist
BANNED
Join Date: Nov 2006
Old 11-07-2006 , 16:44   Re: PCvars?
Reply With Quote #10

zenith doesnt care he just likes to argue. wether hes wrong or not
team06 on the other hand is good at explaining things , and ill believe team06 in this case .
The Specialist is offline
Send a message via AIM to The Specialist
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 06:57.


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