Правила форума Гаранты форума
Размещение рекламы AMX-X компилятор

Здравствуйте, гость Вход | Регистрация

Наши новости:

14-дек
24-апр
10-апр
11-апр

помогите изменить игровую валюту

, редактировать плагин
Статус пользователя nokia2730
сообщение 17.8.2019, 19:44
Сообщение #1
Стаж: 7 лет 11 месяцев

Сообщений: 19
Благодарностей: 1
Полезность: 0

Здраствуйте
У меня есть 2 плагин.

1) Первый - новая игровая валюта (добавляет новую игровую валюту на сервере)
2) Второй - меню покупки оружия за стандартные деньги в игре

А я хочу сделать чтоб оружие покупалось за ту валюту которую я нашел на просторах интернета.
Вот и не знаю как это реализовать.
Буду очень благодарен (если подскажете или сделаете)

код игровой валюты
Cкрытый текст
Код
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
#include < sqlx >


#define MAX_CLIENTS        32
#define TASK_LOAD_DATA    12352

#if defined ZP_SUPPORT
#include < zombieplague >
#endif

// CBasePlayer
#define m_iAccount        115

// CBaseMonster
#define m_LastHitGroup    75

#define FLAG_VIP        ADMIN_LEVEL_A // Флаг для VIP игрока

#define LIMIT_USER        32000 // Максимальное кол-во денег у обычного игрока
#define LIMIT_VIP        64000 // Максимальное кол-во денег у VIP игрока

#define MONEY_START        1000 // Деньги при старте (если игрок зашёл первый раз на сервер)
#define MONEY_HEAD        random_num( 50, 55 ) // Деньги при попадании в голову
#define MONEY_CHEST        random_num( 30, 35 ) // Деньги при попадании в грудь
#define MONEY_STOMACH    25 // Деньги при попадании в живот
#define MONEY_ARM        random_num( 15, 17 ) // Деньги при попадании в руки
#define MONEY_LEG        random_num( 7, 10 ) // Деньги при попадании в ноги
#define MONEY_KILL        150 // Деньги за убийство

new g_iMsgID_Money;
new g_iMoney[ MAX_CLIENTS +1 ];

new bool: g_bUserLoaded[ MAX_CLIENTS +1 ];

new g_szUserSteamID[ MAX_CLIENTS +1 ][ 34 ];
new g_szQuery[ 512 ];

new Handle: g_hDBTuple;
new Handle: g_hConnect;

#define SQL_HOST        ""
#define SQL_USER        ""
#define SQL_PASSWORD    ""
#define SQL_DATABASE    ""
#define SQL_TABLENAME    "amxx_money_system"

public plugin_init( )
{
    register_plugin( "[AMXX] Money System", "Best", "t3rkecorejz" );
    
    register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" );
    
    g_iMsgID_Money = get_user_msgid( "Money" );
    
    register_message( g_iMsgID_Money, "MSG_Money" );
    
    RegisterHam( Ham_Spawn, "player", "CPlayer__Spawn_Post", .Post = 1 );
    RegisterHam( Ham_Killed, "player", "CPlayer__Killed_Post", .Post = 1 );
    RegisterHam( Ham_TakeDamage, "player", "CPlayer__TakeDamage_Post", .Post = 1 );
}

public plugin_natives( )
{
    register_native( "GetUserMoney", "native_get_money", 1 );
    register_native( "SetUserMoney", "native_set_money", 1 );
}

public plugin_cfg( ) SQL_LoadDebug( );
public plugin_end( )
{
    if( g_hDBTuple )
        SQL_FreeHandle( g_hDBTuple );
    
    if( g_hConnect )
        SQL_FreeHandle( g_hConnect );
    
    return;
}

public client_putinserver( iPlayer ) set_task( random_float( 1.0, 3.0 ), "CTask__LoadData", iPlayer +TASK_LOAD_DATA );
public client_disconnect( iPlayer )
{
    if( !g_bUserLoaded[ iPlayer ] )
        return;
    
    formatex( g_szQuery, charsmax( g_szQuery ), "UPDATE `%s` SET `Money` = '%d' WHERE `%s`.`SteamID` = '%s';", SQL_TABLENAME, g_iMoney[ iPlayer ], SQL_TABLENAME, g_szUserSteamID[ iPlayer ] );
    SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery );
}

// Events
public EV_RoundStart( )
{
    for( new iPlayer = 1; iPlayer <= MAX_CLIENTS; iPlayer++ )
    {
        if( !is_user_connected( iPlayer ) )
            continue;
        
        if( !g_bUserLoaded[ iPlayer ] )
            return;
        
        formatex( g_szQuery, charsmax( g_szQuery ), "UPDATE `%s` SET `Money` = '%d' WHERE `%s`.`SteamID` = '%s';", SQL_TABLENAME, g_iMoney[ iPlayer ], SQL_TABLENAME, g_szUserSteamID[ iPlayer ] );
        SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery );
    }
}

// Messages
public MSG_Money( MsgID, MSG_DEST, iEntity )
{
    new iMoney = g_iMoney[ iEntity ];
    
    set_msg_arg_int( 1, ARG_LONG, iMoney );
    set_pdata_int( iEntity, m_iAccount, iMoney, 5 );
}

// Ham
public CPlayer__Spawn_Post( iPlayer )
{
    if( !is_user_alive( iPlayer ) )
        return;
    
    set_pdata_int( iPlayer, m_iAccount, g_iMoney[ iPlayer ], 5 );
    UTIL_Money( iPlayer, g_iMoney[ iPlayer ], 0 );
}

