• Гость, перед открытием темы прочитай описание раздела, чтобы не ошибиться. Любые вопросы по настройке сервера создаются в разделе Технической Поддержки.

Помощь 2 худа вместо одного.

Romik67ru

Участник
Сообщения
18
Симпатии
0
Баллы
57
#1
Привет.
Криво отображается худ (накладывается друг на друга и виснет)
После перезахода, перезагрузки ничего не происходит.
В чём проблема?
Код:
#include < amxmodx >
#include < cstrike >
#include < sqlx >
#include < hamsandwich >
#include < fakemeta >
#include < amxmisc >

#define PLUGIN    "[DeathRun] MySQL LVL + Speedometer"
#define VERSION    "1.0"
#define AUTHOR    "Mr. Hacker4ik [UA]"

new OneKill    =    5                            // Сколько нужно убить что бы получить 2 уровень
new TwoKill    =    3                            // + 10 убийств к следующему уровню ( На 2 уровне, нужно будет убить 50 игроков.)

new Level[ 33 ] , UserKills[ 33 ] , LevelNext[ 33 ], g_Money[ 33 ]

new MaxPlayers, TaskEnt, ShowSpeed
new bool:plrSpeed[33]

new const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0

new const g_szSoundLevel[][] = { "Event_Levels/Level_Up.wav" }

// [ Start: MYSQL ]

new g_szQuery[ 2048 ] , szName[ 33 ][ 34 ] ;
new Handle: g_hDBTuple , Handle: g_hConnect ;

new const szHost[ ] = "*********" ,
szUser[ ] = "*********" ,
szPassword[ ] = "*********" ,
szDataBase[ ] = "*********" ,
szTableName[ ] = "DeathrunDataBase"
// [ End: MYSQL ]

public plugin_init() {
    register_plugin( PLUGIN , VERSION , AUTHOR )
    
    register_forward(FM_Think, "Think")
    
    TaskEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))   
    set_pev(TaskEnt, pev_classname, "speedometer_think")
    set_pev(TaskEnt, pev_nextthink, get_gametime() + 1.01)
    
    RegisterHam( Ham_Killed , "player" , "Player_Killing" , 1 );
    RegisterHam( Ham_Spawn , "player" , "Player_Spawn" , 1 );
    
    register_menu( "Menu_1" , KEYSMENU , "ClCmd_Moneymenu" );
    register_clcmd( "MoneyMenu" , "ClCmd_Moneymenunew" );
    
    MaxPlayers = get_maxplayers();
    ShowSpeed = register_cvar("showspeed", "1")
}

public plugin_natives() {
    register_native( "SetUserLevel" , "NativeSetUserLevel" , 1 )
    register_native( "GetUserLevel" , "NativeGetUserLevel" , 1 )
    register_native( "SetUserNext" , "NativeSetUserNext" , 1 )
    register_native( "GetUserNext" , "NativeGetUserNext" , 1 )
    register_native( "GetUserGold" , "native_get_money" , 1 )
    register_native( "SetUserGold" , "native_set_money" , 1 )
    register_native( "SetUserKills" , "NativeSetUserKills" , 1 )
    register_native( "GetUserKills" , "NativeGetUserKills" , 1 )
    
}

public plugin_precache() precache_sound( "Event_Levels/Level_Up.wav" )

public Think(ent)
{
    if(ent == TaskEnt)
    {
        Info()
        set_pev(ent, pev_nextthink,  get_gametime() + 0.1)
    }
}

public Player_Killing( victim , attacker )
{   
    if( !is_user_connected( attacker ) || Level[attacker] >= 30 )
    return HAM_IGNORED

    UserKills[attacker] += 1
    g_Money[ attacker ] += random_num( 1 , 10 )

    if(UserKills[attacker] >= LevelNext[attacker])
    {
        LevelNext[attacker] += TwoKill
        Level[attacker] += 1
        
        client_print( attacker , print_center , "Вы достигли %d уровня. Следующий через %d убийств" , Level[ attacker ] , LevelNext[ attacker ] )
        
        UserKills[ attacker ] = 0
        client_cmd( attacker , "spk %s" , g_szSoundLevel )
    }
    return PLUGIN_HANDLED;
}

public Player_Spawn( pPlayer )
{
    if( !is_user_connected( pPlayer ) )
    return;

    set_task( 2.0 , "Check_Level" , pPlayer )
    set_task( 2.0 , "savedata" , pPlayer )
}

public Info()
{
    
    for(new pPlayer = 0; pPlayer <= MaxPlayers; pPlayer++)
    {
        if(!is_user_bot(pPlayer) && is_user_connected(pPlayer) || (!plrSpeed[pPlayer]))
        {
            set_hudmessage(0, 200, 200, -1.0, 0.89, 0, 0.0, 0.1, 0.01, -1)
            if(Level [ pPlayer ] <= 29)
            {
            show_hudmessage( pPlayer , "^nЗолото: %d | Уровень: %d | Опыт: %i / %i" , g_Money[ pPlayer ], Level[ pPlayer ] , UserKills[ pPlayer ] , LevelNext[ pPlayer ] , UserKills[ pPlayer ] )
            } else {
            show_hudmessage( pPlayer , "^nЗолото: %d | Уровень: 30 | Максимум", g_Money[ pPlayer ] )
            }
        }
    }
    return PLUGIN_CONTINUE
}

