AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   cvar doesnt work (https://forums.alliedmods.net/showthread.php?t=285331)

Copper 07-18-2016 00:26

cvar doesnt work
 
Can anyone tell what I did wrong. register_cvar("pm_xpmultiplier", "2") doesnt want to work because I have it set to 2 but it gives me 3x xp. Let me know anything please and thank you.
Code:

#include <amxmodx>
#include <hamsandwich>
#include <pokemod>
 
new bool: g_happytime, cvar_hh_start, cvar_hh_end, g_exp[33]


 public plugin_init() 
{
   
        cvar_hh_start = register_cvar("Happy Hour Start","21")
    cvar_hh_end = register_cvar("Happy Hour End","22")
    RegisterHam(Ham_Killed, "player", "fw_playerkilled_post", 1)
        set_task( 180.0, "ev_Start", .flags="b" )
        register_cvar("pm_xpmultiplier", "2")
}
 
public ev_Start( ) 

    static data[ 9 ];
    get_time( "%H", data, 8 );
   
    new Hour = str_to_num( data );
   
    if (get_pcvar_num(cvar_hh_end) > Hour >= get_pcvar_num(cvar_hh_start))
    {
        g_happytime = true;
        client_print(0, print_chat, "Happy Hour is Active! Double XP per Kill")
    }
}
 
public fw_playerkilled_post(victim, attacker)
{
    if(!is_user_connected(attacker))
        return HAM_IGNORED;
   
    if(victim == attacker)
        return HAM_IGNORED;
       
    if(g_happytime)
    {
        new xp = ( (Poke_PlayerLevel( victim, -1 ) ) * (get_cvar_num("pm_xpmultiplier") - 1) )

                Poke_Give_XP(attacker, -1, xp);
    }
        else
    {
        g_exp[attacker]++ // example happyhour off
    }
    return HAM_IGNORED;
}


sirerick 07-18-2016 12:40

Re: cvar doesnt work
 
Delete g_exp its was a example put on else you normal xp, maybe too because you give poketexp elsewhere

Copper 07-18-2016 18:28

Re: cvar doesnt work
 
I dont think that is the problem. The only problem is that its that the xp given to me is not correct. "2" should be X2 xp but its not doing that.

Bugsy 07-18-2016 18:50

Re: cvar doesnt work
 
Why do you have -1 here, that is essentially making the multiplier do nothing when the cvar is set to 2.

new xp = ( (Poke_PlayerLevel( victim, -1 ) ) * (get_cvar_num("pm_xpmultiplier") - 1) )

I fixed some other things too. Untested.
PHP Code:


#include <amxmodx>
#include <hamsandwich>
#include <pokemod>
 
#define MAX_PLAYERS    32

new bool:g_happytimecvar_hh_startcvar_hh_endcvar_multiplierg_expMAX_PLAYERS ];

public 
plugin_init()  
{
    
cvar_hh_start register_cvar("Happy Hour Start","21")
    
cvar_hh_end register_cvar("Happy Hour End","22")
    
cvar_multiplier register_cvar("pm_xpmultiplier""2")
    
    
RegisterHam(Ham_Killed"player""fw_playerkilled_post"1)
    
    
set_task180.0"ev_Start", .flags="b" )
}
 
public 
ev_Start( )  
{  
    new 
data];
    
get_time"%H" data charsmaxdata ) );
    
    if ( 
get_pcvar_num(cvar_hh_end) > str_to_numdata ) >= get_pcvar_numcvar_hh_start ) )
    {
        
g_happytime true;
        
client_printprint_chat"Happy Hour is Active! Double XP per Kill")
    }
}
 
public 
fw_playerkilled_post(victimattacker)
{
    if( ( 
victim == attacker ) || !is_user_connectedattacker ) )
        return 
HAM_IGNORED;
    
    if ( 
g_happytime 
    { 
        new 
xp = ( ( Poke_PlayerLevelvictim, -) ) * get_pcvar_numcvar_multiplier ) )
        
        
Poke_Give_XPattacker , -xp );
    }
    else
    {
        
g_expattacker ]++ // example happyhour off
    
}
    
    return 
HAM_IGNORED;




All times are GMT -4. The time now is 14:49.

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