public CPlayer__Killed_Post( iVictim, iAttacker, iGib )
{
    if( !is_user_connected( iVictim ) || !is_user_connected( iAttacker ) || iVictim == iAttacker )
        return;
    
    #if defined ZP_SUPPORT
    if( zp_get_user_zombie( iAttacker ) )
        return;
    #endif
    
    if( pev_valid( iAttacker ) == 2 )
    {
        set_pdata_int( iAttacker, m_iAccount, g_iMoney[ iAttacker ], 5 );
        UTIL_Money( iAttacker, g_iMoney[ iAttacker ], 0 );
    }
    
    Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_KILL );
}

public CPlayer__TakeDamage_Post( iVictim, iInflictor, iAttacker, Float: flDamage )
{
    if( !is_user_connected( iVictim ) || !is_user_connected( iAttacker ) || iVictim == iAttacker )
        return;
    
    #if defined ZP_SUPPORT
    if( zp_get_user_zombie( iAttacker ) )
        return;
    #endif
    
    switch( get_pdata_int( iVictim, m_LastHitGroup, 5 ) )
    {
        case HIT_HEAD: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_HEAD );
        case HIT_CHEST: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_CHEST );
        case HIT_STOMACH: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_STOMACH );
        case HIT_LEFTARM, HIT_RIGHTARM: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_ARM );
        case HIT_LEFTLEG, HIT_RIGHTLEG: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_LEG );
    }
}

// Task
public CTask__LoadData( iTask )
{
    new iPlayer = iTask -TASK_LOAD_DATA;
    
    if( !is_user_connected( iPlayer ) )
        return;
    
    new iParams[ 1 ];
    iParams [ 0 ] = iPlayer;
    
    get_user_authid( iPlayer, g_szUserSteamID[ iPlayer ], charsmax( g_szUserSteamID[ ] ) );
    
    formatex( g_szQuery, charsmax( g_szQuery ), "SELECT * FROM `%s` WHERE ( `%s`.`SteamID` = '%s' )", SQL_TABLENAME, SQL_TABLENAME, g_szUserSteamID[ iPlayer ] );
    SQL_ThreadQuery( g_hDBTuple, "SQL_QueryConnection", g_szQuery, iParams, sizeof iParams );
}

// MySQL
public SQL_LoadDebug( )
{
    new szError[ 512 ];
    new iErrorCode;
    
    g_hDBTuple = SQL_MakeDbTuple( SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_DATABASE );
    g_hConnect = SQL_Connect( g_hDBTuple, iErrorCode, szError, charsmax( szError ) );
    
    if( g_hConnect == Empty_Handle )
        set_fail_state( szError );
    
    if( !SQL_TableExists( g_hConnect, SQL_TABLENAME ) )
    {
        new Handle: hQueries;
        new szQuery[ 512 ];
        
        formatex( szQuery, charsmax( szQuery ), "CREATE TABLE IF NOT EXISTS `%s` ( SteamID varchar( 32 ) CHARACTER SET cp1250 COLLATE cp1250_general_ci NOT NULL, Money INT NOT NULL, PRIMARY KEY ( SteamID ) )", SQL_TABLENAME );
        hQueries = SQL_PrepareQuery( g_hConnect, szQuery );
        
        if( !SQL_Execute( hQueries ) )
        {
            SQL_QueryError( hQueries, szError, charsmax( szError ) );
            set_fail_state( szError );
        }
        SQL_FreeHandle( hQueries );    
    }
    SQL_QueryAndIgnore( g_hConnect, "SET NAMES utf8" );
}

public SQL_QueryConnection( iState, Handle: hQuery, szError[ ], iErrorCode, iParams[ ], iParamsSize )
{
    switch( iState )
    {
        case TQUERY_CONNECT_FAILED: log_amx( "Load - Could not connect to SQL database. [%d] %s", iErrorCode, szError );
        case TQUERY_QUERY_FAILED: log_amx( "Load Query failed. [%d] %s", iErrorCode, szError );
    }
    
    new iPlayer = iParams[ 0 ];
    g_bUserLoaded[ iPlayer ] = true;
    
    if( SQL_NumResults( hQuery ) < 1 )
    {
        if( equal( g_szUserSteamID[ iPlayer ], "ID_PENDING" ) )
            return PLUGIN_HANDLED;

        g_iMoney[ iPlayer ] = MONEY_START;

        formatex( g_szQuery, charsmax( g_szQuery ), "INSERT INTO `%s` ( `SteamID`, `Money` ) VALUES ( '%s', '%d' );", SQL_TABLENAME, g_szUserSteamID[ iPlayer ], g_iMoney[ iPlayer ] );
        SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery );
        
        return PLUGIN_HANDLED;
    }
    else Native_SetUserMoney( iPlayer, SQL_ReadResult( hQuery, 1 ) );
    
    return PLUGIN_HANDLED;
}

public SQL_ThreadQueryHandler( iState, Handle: hQuery, szError[ ], iErrorCode, iParams[ ], iParamsSize )
{
    if( iState == 0 )
        return;
    
    log_amx( "SQL Error: %d (%s)", iErrorCode, szError );
}

// Natives
Native_SetUserMoney( iPlayer, iAmount, iFlash = 1 )
{
    if( pev_valid( iPlayer ) != 2 )
        return;
    
    static iMax;
    
    if( get_user_flags( iPlayer ) & FLAG_VIP ) iMax = LIMIT_VIP;
    else iMax = LIMIT_USER;
    
    if( iAmount > iMax )
    {
        g_iMoney[ iPlayer ] = iMax;
        
        set_pdata_int( iPlayer, m_iAccount, iMax, 5 );
        UTIL_Money( iPlayer, iMax, 0 );
        
        return;
    }
    
    g_iMoney[ iPlayer ] = iAmount;
    
    set_pdata_int( iPlayer, m_iAccount, iAmount, 5 );
    UTIL_Money( iPlayer, iAmount, iFlash );
}

public native_set_money( iPlayer, iValue )
    Native_SetUserMoney( iPlayer, iValue );

