Raised This Month: $12 Target: $400
 3% 

ConVar-trouble


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 10-27-2009 , 19:17   ConVar-trouble
Reply With Quote #1

Hello everyone!

I'm trying to get some ConVars to work. The problem is - they do not work O_o
In the beginning of my code I set every cvar to a global var. For some reason the cvar always gets it's default value (given in CreateConVar).
If I check the cvar later (with GetConVarInt), it is the correct value. What am I doing wrong?

PHP Code:

new Handle:LRsenabled;

// ConVar-stuff
new Handle:sm_hosties_knife_enable INVALID_HANDLE;
new 
Handle:sm_hosties_s4s_enable INVALID_HANDLE;
new 
Handle:sm_hosties_guntoss_enable INVALID_HANDLE;
new 
Handle:sm_hosties_chickenfight_enable INVALID_HANDLE;

public 
OnPluginStart()
{

    
RegConsoleCmd("sm_cvarcheck"Command_CvarCheck);

    
// Create ConVars
    
sm_hosties_knife_enable CreateConVar("sm_hosties_knife_enable""1""Enable LR Knife Fight; 0 - disable, 1 - enable")
    
sm_hosties_s4s_enable CreateConVar("sm_hosties_s4s_enable""1""Enable LR Shot4Shot; 0 - disable, 1 - enable")
    
sm_hosties_guntoss_enable CreateConVar("sm_hosties_guntoss_enable""1""Enable LR Gun Toss; 0 - disable, 1 - enable")
    
sm_hosties_chickenfight_enable CreateConVar("sm_hosties_chickenfight_enable""1""Enable LR Chicken Fight; 0 - disable, 1 - enable")
    
AutoExecConfig(true"sm_hosties")

    
knife_enable GetConVarInt(sm_hosties_knife_enable);
    
s4s_enable GetConVarInt(sm_hosties_s4s_enable);
    
guntoss_enable GetConVarInt(sm_hosties_guntoss_enable);
    
chickenfight_enable GetConVarInt(sm_hosties_chickenfight_enable);

    
LRsenabled CreateArray(2);

    
// THESE ARE ALWAYS == 1, whatever I set the cvars to -.- (here's some problem)

    
if (knife_enable == 1)
    {
        
PushArrayCell(LRsenabled0);
    }
    if (
s4s_enable == 1)
    {
        
PushArrayCell(LRsenabled1);
    }
    if (
guntoss_enable == 1)
    {
        
PushArrayCell(LRsenabled2);
    }
    if (
chickenfight_enable == 1)
    {
        
PushArrayCell(LRsenabled3);
    }
}

public 
Action:Command_CvarCheck(clientargs)
{
    if (
GetConVarInt(sm_hosties_guntoss_enable) == 0// THIS works just like I want it to
    
{
        
PrintToChatAll("GetConVarInt(sm_hosties_guntoss_enable) was 0.");
    }
    return 
Plugin_Handled;

dataviruset is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 10-27-2009 , 19:39   Re: ConVar-trouble
Reply With Quote #2

Try this instead of doing it in plugin start.
PHP Code:
public OnConfigsExecuted()
{
    
knife_enable GetConVarInt(sm_hosties_knife_enable);
    
s4s_enable GetConVarInt(sm_hosties_s4s_enable);
    
guntoss_enable GetConVarInt(sm_hosties_guntoss_enable);
    
chickenfight_enable GetConVarInt(sm_hosties_chickenfight_enable);
 
    
LRsenabled CreateArray(2);
 
    if (
knife_enable == 1)
    {
        
PushArrayCell(LRsenabled0);
    }
    if (
s4s_enable == 1)
    {
        
PushArrayCell(LRsenabled1);
    }
    if (
guntoss_enable == 1)
    {
        
PushArrayCell(LRsenabled2);
    }
    if (
chickenfight_enable == 1)
    {
        
PushArrayCell(LRsenabled3);
    }

If you do it in plugin start and have the cvars in a config it wont work since your getting it before configs are read.

Last edited by Dr!fter; 10-27-2009 at 19:42.
Dr!fter is offline
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 10-27-2009 , 20:37   Re: ConVar-trouble
Reply With Quote #3

AH, I knew it was something simple as that. Many thanks to you!
dataviruset is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 10-27-2009 , 22:37   Re: ConVar-trouble
Reply With Quote #4

No problem i had the same problem once took me forever to figure it out ^^
Dr!fter 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 23:26.


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