Sell Weapons

reapi Sell Weapons 1.0

Нет прав для скачивания
Автор
Ruby
Исходный код
Код:
new const Plugin_Name[ ] = "Sell Weapons";
new const Plugin_Version[ ] = "1.0";
new const Plugin_Author[ ] = "Ruby";

#include <amxmodx>
#include <reapi>

#define IsDefaultWeapon(%0)                        bool: ( get_entvar( %0, var_impulse ) == 0 )

new const Dictionary_File[ ] = "sell_weapons.txt";
new const Config_File[ ] = "sell_weapons";

new g_pCvar_MaxMoney,
    g_pCvar_BuyTime,
    g_pCvar_Price,
    g_iMaxMoney,
    Float: g_flBuyTime,
    Float: g_flPrice;

public plugin_init( )
{
    register_plugin( Plugin_Name, Plugin_Version, Plugin_Author );

    register_event( "StatusIcon", "Event__StatusIcon", "be", "1=1", "2=buyzone" );
    RegisterHookChain( RG_CBasePlayer_ImpulseCommands, "RG_CBasePlayer__ImpulseCommands_Pre", false );

    bind_pcvar_float( ( g_pCvar_Price = create_cvar( "sw_sale_price", "0.5", FCVAR_NONE, "The amount for which the sale will be made (weapon cost * cvar = sale price) (0.5 = 50% of the cost of the weapon)" ) ), g_flPrice );
    hook_cvar_change( ( g_pCvar_MaxMoney = get_cvar_pointer( "mp_maxmoney" ) ), "HookCvarsChange" );
    hook_cvar_change( ( g_pCvar_BuyTime = get_cvar_pointer( "mp_buytime" ) ), "HookCvarsChange" );
    hook_cvar_change( g_pCvar_Price, "HookCvarsChange" );
    g_iMaxMoney = get_pcvar_num( g_pCvar_MaxMoney );
    g_flBuyTime = get_pcvar_float( g_pCvar_BuyTime );

    register_dictionary( Dictionary_File );
    AutoExecConfig( .name = Config_File );
}

public Event__StatusIcon( const pPlayer )
{
    if ( !is_user_alive( pPlayer ) || rg_buytime_expired( ) || g_flPrice <= 0.0 )
        return;

    client_print_color( pPlayer, print_team_default, "%l %l", "ML_Prefix", "ML_Info" );
}

public RG_CBasePlayer__ImpulseCommands_Pre( const pPlayer )
{
    if ( !is_user_alive( pPlayer ) || !rg_get_user_buyzone( pPlayer ) || rg_buytime_expired( ) || g_flPrice <= 0.0 )
        return;

    if ( get_entvar( pPlayer, var_impulse ) != 201 || ~get_entvar( pPlayer, var_button ) & IN_USE )
        return;

    static pActiveItem; pActiveItem = get_member( pPlayer, m_pActiveItem );
    if ( is_nullent( pActiveItem ) || !IsDefaultWeapon( pActiveItem ) )
        return;

    static iCost; iCost = rg_get_weapon_info( get_member( pActiveItem, m_iId ), WI_COST );
    if ( iCost <= 0 )
    {
        client_print_color( pPlayer, print_team_default, "%l %l", "ML_Prefix", "ML_NotForSale" );
        return;
    }

    if ( get_member( pPlayer, m_iAccount ) >= g_iMaxMoney )
    {
        client_print_color( pPlayer, print_team_default, "%l %l", "ML_Prefix", "ML_MaxMoney" );
        return;
    }

    static szWeaponName[ 24 ]; rg_get_iteminfo( pActiveItem, ItemInfo_pszName, szWeaponName, charsmax( szWeaponName ) );
    rg_add_account( pPlayer, ( iCost = floatround( iCost * g_flPrice ) ) );
    rg_remove_item( pPlayer, szWeaponName );

    client_print_color( pPlayer, print_team_default, "%l %l", "ML_Prefix", "ML_Selling", iCost );
}

public HookCvarsChange( const pCvar, const szOldValue[ ], const szNewValue[ ] )
{
    if ( pCvar == g_pCvar_MaxMoney )
        g_iMaxMoney = str_to_num( szNewValue );
    else if ( pCvar == g_flBuyTime )
        g_flBuyTime = str_to_float( szNewValue );
    else if ( pCvar == g_pCvar_Price )
        g_flPrice = str_to_float( szNewValue );
}

stock bool: rg_buytime_expired( )
{
    if ( g_flBuyTime == -1.0 )
        return false;

    return bool: ( g_flBuyTime == 0.0 || ( get_gametime( ) - Float: get_member_game( m_fRoundStartTime ) > ( g_flBuyTime * 60 ) ) );
}

stock bool: rg_get_user_buyzone( const pPlayer )
{
    new iSignals[ UnifiedSignals ]; get_member( pPlayer, m_signals, iSignals );
    return bool: ( SignalState: iSignals[ US_State ] & SIGNAL_BUY );
}
Требования
ReAPI
Требование ReAPI
Да
Поддержка русского языка
Да
Совместимость
  1. REHLDS
Сверху Снизу