public native_get_money( iPlayer )
    return g_iMoney[ iPlayer ];

// Stocks
stock UTIL_Money( iPlayer, iAmount, iFlash )
{
    message_begin( MSG_ONE, g_iMsgID_Money, _, iPlayer );
    write_long( iAmount );
    write_byte( iFlash );
    message_end( );
}

stock bool: SQL_TableExists( Handle: hDataBase, const szTable[ ] )
{
    new Handle: hQuery = SQL_PrepareQuery( hDataBase, "SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;", szTable );
    new szError[ 512 ];
    
    if( !SQL_Execute( hQuery ) )
    {
        SQL_QueryError( hQuery, szError, charsmax( szError ) );
        set_fail_state( szError );
    }
    else if( !SQL_NumResults( hQuery ) )
    {
        SQL_FreeHandle( hQuery );
        return false;
    }
    SQL_FreeHandle( hQuery );
    return true;
}





код самого плагина (покупки оружия)
Cкрытый текст
Код
    #include AmxModX
    #include FakeMeta
    #include HamSandwich
    
    //cmd callback - команда вызова
    new const g_szCmdCallback[][] = {
        "say /shop",
        "say_team /shop",
        "say /shopmenu",
        "say_team /shopmenu",
        "nightvision" //хук кнопки <<N>>
    };
    
    // Dir setting
    #define MODEL_DIR                "models/shop_skin/%s.mdl"
    #define CFG_DIR                    "%s/shop_skin_system"                         //addons/amxmodx/configs/
    #define CFG_DIR_BLOCKS            "%s/shop_skin_system/sss_block_maps.ini"    //addons/amxmodx/configs/
    #define CFG_DIR_SETTING            "%s/shop_skin_system/sss_setting.ini"        //addons/amxmodx/configs/
    #define CFG_DIR_MENU            "%s/shop_skin_system/sss_weapons.ini"        //addons/amxmodx/configs/
    
    /// OFFSET: CWeaponBox
    #define m_rgpPlayerItems_CWeaponBox 34

    /// Структуры (Перечеслительные)
    #define DROP:: DropType_
    enum eData_DropType {
        DROP::PRIMARY,
        DROP::SECONDARY
    };
    
    enum eData_ModelId {
        V,
        P
    };
    
    enum eData_Skins {
        WEAPON_NAME[ 32 ],
        WEAPON_COST,
        MODEL_ID[ eData_ModelId ],
        MODEL_ID_W[ 45 ],
        WEAPON_ACCESS,
        eData_DropType: WEAPON_DROP_TYPE,
        WEAPON_ANCESTOR[ 16 ],
        WEAPON_ACCESS_NO[ 32 ]    
    };
    
    //array
    new Array: g_aMenuItemAll, Array: g_aMenuItemVip, Array: g_aMenuItemAdmin, g_iSkinMax[ 3 ];
    
    //player pointer
    new g_iUserMenuType[ 33 ], g_iMenuPosition[ 33 ];
    
    /// const
    #define WEAPON_KEY 6162621
    
    //weapon class name
    new const g_szWeaponName[][] =
    {
        "weapon_p228", "weapon_scout", "weapon_xm1014", "weapon_mac10", "weapon_aug",
        "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550", "weapon_galil",
        "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy",
        "weapon_m249", "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1",
        "weapon_deagle", "weapon_sg552", "weapon_ak47", "weapon_p90"
    };

    //setting
    new g_szPluginPrefix[ 64 ], bool: g_bShopEnable[ 3 ], g_iBitMenuAccess[ 2 ], g_szShopMenuName[ 3 ][ 64 ], g_szMapWeapon[ 16 ] = "all", g_szPluginChatPrefix[ 32 ],
        g_iTimeBuy, bool: g_bBuyStatus = true, g_iMaxPlayers;
    
    /// func
    public plugin_precache()
    {
        g_aMenuItemAll = ArrayCreate( eData_Skins );
        g_aMenuItemVip = ArrayCreate( eData_Skins );
        g_aMenuItemAdmin = ArrayCreate( eData_Skins );
        
        new szCfgFile[ 128 ], szCfgDir[ 64 ];
        get_localinfo( "amxx_configsdir", szCfgDir, charsmax( szCfgDir ) );
        formatex( szCfgFile, charsmax( szCfgFile ), CFG_DIR, szCfgDir );        
        if( !dir_exists( szCfgFile ) ) {
            new szLogs[ 128 ]; format( szLogs, charsmax( szLogs ), "[Shop Skin System]: Dir ^"%s^" not exists.", szCfgFile );
            DestroyArrayById(); set_fail_state( szLogs ); return;
        }
        
        formatex( szCfgFile, charsmax( szCfgFile ), CFG_DIR_SETTING, szCfgDir );
        if( !file_exists( szCfgFile ) ) {
            new szLogs[ 128 ]; format( szLogs, charsmax( szLogs ), "[Shop Skin System]: File ^"%s^" not exists.", szCfgFile );
            DestroyArrayById(); set_fail_state( szLogs ); return;
        }
        else
            LoadSetting( szCfgFile );
        
        formatex( szCfgFile, charsmax( szCfgFile ), CFG_DIR_BLOCKS, szCfgDir );
        if( !file_exists( szCfgFile ) ) {
            new szLogs[ 128 ]; format( szLogs, charsmax( szLogs ), "[Shop Skin System]: File ^"%s^" not exists.", szCfgFile );
            DestroyArrayById(); set_fail_state( szLogs ); return;
        }
        else
            LoadBlocks( szCfgFile );
        
        formatex( szCfgFile, charsmax( szCfgFile ), CFG_DIR_MENU, szCfgDir );
        if( !file_exists( szCfgFile ) ) {
            new szLogs[ 128 ]; format( szLogs, charsmax( szLogs ), "[Shop Skin System]: File ^"%s^" not exists.", szCfgFile );
            DestroyArrayById(); set_fail_state( szLogs ); return;
        }
        
        // for file
        new szBuffer[ 256 ], iLen, iLine;
        // образ
        new aDataSkins[ eData_Skins ], szCost[ 18 ], szAccess[ 18 ], szDropType[ 18 ], szModels[ 2 ][ 32 ], szShopId[ 16 ];
        // read file
        while( read_file( szCfgFile, iLine++, szBuffer, charsmax( szBuffer ), iLen ) ) {
            if( szBuffer[ 0 ] == '"' ) {
                parse( szBuffer,
                    aDataSkins[ WEAPON_NAME ], charsmax( aDataSkins[ WEAPON_NAME ] ),
                    szCost, charsmax( szCost ),
                    szModels[ 0 ], charsmax( szModels[] ),
                    szModels[ 1 ], charsmax( szModels[] ),
                    aDataSkins[ MODEL_ID_W ], charsmax( aDataSkins[ MODEL_ID_W ] ),
                    szDropType, charsmax( szDropType ),
                    aDataSkins[ WEAPON_ANCESTOR ], charsmax( aDataSkins[ WEAPON_ANCESTOR ] ),
                    szAccess, charsmax( szAccess ),
                    aDataSkins[ WEAPON_ACCESS_NO ], charsmax( aDataSkins[ WEAPON_ACCESS_NO ] ),
                    szShopId, charsmax( szShopId ) );
                
                if( contain( szDropType, "2" ) != -1 )
                    aDataSkins[ WEAPON_DROP_TYPE ] = DROP::SECONDARY; else aDataSkins[ WEAPON_DROP_TYPE ] = DROP::PRIMARY;
                
                format( szBuffer, charsmax( szBuffer ), "weapon_%s", aDataSkins[ WEAPON_ANCESTOR ] );
                copyc( aDataSkins[ WEAPON_ANCESTOR ], charsmax( aDataSkins[ WEAPON_ANCESTOR ] ), szBuffer, strlen( aDataSkins[ WEAPON_ANCESTOR ] ) );
                
                for( new i = 0; i < sizeof( g_szWeaponName ); i++ ) {
                    if( equal( g_szWeaponName[ i ], aDataSkins[ WEAPON_ANCESTOR ] ) )
                        i = 999;
                    
                    switch( i ) {
                        case 999:
                            goto ForExit;
                            
                        case ( sizeof( g_szWeaponName ) ):
                            set_fail_state( "[ShopSkinSystem]: Error Weapon Ancestor not valid!" );
                    }                    
                }
                
                ForExit: {
                    format( szBuffer, charsmax( szBuffer ), MODEL_DIR, aDataSkins[ MODEL_ID_W ] );
                    copyc( aDataSkins[ MODEL_ID_W ], charsmax( aDataSkins[ MODEL_ID_W ] ), szBuffer, strlen( aDataSkins[ MODEL_ID_W ] ) );
                    engfunc( EngFunc_PrecacheModel, aDataSkins[ MODEL_ID_W ] );
                    
                    while( replace( szCost, charsmax( szCost ), " ", "" ) ) {}
                    replace( szCost, charsmax( szCost ), ":", "" );
                    replace( szCost, charsmax( szCost ), "$", "" );
                    replace( szCost, charsmax( szCost ), "cost", "" );    
                    aDataSkins[ WEAPON_COST ] = str_to_num( szCost );
                    
                    if( contain( szAccess, "none" ) != -1 )
                        aDataSkins[ WEAPON_ACCESS ] = 0;
                    else {
                        while( replace( szAccess, charsmax( szAccess ), " ", "" ) ) {}
                        replace( szAccess, charsmax( szAccess ), ":", "" );
                        replace( szAccess, charsmax( szAccess ), "access", "" );                        
                        aDataSkins[ WEAPON_ACCESS ] = read_flags( szAccess );
                    }
                    
                    #define PrecacheFileFromId(%1,%2) ((format(szBuffer,charsmax(szBuffer),MODEL_DIR,szModels[%1])),(engfunc(EngFunc_PrecacheModel,szBuffer)),(aDataSkins[MODEL_ID][%2]=engfunc(EngFunc_AllocString,szBuffer)))            
                    PrecacheFileFromId( 0, P );    
                    PrecacheFileFromId( 1, V ); UTIL_PrecacheSoundsFromModel( szBuffer );                        
                    #undef PrecacheFileFromId
                    
                    if( equal( szShopId, "ADMIN" ) )
                        ArrayPushArray( g_aMenuItemAdmin, aDataSkins );
                    else if( equal( szShopId, "VIP" ) )
                        ArrayPushArray( g_aMenuItemVip, aDataSkins );
                    else
                        ArrayPushArray( g_aMenuItemAll, aDataSkins );            
                }
            }
        }
        g_iSkinMax[ 0 ] = ArraySize( g_aMenuItemAll ) - 1;
        g_iSkinMax[ 1 ] = ArraySize( g_aMenuItemVip ) - 1;
        g_iSkinMax[ 2 ] = ArraySize( g_aMenuItemAdmin ) - 1;
    }

    LoadSetting( const szSettingFile[] )
    {
        new szBuffer[ 128 ], iLen, iLine, szNull[ 1 ];
        while( read_file( szSettingFile, iLine++, szBuffer, charsmax( szBuffer ), iLen ) ) {
            if( !iLen || szBuffer[ 0 ] == ';' )
                continue;
            
            if( szBuffer[ 0 ] == '$' ) {
                //префикс в меню
                if( contain( szBuffer, "$PREFIX_MENU" ) != -1 ) {
                    parse( szBuffer, szNull, charsmax( szNull ), szBuffer, charsmax( szBuffer ) );        
                    remove_quotes( szBuffer ); copy( g_szPluginPrefix, charsmax( g_szPluginPrefix ), szBuffer );                
                }
                //префикс в чате
                if( contain( szBuffer, "$PREFIX_CHAT" ) != -1 ) {
                    parse( szBuffer, szNull, charsmax( szNull ), szBuffer, charsmax( szBuffer ) );    
                    remove_quotes( szBuffer ); copy( g_szPluginChatPrefix, charsmax( g_szPluginChatPrefix ), szBuffer );
                }
                //название магазина
                {
                    //общий
                    if( contain( szBuffer, "$SHOP_ALL_NAME" ) != -1 ) {
                        parse( szBuffer, szNull, charsmax( szNull ), szBuffer, charsmax( szBuffer ) );    
                        remove_quotes( szBuffer ); copy( g_szShopMenuName[ 0 ], charsmax( g_szShopMenuName[] ), szBuffer );
                    }
                    //vip
                    if( contain( szBuffer, "$SHOP_VIP_NAME" ) != -1 ) {
                        parse( szBuffer, szNull, charsmax( szNull ), szBuffer, charsmax( szBuffer ) );    
                        remove_quotes( szBuffer ); copy( g_szShopMenuName[ 1 ], charsmax( g_szShopMenuName[] ), szBuffer );
                    }
                    //admin
                    if( contain( szBuffer, "$SHOP_ADMIN_NAME" ) != -1 ) {
                        parse( szBuffer, szNull, charsmax( szNull ), szBuffer, charsmax( szBuffer ) );    
                        remove_quotes( szBuffer ); copy( g_szShopMenuName[ 2 ], charsmax( g_szShopMenuName[] ), szBuffer );
                    }
                }
                //включён магазин или нет
                {
                    if( ( contain( szBuffer, "$ALL_SHOP" ) != -1 ) && contain( szBuffer, "ON" ) != -1 )
                        g_bShopEnable[ 0 ] = true;
                        
                    if( ( contain( szBuffer, "$VIP_SHOP" ) != -1 ) && contain( szBuffer, "ON" ) != -1 )
                        g_bShopEnable[ 1 ] = true;
                        
                    if( ( contain( szBuffer, "$ADMIN_SHOP" ) != -1 ) && contain( szBuffer, "ON" ) != -1 )
                        g_bShopEnable[ 2 ] = true;
                }
                //флаги доступа
                {
                    if( ( contain( szBuffer, "$VIP_ACCESS" ) != -1 ) ) {
                        replace( szBuffer, charsmax( szBuffer ), "$VIP_ACCESS", "" );
                        while( replace( szBuffer, charsmax( szBuffer ), " ", "" ) ) {}
                        remove_quotes( szBuffer );
                        g_iBitMenuAccess[ 0 ] = read_flags( szBuffer );
                    }
                    if( ( contain( szBuffer, "$ADMIN_ACCESS" ) != -1 ) ) {
                        replace( szBuffer, charsmax( szBuffer ), "$ADMIN_ACCESS", "" );
                        while( replace( szBuffer, charsmax( szBuffer ), " ", "" ) ) {}
                        remove_quotes( szBuffer );
                        g_iBitMenuAccess[ 1 ] = read_flags( szBuffer );
                    }
                }
                //время покупки
                if( contain( szBuffer, "$TIME_BUY_MENU" ) != -1 ) {
                    parse( szBuffer, szNull, charsmax( szNull ), szBuffer, charsmax( szBuffer ) );    
                    remove_quotes( szBuffer );
                    
                    if( equal( szBuffer, "unlimit" ) ) {
                        g_iTimeBuy = 0;
                        g_bBuyStatus = true;
                    }
                    else
                        g_iTimeBuy = str_to_num( szBuffer );    
                }
            }
        }
    }
    
    LoadBlocks( const szBlockMapsFile[] )
    {
        new szMapName[ 35 ]; get_mapname( szMapName, charsmax( szMapName ) );
        new szBuffer[ 128 ], iLen, iLine;
        while( read_file( szBlockMapsFile, iLine++, szBuffer, charsmax( szBuffer ), iLen ) ) {
            if( !iLen || szBuffer[ 0 ] == ';' )
                continue;
                
            if( contain( szBuffer, szMapName ) != -1 ) {
                replace( szBuffer, charsmax( szBuffer ), szMapName, "" );
                while( replace( szBuffer, charsmax( szBuffer ), " ", "" ) ) {} remove_quotes( szBuffer );
                copy( g_szMapWeapon, charsmax( g_szMapWeapon ), szBuffer ); break;
            }    
        }
    }
    
    public plugin_init()
    {
        register_plugin( "Shop Skin System", "vk/krisiso", "ToJI9IHGaa/Batcon & t3rkecorejz" );
        
        register_menucmd( register_menuid( "Show_ShopMenu" ), ( 1<<0|1<<1|1<<2|1<<9 ), "Handle_ShopMenu" );
        register_menucmd( register_menuid( "Show_ExtraShop" ), 1023, "Handle_ExtraShop" );
        
        for( new iPos; iPos <= sizeof g_szCmdCallback - 1; iPos++ )
            register_clcmd( g_szCmdCallback[ iPos ], "ClCmd_ShopMenu" );
        
        register_forward( FM_SetModel, "FakeMeta_SetModel" );
        for( new i = 0; i < sizeof( g_szWeaponName ); i++ )
            RegisterHam( Ham_Item_Deploy, g_szWeaponName[ i ], "Ham_ItemDeploy_Post", true );
            
        if( g_iTimeBuy )
            register_event( "HLTV", "Event_HLTV", "a", "1=0", "2=0" );
            
        g_iMaxPlayers = get_maxplayers();
    }
    
    public FakeMeta_SetModel( iEntity )
    {
        static szClassname[ 32 ]; pev( iEntity, pev_classname, szClassname, charsmax( szClassname ) );
        if( !equal( szClassname, "weaponbox" ) )
            return FMRES_IGNORED;
        
        static i, iItem;
        for( i = 0; i < 6; i++ ) {
            if( ( iItem = get_pdata_cbase( iEntity, m_rgpPlayerItems_CWeaponBox + i, 4 ) ) > 0 && CustomItem( iItem ) ) {
                new aData[ eData_Skins ]; GetArrayById( pev( iItem, pev_iuser2 ), pev( iItem, pev_iuser1 ), aData );
                engfunc( EngFunc_SetModel, iEntity, aData[ MODEL_ID_W ] );
                return FMRES_SUPERCEDE;
            }
        }
        
        return FMRES_IGNORED;
    }
    
    public Ham_ItemDeploy_Post( iEntity )
    {
        if( !CustomItem( iEntity ) )
            return;
        
        new pId = pev( iEntity, pev_owner );
        new aData[ eData_Skins ]; GetArrayById( pev( iEntity, pev_iuser2 ), pev( iEntity, pev_iuser1 ), aData );
        set_pev_string( pId, pev_viewmodel2, aData[ MODEL_ID ][ V ] );
        set_pev_string( pId, pev_weaponmodel2, aData[ MODEL_ID ][ P ] );
    }
    
    public ClCmd_ShopMenu( pId )
    {
        if( equal( g_szMapWeapon, "none" ) ) {
            UTIL_SayText( pId, "Простите, но на данной карте магазин !gзакрыт." );
            return PLUGIN_HANDLED;
        }
        if( !g_bBuyStatus && g_iTimeBuy ) {
            UTIL_SayText( pId, "Простите, но время закупки !gпрошло. !t(%d секунд)", g_iTimeBuy );
            return PLUGIN_HANDLED;
        }
        Show_ShopMenu( pId );
        return PLUGIN_HANDLED;
    }
    
    Show_ShopMenu( pId )
    {
        new szMenu[ 512 ], iKeys = ( 1<<9 ), iBitUserFlags = get_user_flags( pId ),
        iLen = formatex( szMenu, charsmax( szMenu ), "%s \yShop Skin System^n", g_szPluginPrefix );
        if( g_iTimeBuy )
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "%s Время покупки: \r%d секунд^n^n", g_szPluginPrefix, g_iTimeBuy );
        else
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "%s Время покупки: \rНеограниченно^n^n", g_szPluginPrefix );
        
        if( g_bShopEnable[ 0 ] ) {
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r1. \w%s^n", g_szShopMenuName[ 0 ] );
            iKeys |= ( 1<<0 );
        }
        else
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\d1. \d%s \r[Закрыт]^n", g_szShopMenuName[ 0 ] );
        
        if( g_bShopEnable[ 1 ] ) {
            iKeys |= ( 1<<1 );
            if( iBitUserFlags & g_iBitMenuAccess[ 0 ] )
                iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r2. \w%s^n", g_szShopMenuName[ 1 ] );
            else
                iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\d2. %s^n", g_szShopMenuName[ 1 ] );
        }
        else
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\d2. %s \r[Закрыт]^n", g_szShopMenuName[ 1 ] );
        
        if( g_bShopEnable[ 2 ] ) {
            iKeys |= ( 1<<2 );
            if( iBitUserFlags & g_iBitMenuAccess[ 1 ] )
                iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r3. \w%s^n", g_szShopMenuName[ 2 ] );
            else
                iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\d3. %s^n", g_szShopMenuName[ 2 ] );
        }
        else
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\d3. %s \r[Закрыт]^n", g_szShopMenuName[ 2 ] );
        
        

        formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "^n\r0. \wВыход" );    
        return show_menu( pId, iKeys, szMenu, g_iTimeBuy ? g_iTimeBuy : -1, "Show_ShopMenu" );
    }
    
    public Handle_ShopMenu( pId, iKey )
    {
        switch( iKey ) {
            case 0:
                return Show_ExtraShop( pId, g_iMenuPosition[ pId ] = 0, g_iUserMenuType[ pId ] = 0 );
            case 1:
                return Show_ExtraShop( pId, g_iMenuPosition[ pId ] = 0, g_iUserMenuType[ pId ] = 1 );
            case 2:
                return Show_ExtraShop( pId, g_iMenuPosition[ pId ] = 0, g_iUserMenuType[ pId ] = 2 );
        }
        return PLUGIN_HANDLED;
    }
    
    const PLAYERS_PER_PAGE = 8;
    Show_ExtraShop( pId, iPos, iItemId )
    {
        if( iPos < 0 )
            return PLUGIN_HANDLED;
        
        if( !g_bBuyStatus ) {
            UTIL_SayText( pId, "Простите, но время закупки !gпрошло. !t(%d секунд)", g_iTimeBuy );
            return PLUGIN_HANDLED;
        }
        
        new iStart = iPos * PLAYERS_PER_PAGE, iSize = g_iSkinMax[ iItemId ];
        if( iStart > iSize )
            iStart = iSize;
        
        iStart = iStart - ( iStart % 8 );
        g_iMenuPosition[ pId ] = iStart / PLAYERS_PER_PAGE;
        
        new iEnd = iStart + PLAYERS_PER_PAGE;
        if( iEnd > iSize )
            iEnd = iSize + ( iPos ? 0 : 1 );
        
        new szMenu[ 512 ], iLen, iPagesNum = ( iSize / PLAYERS_PER_PAGE + ( ( iSize % PLAYERS_PER_PAGE ) ? 1 : 0 ) );
        iLen = formatex(szMenu, charsmax(szMenu), "%s \w%s \w[%d|%d]^n\R\rЦена:^n^n", g_szPluginPrefix, g_szShopMenuName[ iItemId ], iPos + 1, iPagesNum );
        new iKeys = ( 1<<9 ), b, aData[ eData_Skins ], iBitUserFlags = get_user_flags( pId );
        for( new a = iStart; a < iEnd; a++ ) {            
            GetArrayById( iItemId, a, aData );
            if( equal( g_szMapWeapon, "all" ) ) {
                if( !aData[ WEAPON_ACCESS ] || iBitUserFlags & aData[ WEAPON_ACCESS ] ) {
                    if( GetMoney( pId ) >= aData[ WEAPON_COST ] ) {
                        iKeys |= ( 1<<b );
                        iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \w%s \R\r%d$^n", ++b, aData[ WEAPON_NAME ], aData[ WEAPON_COST ] );
                    }
                    else
                        iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \d%s \R\r%d$^n", ++b, aData[ WEAPON_NAME ], aData[ WEAPON_COST ] );
                }
                else
                    iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \d%s %s^n", ++b, aData[ WEAPON_NAME ], aData[ WEAPON_ACCESS_NO ] );
            }
            else {
                if( contain( aData[ WEAPON_ANCESTOR ], g_szMapWeapon ) != -1 ) {
                    if( !aData[ WEAPON_ACCESS ] || iBitUserFlags & aData[ WEAPON_ACCESS ] ) {
                        if( GetMoney( pId ) >= aData[ WEAPON_COST ] ) {
                            iKeys |= ( 1<<b );
                            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \w%s \R\r%d$^n", ++b, aData[ WEAPON_NAME ], aData[ WEAPON_COST ] );
                        }
                        else
                            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \d%s \R\r%d$^n", ++b, aData[ WEAPON_NAME ], aData[ WEAPON_COST ] );
                    }
                    else
                        iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \d%s %s^n", ++b, aData[ WEAPON_NAME ], aData[ WEAPON_ACCESS_NO ] );
                }
                else
                    iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "\r%d. \w%s \R\r[block map]^n", ++b, aData[ WEAPON_NAME ] );
            }
        }
        
        for( new i = b; i < PLAYERS_PER_PAGE; i++ )
            iLen += formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "^n" );
        
        if( iEnd < iSize ) {
            iKeys |= ( 1<<8 );
            formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "^n\r9. \wДалее^n\r0. \w%s", iPos ? "Назад" : "Выход" );
        }
        else
            formatex( szMenu[ iLen ], charsmax( szMenu ) - iLen, "^n^n\r0. \w%s", iPos ? "Назад" : "Выход" );
        
        return show_menu( pId, iKeys, szMenu, g_iTimeBuy ? g_iTimeBuy : -1, "Show_ExtraShop" );
    }
    
    public Handle_ExtraShop( pId, iKey )
    {
        if( !g_bBuyStatus ) {
            UTIL_SayText( pId, "Простите, но время закупки !gпрошло. !t(%d секунд)", g_iTimeBuy );
            return PLUGIN_HANDLED;
        }
        
        switch( iKey )
        {
            case 8:
                return Show_ExtraShop( pId, ++g_iMenuPosition[ pId ], g_iUserMenuType[ pId ] );
                
            case 9:
                return Show_ExtraShop( pId, --g_iMenuPosition[ pId ], g_iUserMenuType[ pId ] );
                
            default:
            {
                new aData[ eData_Skins ]; GetArrayById( g_iUserMenuType[ pId ], g_iMenuPosition[ pId ] * PLAYERS_PER_PAGE + iKey, aData );
                drop_user_weapons( pId, aData[ WEAPON_DROP_TYPE ] );
                new iEntity = fm_give_item( pId, aData[ WEAPON_ANCESTOR ] );
                if( !pev_valid( iEntity ) )
                    return PLUGIN_HANDLED;
                
                set_pev( iEntity, pev_impulse, iKey + WEAPON_KEY );
                set_pev( iEntity, pev_iuser1, iKey );
                set_pev( iEntity, pev_iuser2, g_iUserMenuType[ pId ] );                
                ExecuteHamB( Ham_Item_AttachToPlayer, iEntity, pId );
                engclient_cmd( pId, aData[ WEAPON_ANCESTOR ] );
                
                set_pev_string( pId, pev_viewmodel2, aData[ MODEL_ID ][ V ] );
                set_pev_string( pId, pev_weaponmodel2, aData[ MODEL_ID ][ P ] );
                
                SetMoney( pId, ( GetMoney( pId ) - aData[ WEAPON_COST ] ) );
            }
        }
        return PLUGIN_HANDLED;
    }
    
    const Task_BuyTime = 5215126156;
    public Event_HLTV()
    {
        g_bBuyStatus = true;
        if( task_exists( Task_BuyTime ) )
            change_task( Task_BuyTime, float( g_iTimeBuy ) );
        else
            set_task( float( g_iTimeBuy ), "task_BlockBuyStatusShop", Task_BuyTime );
    }
    
    public task_BlockBuyStatusShop( iTaskId )
        g_bBuyStatus = false;
    
    DestroyArrayById( iId = 0 )
    {
        switch( iId ) {        
            case 1:
                ArrayDestroy( g_aMenuItemAll );
                
            case 2:
                ArrayDestroy( g_aMenuItemVip );
                
            case 3:
                ArrayDestroy( g_aMenuItemAdmin );
                
            default: {
                ArrayDestroy( g_aMenuItemAdmin );
                ArrayDestroy( g_aMenuItemAll );
                ArrayDestroy( g_aMenuItemVip );
            }
        }
    }
    
    stock UTIL_SayText(pPlayer, const szMessage[], any:...)
    {
        const MsgId_SayText = 76;
        new szBuffer[190], iLen = formatex( szBuffer, charsmax( szBuffer ), g_szPluginChatPrefix );
        if(numargs() > 2) vformat(szBuffer[iLen], charsmax(szBuffer), szMessage, 3);
        else copy(szBuffer[iLen], charsmax(szBuffer), szMessage);
        while(replace(szBuffer, charsmax(szBuffer), "!y", "^1")) {}
        while(replace(szBuffer, charsmax(szBuffer), "!t", "^3")) {}
        while(replace(szBuffer, charsmax(szBuffer), "!g", "^4")) {}
        switch(pPlayer)
        {
            case 0:
            {
                for(new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++)
                {
                    if(!is_user_connected(iPlayer)) continue;
                    engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, MsgId_SayText, {0.0, 0.0, 0.0}, iPlayer);
                    write_byte(iPlayer);
                    write_string(szBuffer);
                    message_end();
                }
            }
            default:
            {
                engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, MsgId_SayText, {0.0, 0.0, 0.0}, pPlayer);
                write_byte(pPlayer);
                write_string(szBuffer);
                message_end();
            }
        }
    }
    
    GetMoney( pId )
        return get_pdata_int( pId, 115 );
    
    SetMoney( pId, iMoney )
    {
        set_pdata_int( pId, 115, iMoney );
        engfunc( EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, 102, {0.0, 0.0, 0.0}, pId );
        write_long( iMoney );
        write_byte( 1 );
        emessage_end();
    }
    
    
    GetArrayById( iArrayId, iPos, aData[ eData_Skins ] )
    {
        switch( iArrayId ) {
            case 0:
                ArrayGetArray( g_aMenuItemAll, iPos, aData );
                
            case 1:
                ArrayGetArray( g_aMenuItemVip, iPos, aData );
            
            case 2:
                ArrayGetArray( g_aMenuItemAdmin, iPos, aData );
        }
    }
    
    CustomItem( iEnt )
        return ( ( pev( iEnt, pev_impulse ) - pev( iEnt, pev_iuser1 ) ) == WEAPON_KEY );
    
    stock drop_user_weapons( pPlayer, iType )
    {
        new iWeaponsId[32], iNum;
        get_user_weapons(pPlayer, iWeaponsId, iNum);
        if(iType) iType = (1<<CSW_GLOCK18|1<<CSW_USP|1<<CSW_P228|1<<CSW_DEAGLE|1<<CSW_ELITE|1<<CSW_FIVESEVEN);
        else iType = (1<<CSW_M3|1<<CSW_XM1014|1<<CSW_MAC10|1<<CSW_TMP|1<<CSW_MP5NAVY|1<<CSW_UMP45|1<<CSW_P90|1<<CSW_GALIL|1<<CSW_FAMAS|1<<CSW_AK47|1<<CSW_M4A1|1<<CSW_SCOUT|1<<CSW_SG552|1<<CSW_AUG|1<<CSW_AWP|1<<CSW_G3SG1|1<<CSW_SG550|1<<CSW_M249);
        for(new i; i < iNum; i++) {
            if(iType & (1<<iWeaponsId[i])) {
                new szWeaponName[24];
                get_weaponname(iWeaponsId[i], szWeaponName, charsmax(szWeaponName));
                engclient_cmd(pPlayer, "drop", szWeaponName);
            }
        }
    }
    
    stock fm_give_item(pPlayer, const szItem[])
    {
        new iEntity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, szItem));
        if(!pev_valid(iEntity)) return 0;
        new Float:vecOrigin[3];
        pev(pPlayer, pev_origin, vecOrigin);
        set_pev(iEntity, pev_origin, vecOrigin);
        set_pev(iEntity, pev_spawnflags, pev(iEntity, pev_spawnflags) | SF_NORESPAWN);
        dllfunc(DLLFunc_Spawn, iEntity);
        dllfunc(DLLFunc_Touch, iEntity, pPlayer);
        if(pev(iEntity, pev_solid) != SOLID_NOT) {
            engfunc(EngFunc_RemoveEntity, iEntity);
            return -1;
        }
        return iEntity;
    }
    
    stock UTIL_PrecacheSoundsFromModel( const szModelPath[] )
    {
        new iFile;
        
        if ( ( iFile = fopen( szModelPath, "rt" ) ) ) {
            new szSoundPath[ 64 ];
            
            new iNumSeq, iSeqIndex;
            new iEvent, iNumEvents, iEventIndex;
            
            fseek( iFile, 164, SEEK_SET );
            fread( iFile, iNumSeq, BLOCK_INT );
            fread( iFile, iSeqIndex, BLOCK_INT );
            
            for ( new k, i = 0; i < iNumSeq; i++ ) {
                fseek( iFile, iSeqIndex + 48 + 176 * i, SEEK_SET );
                fread( iFile, iNumEvents, BLOCK_INT );
                fread( iFile, iEventIndex, BLOCK_INT );
                fseek( iFile, iEventIndex + 176 * i, SEEK_SET );
                
                for ( k = 0; k < iNumEvents; k++ ) {
                    fseek( iFile, iEventIndex + 4 + 76 * k, SEEK_SET );
                    fread( iFile, iEvent, BLOCK_INT );
                    fseek( iFile, 4, SEEK_CUR );
                    
                    if ( iEvent != 5004 )
                        continue;
                    
                    fread_blocks( iFile, szSoundPath, 64, BLOCK_CHAR );
                    
                    if ( strlen( szSoundPath ) ) {
                        strtolower( szSoundPath );
                        precache_sound( szSoundPath );
                    }
                }
            }
        }    
        fclose( iFile );
    }
Перейти в начало страницы         Просмотр профиля    Отправить личное сообщение
   Цитировать сообщение
  Ответить в данную темуНачать новую тему
 
0 пользователей и 1 гостей читают эту тему: