Raised This Month: $ Target: $400
 0% 

CVAR Problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-17-2011 , 22:18   CVAR Problem
Reply With Quote #1

I made a PCVar, and then when I try to get it's value, it always returns 0.

When I retrieve it as a stirng, it returns the modelname of something else I have in my plugin.

PHP Code:
public plugin_init()
{
    
register_plugin"Jailbreak Shop""1.0""H3avY Ra1n" );
    
    
gpKatanaCost register_cvar"jb_katana_cost""45000" );

    
server_print"The cost is %i."get_pcvar_numgpKatanaCost ) );

It always prints "The cost is 0" in console. NO IDEA why.

I never set the cvar to the modelname.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-17-2011 , 22:32   Re: CVAR Problem
Reply With Quote #2

Try moving the server_print() to somewhere else like plugin_cfg() or something after declaring the cvar.
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-17-2011 , 22:40   Re: CVAR Problem
Reply With Quote #3

Still zero.

I tried with a local variable in init and it works fine

For some reason with the global variable taht I declared it does not work.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-17-2011 , 22:42   Re: CVAR Problem
Reply With Quote #4

Quote:
Originally Posted by nikhilgupta345 View Post
Still zero.

I tried with a local variable in init and it works fine

For some reason with the global variable taht I declared it does not work.
Errors? I don't believe that it won't work since it works on every plugin on the forums that uses cvars .

Show your code.
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-17-2011 , 22:47   Re: CVAR Problem
Reply With Quote #5

I think initializations and init should be suffice.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <hamsandwich>
#include <cstrike>
#include <fun>
#include <fakemeta>
#include <colorchat>

const gItemAmount 11;

new 
gMoneyVault;
new 
gJBPoints[33];

new 
bool:gHasKatana[33];
new 
bool:gHasKnife[33];

new 
bool:gBoughtMac10[33];
new 
bool:gBoughtTMP[33];
new 
bool:gBoughtDeagle[33];
new 
bool:gBoughtFrag[33];
new 
bool:gBoughtFlash[33];
new 
bool:gBoughtSmoke[33];
new 
bool:gBoughtRambo[33];

new 
gKnifeType[33];

new 
gChosenPlayer[33];

new const 
gItemNames[gItemAmount][] = 
{
    
"Katana Knife",
    
"Professional Knife",
    
"Mac-10",
    
"TMP",
    
"Deagle",
    
"+100 HP",
    
"+100 AP",
    
"HE Grenade",
    
"Flashbang",
    
"Smoke Grenade",
    
"Flying Rambo"
};

new const 
gPlayerModels[2][] = 
{
    
"models/knife/p_katana.mdl",
    
"models/knife/p_proff.mdl"
};

new const 
gViewModels[2][] = 
{
    
"models/knife/v_katana.mdl",
    
"models/knife/v_proff.mdl"
};

enum
{
    
KATANA,
    
KNIFE,
    
MAC,
    
TMP,
    
DEAGLE,
    
HP,
    
AP,
    
HE,
    
FLASH,
    
SMOKE,
    
RAMBO
};

new 
gpKatanaCost;
new 
gpProKnifeCost;
new 
gpMac10Cost;
new 
gpTMPCost;
new 
gpDeagleCost;
new 
gpHealthCost;
new 
gpArmorCost;
new 
gpFragCost;
new 
gpFlashCost;
new 
gpSmokeCost;
new 
gpRamboCost;

new 
gpHeadshotReward;
new 
gpKillReward;
new 
gpKatanaReward;

new 
gpRamboHealth;

public 
plugin_init()
{
    
register_plugin"Jailbreak Shop""1.0""H3avY Ra1n" );
    
    
gpKatanaCost         =         register_cvar(         "jb_katana_cost",         "45000"     );
    
gpProKnifeCost         =         register_cvar(         "jb_proknife_cost",     "25000"     );
    
gpMac10Cost         =         register_cvar(         "jb_mac10_cost",         "3200"         );
    
gpTMPCost             =         register_cvar(         "jb_tmp_cost",             "3200"         );
    
gpDeagleCost         =         register_cvar(         "jb_deagle_cost",         "4000"         );
    
gpHealthCost         =         register_cvar(         "jb_health_cost",         "1000"         );
    
gpArmorCost         =         register_cvar(         "jb_armor_cost",         "800"         );
    
gpFragCost             =         register_cvar(         "jb_hegrenade_cost",     "1000"         );
    
gpFlashCost         =         register_cvar(         "jb_flashbang_cost",     "500"         );
    
gpSmokeCost         =         register_cvar(         "jb_smokegrenade_cost""500"         );
    
gpRamboCost         =         register_cvar(         "jb_rambo_cost",         "10000"     );
    
    
gpHeadshotReward register_cvar"jb_headshot_reward""100" );
    
gpKillReward register_cvar"jb_kill_reward""200" );
    
gpRamboHealth register_cvar"jb_rambo_health""150" );
    
gpKatanaReward register_cvar"jb_katana_reward""400" );
    
    
gMoneyVault nvault_open"jb_shop" );
    
    new 
cvar register_cvar"test_cvar""10" );
    
    
server_print"%i"get_pcvar_numcvar ) );
    
register_event"DeathMsg""Event_DeathMsg""a" );
    
register_event"CurWeapon""Event_CurWeapon""be""1=1" );

    
register_concmd"amx_jbshop""CmdAdminControl"ADMIN_ADMIN );
    
    
register_clcmd"say""CmdSay" );
    
register_clcmd"say_team""CmdSay" );
    
    
register_clcmd"_amount_take""CmdTake"ADMIN_ADMIN );
    
register_clcmd"_amount_give""CmdGive"ADMIN_ADMIN );
    
    
register_logevent"Event_RoundEvent"3"1=Round_Start""2=Round_End" );
    
    
RegisterHamHam_Spawn"player""Event_PlayerSpawn");
}

public 
plugin_end()
{
    
nvault_closegMoneyVault );
}

public 
plugin_cfg()
{
    
server_print"The katana cost is %i"get_pcvar_numgpKatanaCost ) );

__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-17-2011 , 23:12   Re: CVAR Problem
Reply With Quote #6

Have you check pointer values? Have you tried with a global variable in a plugin all alone (nothing else, just one include, one function, one pointer, one cvar)?
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-17-2011 , 23:17   Re: CVAR Problem
Reply With Quote #7

I have, and it works fine. I will send you the codde through a PM, if you could see what the problem is?
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-17-2011 , 23:37   Re: CVAR Problem
Reply With Quote #8

More Info:

When I retrieve it as a string, I get this as the value:

"plmodels/knife/p_katana.mdl"
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-17-2011 , 23:46   Re: CVAR Problem
Reply With Quote #9

Bizarre. I don't know where to go with that. Maybe someone else can figure it out.
__________________
fysiks is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-18-2011 , 00:42   Re: CVAR Problem
Reply With Quote #10

I tested your code:
Code:
#include <amxmodx>

new gpKatanaCost

public plugin_init()
{
    register_plugin( "Jailbreak Shop", "1.0", "H3avY Ra1n" );
    
    gpKatanaCost = register_cvar( "jb_katana_cost", "45000" );

    server_print( "The cost is %i.", get_pcvar_num( gpKatanaCost ) );
}
and...
Quote:
The cost is 45000.
So the code works, make sure the cvar is not set to anything else already in the server's memory, just stop the server and start it again before you test, don't use reload.
__________________
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 19:59.


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