public Check_Level( pPlayer )
{
    if( Level[ pPlayer ] < 1 )
    {
        Level[ pPlayer ] = 1
        LevelNext[ pPlayer ] = OneKill
    }
}

public ClCmd_Moneymenunew( pPlayer )
{
    static menu[ 1048 ], len
    len = 0

    len += formatex( menu[ len ] , charsmax( menu ) - len , "\d[\y©\d] DeathRun | Выдача золота^n^n" )

    if( get_user_flags( pPlayer ) & ADMIN_RCON )
    len += formatex( menu[ len ] , charsmax( menu ) - len , "\r1 \d| \wВыдать: \d[500 золота]^n" )
    else
    len += formatex( menu[ len ] , charsmax( menu ) - len , "\d2 \d| \dВыдать: \d[500 золота]^n" )
    
    len += formatex( menu[ len ] , charsmax( menu ) - len , "^n^n\r0 \d| \wВыход" , pPlayer )
    
    show_menu( pPlayer , KEYSMENU , menu , -1 , "Menu_1" );
}

public ClCmd_Moneymenu( pPlayer , key )
{
    client_cmd(pPlayer, "spk items/nvg_off");
    switch ( key )
    {
    case 0:
        {
            MenuPlayer( pPlayer )
        }
    }
    return PLUGIN_HANDLED
}

public MenuPlayer( pPlayer )
{
    if( get_user_flags( pPlayer ) & ADMIN_RCON ) {
        new i_Menu = menu_create( "\d[\y©\d] DeathRun | Выбери игрока", "menu_handle" )

        new s_Players[ 32 ], i_Num, i_Player

        new s_Name[ 32 ], s_Player[ 10 ], text[ 128 ]

        get_players( s_Players , i_Num )

        for ( new i; i < i_Num; i++ )
        {
            i_Player = s_Players[ i ]
            
            get_user_name( i_Player , s_Name , charsmax( s_Name ) )
            num_to_str( i_Player , s_Player , charsmax( s_Player ) )

            formatex( text , charsmax( text ) , "\w%s \y[\d%d\y]" , s_Name , g_Money[ i_Player ] )
            menu_additem( i_Menu , text , s_Player , 0 )
            ClCmd_Moneymenunew( pPlayer )
        }
        menu_setprop( i_Menu, MPROP_EXITNAME , "Выход" )
        menu_setprop( i_Menu, MPROP_NEXTNAME , "Далее" )
        menu_setprop( i_Menu, MPROP_BACKNAME , "Назад" )
        menu_display( pPlayer , i_Menu , 0 )
    } else
    client_print( pPlayer , print_center , "НЕТ ДОСТУПА" )
}
public menu_handle( pPlayer , menu , item )
{
    if ( item == MENU_EXIT )
    {
        menu_destroy( menu )
        return PLUGIN_HANDLED
    }
    
    client_cmd(pPlayer, "spk items/nvg_off");

    new s_Data[ 6 ] , s_Name[ 64 ] , i_Access , i_Callback
    menu_item_getinfo( menu , item , i_Access , s_Data , charsmax( s_Data ) , s_Name , charsmax( s_Name ) , i_Callback )

    new i_Player = str_to_num( s_Data )
    
    g_Money[ i_Player ] += 500
    client_print( i_Player , print_center , "Вы получили 500 золота." )
    
    menu_destroy( menu )
    return PLUGIN_HANDLED
}

// [ Start: MYSQL ]

public plugin_cfg( ) {
    new szError[ 512 ] , iErrorCode;
    
    g_hDBTuple = SQL_MakeDbTuple ( szHost , szUser , szPassword , szDataBase );
    g_hConnect = SQL_Connect( g_hDBTuple , iErrorCode , szError , charsmax( szError ) );
    
    if ( g_hConnect == Empty_Handle )
    set_fail_state( szError );
    
    if ( !SQL_TableExists( g_hConnect , szTableName ) ) {
        new Handle: Queries;
        new Query [ 1024 ];
        format( Query , 1023 , "CREATE TABLE `%s` (Name VARCHAR(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, Money INT NOT NULL, Level INT NOT NULL, Kills INT NOT NULL, NextKills INT NOT NULL, PRIMARY KEY (Name))" , szTableName );
        Queries = SQL_PrepareQuery( g_hConnect, Query );
        
        if ( !SQL_Execute( Queries ) ) {
            SQL_QueryError( Queries , szError ,charsmax( szError ) );
            set_fail_state( szError );
        }
        SQL_FreeHandle ( Queries );   
    }
    SQL_QueryAndIgnore( g_hConnect , "SET NAMES utf8" );
}

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

