AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CVAR Problem (https://forums.alliedmods.net/showthread.php?t=155134)

nikhilgupta345 04-17-2011 22:18

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

fysiks 04-17-2011 22:32

Re: CVAR Problem
 
Try moving the server_print() to somewhere else like plugin_cfg() or something after declaring the cvar.

nikhilgupta345 04-17-2011 22:40

Re: CVAR Problem
 
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.

fysiks 04-17-2011 22:42

Re: CVAR Problem
 
Quote:

Originally Posted by nikhilgupta345 (Post 1452518)
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.

nikhilgupta345 04-17-2011 22:47

Re: CVAR Problem
 
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 ) );



fysiks 04-17-2011 23:12

Re: CVAR Problem
 
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)?

nikhilgupta345 04-17-2011 23:17

Re: CVAR Problem
 
I have, and it works fine. I will send you the codde through a PM, if you could see what the problem is?

nikhilgupta345 04-17-2011 23:37

Re: CVAR Problem
 
More Info:

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

"plmodels/knife/p_katana.mdl"

fysiks 04-17-2011 23:46

Re: CVAR Problem
 
Bizarre. I don't know where to go with that. Maybe someone else can figure it out.

Hunter-Digital 04-18-2011 00:42

Re: CVAR Problem
 
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.


All times are GMT -4. The time now is 19:59.

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