Raised This Month: $ Target: $400
 0% 

Cvar Utilities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 06-20-2014 , 10:43   Cvar Utilities
Reply With Quote #1

Code:
enum e_Cvar {
    CVAR_BASE_HEALTH,
    CVAR_TIME_TO_WAVE,
    CVAR_MONSTER_DAMAGE,
    CVAR_BOSS_DAMAGE,
    CVAR_KILL_GOLD,
    CVAR_KILL_MONEY,
    CVAR_KILL_BONUS_GOLD,
    CVAR_KILL_BOSS_GOLD,
    CVAR_KILL_BP_AMMO,
    CVAR_BLOCK_CMD_KILL,
    CVAR_KILL_MONSTER_FX,
    CVAR_ONE_PLAYER_MODE,
    CVAR_WAVE_GOLD,
    CVAR_WAVE_MONEY,
    CVAR_COUNTDOWN_MODE,
    CVAR_RESPAWN_PLAYER_CMD,
    CVAR_SEND_MONSTER_TIME,
    CVAR_SWAP_MONEY,
    CVAR_SWAP_MONEY_MONEY,
    CVAR_SWAP_MONEY_GOLD,
    CVAR_DAMAGE_RATIO,
    CVAR_DAMAGE_GOLD
}

new gCvarInfo[e_Cvar]
new gCvarValue[e_Cvar]

public plugin_init()
{
gCvarInfo[CVAR_BASE_HEALTH]     = CvarRegister("td_base_health", "80");
    gCvarInfo[CVAR_TIME_TO_WAVE]     = CvarRegister("td_time_to_wave", "12")
    gCvarInfo[CVAR_MONSTER_DAMAGE]     = CvarRegister("td_damage", "4");
    gCvarInfo[CVAR_BOSS_DAMAGE]     = CvarRegister("td_boss_damage", "8");
    
    // =====
    
    gCvarInfo[CVAR_KILL_GOLD]     = CvarRegister("td_kill_gold", "3");
    gCvarInfo[CVAR_KILL_BONUS_GOLD]    = CvarRegister("td_kill_bonus_gold", "10");
    gCvarInfo[CVAR_KILL_BOSS_GOLD]     = CvarRegister("td_kill_boss_gold", "6");
    gCvarInfo[CVAR_KILL_MONEY]     = CvarRegister("td_kill_money", "650");
    gCvarInfo[CVAR_KILL_BP_AMMO]     = CvarRegister("td_kill_bp_ammo", "15");
    gCvarInfo[CVAR_WAVE_GOLD]     = CvarRegister("td_wave_gold", "5");
    gCvarInfo[CVAR_WAVE_MONEY]     = CvarRegister("td_wave_money", "1000");
    
    gCvarInfo[CVAR_SWAP_MONEY]     = CvarRegister("td_swap_money", "1");
    gCvarInfo[CVAR_SWAP_MONEY_MONEY] = CvarRegister("td_swap_money_money", "10000");
}
public OnChangeCvarValue( handleCvar, const oldValue[], const newValue[], const cvarName[], const defaultValue[] )
{
    if(handleCvar != _:gCvarInfo[CVAR_SEND_MONSTER_TIME])
    {
        server_print("%s %d", newValue, handleCvar)
        gCvarValue[e_Cvar:handleCvar] = str_to_num(newValue)
    }
}
I want to set value of Cvar to gCvarValue which is created by enum, when i want to set this value, i've got Index out of bounds error.

How to do it usings enum's ?
grs4 is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-20-2014 , 12:17   Re: Cvar Utilities
Reply With Quote #2

The cvar handles do not correspond to your enum values. Doing e_Cvar:handleCvar is pretty much guaranteed to give you OOB errors. You have to actually search for the cvar handle in gCvarInfo.
__________________
In Flames we trust!
Nextra is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 06-20-2014 , 13:15   Re: Cvar Utilities
Reply With Quote #3

OK thanks for answer, i do it :
Code:
public OnChangeCvarValue( handleCvar, const oldValue[], const newValue[], const cvarName[], const defaultValue[] )
{
    if(handleCvar != _:gCvarInfo[CVAR_SEND_MONSTER_TIME]) {
        for(new i; i < _:e_Cvar; i++) {
            if(gCvarInfo[e_Cvar:i] == handleCvar) {
                gCvarValue[e_Cvar:i] = str_to_num(newValue)
                client_print(0,3,"%d %s %d", i, cvarName, str_to_num(newValue))
                client_print(0,3,"%d", gCvarValue[e_Cvar:i] )
                break
            }
        }
        
    }
}
And it works propely, but if i type under all cvars
Code:
CvarHookChangeAll("OnChangeCvarValue");
I'll give error:
Code:
L 06/20/2014 - 19:19:30: [CVAR_UTIL] Invalid hook callback "100"
L 06/20/2014 - 19:19:30: [AMXX] Displaying debug trace (plugin "td_new.amxx", version "0.4")
L 06/20/2014 - 19:19:30: [AMXX] Run time error 19: function not found 
L 06/20/2014 - 19:19:30: [AMXX]    [0] td_new.sma::LoadCvars (line 465)
L 06/20/2014 - 19:19:30: [AMXX]    [1] td_new.sma::plugin_init (line 417)
If i type
Code:
CvarHookChangeAll("OnChangeCvarValue", true);
It will work, but first value is 0, and 0 errors it'll given
How to do this with out ignoring first call, with out any errors ... ?


edit;

i missed the problem using this under all CvarRegister
Code:
    for(new i; i < _:e_Cvar;i++)
        if(i != _:CVAR_SEND_MONSTER_TIME)
            gCvarValue[e_Cvar:i] = get_pcvar_num(gCvarInfo[e_Cvar:i])
I do it with "true", and values are properly loaded, and it works fine, but i want to do without this "true" in hook,how to ?

Last edited by grs4; 06-20-2014 at 13:20.
grs4 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-20-2014 , 15:36   Re: Cvar Utilities
Reply With Quote #4

If purpose is to cache value, you could use directly CvarCache without the cvar hooking hassle.
__________________

Last edited by Arkshine; 06-20-2014 at 15:37.
Arkshine is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 06-20-2014 , 16:40   Re: Cvar Utilities
Reply With Quote #5

Love you Mr.Freeman, this is pretty cool
Greattings from Poland, and the topic can be closed
grs4 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 21:10.


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