public client_putinserver( pPlayer )
{   
    new iParams [ 1 ]; iParams [ 0 ] = pPlayer;
    get_user_name( pPlayer, szName [ pPlayer ] , charsmax( szName[ ] ) );
    plrSpeed[pPlayer] = ShowSpeed > 0 ? true : false

    format( g_szQuery , charsmax( g_szQuery ) ,
    "SELECT * FROM `%s` WHERE ( `%s`.`Name` = '%s' )", szTableName , szTableName , szName [ pPlayer ]
    );
    
    SQL_ThreadQuery( g_hDBTuple, "SQL_QueryConnection", g_szQuery, iParams, sizeof iParams );
}

public client_disconnect( pPlayer ) {
    format( g_szQuery , charsmax( g_szQuery ),
    "UPDATE `%s` SET `Money` = '%d' , `Level` = '%i' , `Kills` = '%i' , `NextKills` = '%i'  WHERE `%s`.`Name` = '%s';",
    szTableName , g_Money[ pPlayer ] , Level[ pPlayer ] , UserKills[ pPlayer ] , LevelNext[ pPlayer ] , szTableName , szName [ pPlayer ]
    );
    
    SQL_ThreadQuery( g_hDBTuple, "ThreadQueryHandler", g_szQuery );
}

public savedata( pPlayer ) {
    format( g_szQuery , charsmax( g_szQuery ),
    "UPDATE `%s` SET `Money` = '%d' , `Level` = '%i' , `Kills` = '%i' , `NextKills` = '%i'  WHERE `%s`.`Name` = '%s';",
    szTableName , g_Money[ pPlayer ] , Level[ pPlayer ] , UserKills[ pPlayer ] , LevelNext[ pPlayer ] , szTableName , szName [ pPlayer ]
    );
    
    SQL_ThreadQuery( g_hDBTuple, "ThreadQueryHandler", g_szQuery );
}

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

        Level [ pPlayer ] = 0;
        g_Money [ pPlayer ] = 0;
        
        format(
        g_szQuery , charsmax( g_szQuery ),
        
        "INSERT INTO `%s` ( `Name` , `Money` , `Level` , `Kills` , `NextKills` ) VALUES ( '%s' , '%d' , '%i' , '%i' , '%i' );",
        szTableName , szName [ pPlayer ] , g_Money[ pPlayer ] , Level [ pPlayer ] , UserKills [ pPlayer ] , LevelNext [ pPlayer ]
        );
        
        SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );
        
        return PLUGIN_HANDLED;
    }
    else {
        g_Money [ pPlayer ] = SQL_ReadResult ( hQuery , 1 );
        Level [ pPlayer ] = SQL_ReadResult ( hQuery , 2 );
        UserKills [ pPlayer ] = SQL_ReadResult ( hQuery , 3 );
        LevelNext [ pPlayer ] = SQL_ReadResult ( hQuery , 4 );
    }
    
    return PLUGIN_HANDLED;
}

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

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

public NativeSetUserLevel( pPlayer , iValue ) {
    Level [ pPlayer ] = iValue;

    format( g_szQuery , charsmax( g_szQuery ) , "UPDATE `%s` SET `Level` = '%i' WHERE `%s`.`Name` = '%s';", szTableName, Level [ pPlayer ] , szTableName , szName [ pPlayer ] );
    SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );
}

public NativeSetUserNext( pPlayer , iValue ) {
    LevelNext [ pPlayer ] = iValue;

    format( g_szQuery , charsmax( g_szQuery ) , "UPDATE `%s` SET `LevelNext` = '%i' WHERE `%s`.`Name` = '%s';", szTableName, LevelNext [ pPlayer ] , szTableName , szName [ pPlayer ] );
    SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );
}

public NativeSetUserKills( pPlayer , iValue ) {
    UserKills [ pPlayer ] = iValue;

    format( g_szQuery , charsmax( g_szQuery ) , "UPDATE `%s` SET `Kills` = '%i' WHERE `%s`.`Name` = '%s';", szTableName, UserKills [ pPlayer ] , szTableName , szName [ pPlayer ] );
    SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );
}

public native_set_money( pPlayer , num )
{
    g_Money[ pPlayer ] = num
}

public NativeGetUserNext( pPlayer ) {
    return LevelNext[ pPlayer ];
}

public NativeGetUserLevel( pPlayer ) {
    return Level[ pPlayer ];
}

public native_get_money( pPlayer )
{
    return g_Money[ pPlayer ]
}

public NativeGetUserKills( pPlayer ) {
    return UserKills[ pPlayer ];
}
// [ End: MYSQL ]

Бд подключено верно, таблица есть. После остановки плагина худ полностью убирается, а после включения опять накладывается.
 
Сверху