Вопрос по плагину csdm_balancer от zerocool

ifx

Сообщения
331
Реакции
153
Помог
4 раз(а)
Есть вот такой плагин csdm_balancer. Он балансит игроков на ксдм моде по скилу, но балансит их когда они живы. У меня стоит мод с пушками\лазерами и получается, что игрока живого кидает за др команду и все его пушки уничтожаются.

Надо сделать, чтобы игрока перекидывало уже после смерти + добавить игнорирование на перекидывание ботов.

Вот сам код плагина

Код:
/*
*    CSDM Balancer V1.0 by Zer0CooL
*    http://forum.alfa-strike.net
*/

#include <amxmodx>
#include <cstrike>

#define LAST_PLAYERS_COUNT 4

////////////////// √лобальные переменные//////////////////////
static Float:g_checkInterval, g_maxDisbalance, g_skillPlayer,
g_minPlayers, g_maxPlayers, skillPlayer,
CsTeams:g_lessTeam, g_playerScore, g_worstScore,
g_bestScore, g_lastPlayers[LAST_PLAYERS_COUNT];
new g_num;
//////////////////////////////////////////////////////////////

public plugin_init()
{
    register_plugin( "CSDM Balancer", "1.0", "Zer0CooL" )
    register_dictionary( "csdmbalancer.txt" )
 
    register_cvar    ( "dmb_sound",             "0"    )
    register_cvar    ( "dmb_minplayers",     "4"    )
    register_cvar    ( "dmb_skillplayer",     "1"    )
    register_cvar    ( "dmb_enableplugin",     "1"    )
    register_cvar    ( "dmb_checkinterval",    "180.0" )
    register_cvar    ( "dmb_maxdisbalance",    "1"    )
}

public plugin_cfg()
{
    g_maxPlayers        =   get_maxplayers    ()
    g_minPlayers        =    get_cvar_num    ( "dmb_minplayers"      )
    skillPlayer         =
    g_skillPlayer        =     get_cvar_num      ( "dmb_skillplayer"   )
    g_maxDisbalance        =     get_cvar_num      ( "dmb_maxdisbalance" )
    g_checkInterval     =     get_cvar_float    ( "dmb_checkinterval" )
 
    if( get_cvar_num("dmb_enableplugin") < 1 || g_maxPlayers < 4 )
        return 0
 
    if( g_maxDisbalance < 1 )
        g_maxDisbalance = 1
     
    if( g_minPlayers < 4 )
        g_minPlayers = 4
     
    if( g_checkInterval < 10 )
        g_checkInterval = 10.0
 
    server_cmd( "mp_autoteambalance 0;mp_limitteams %d", g_maxDisbalance )
 
    set_task( g_checkInterval, "check", 0, _, _, "b" )
    return 0
}

public check()
{
    static players[32];
    new playerCount = 0,
    T_Count = 0, CT_Count = 0;
 
    for( new i = 1; i <= g_maxPlayers; i++ )
    {
        if ( !is_user_connected(i) || is_user_hltv(i) )
            continue
 
        switch( cs_get_user_team(i) )
        {
            case CS_TEAM_CT: CT_Count++;
            case CS_TEAM_T: T_Count++;
            default: continue;
        }
     
        players[playerCount] = i
        playerCount++
    }
 
    if( playerCount < g_minPlayers ) return PLUGIN_CONTINUE
 
    else if( (CT_Count - T_Count) > g_maxDisbalance )
        g_lessTeam = CS_TEAM_T
 
    else if( (T_Count - CT_Count) > g_maxDisbalance )
        g_lessTeam = CS_TEAM_CT
     
    else return PLUGIN_CONTINUE
 
    //    Transfer Player
    new id = GetPlayer( players, playerCount, g_lessTeam )
 
    else if( g_lessTeam == CS_TEAM_CT && user_has_weapon(id, CSW_C4) )
        engclient_cmd( id, "drop", "weapon_c4" )
 
    else if( g_lessTeam == CS_TEAM_T && cs_get_user_defuse(id) )
        cs_set_user_defuse( id, 0 )
 
    cs_set_user_team( id, g_lessTeam )
    ShowMessage( id )
 
    return PLUGIN_CONTINUE
}

ShowMessage( id )
{
    static name[32], teamName[19];
    get_user_name( id, name, charsmax(name) )
 
    teamName = g_lessTeam == CS_TEAM_CT ? "Counter-Terrorists" : "Terrorists";
 
    client_print    ( 0, print_chat, "%L", LANG_PLAYER, "CHAT_MESSAGE", name, teamName )
    console_print    ( 0, "%s has been transfered to %s.", name, teamName )
 
    if( !is_user_bot(id) )
    {
        set_hudmessage    ( 255, 140, 0, -1.0, 0.40, 2, 0.02, 5.0, 0.01, 0.1, 2 )
        show_hudmessage    ( id, "%L", LANG_PLAYER, "HUD_MESSAGE", teamName )
    }
    else
        user_kill( id )
}

GetPlayer( const players[], playerCount, CsTeams:g_lessTeam )
{
    if( g_skillPlayer > 1 ) skillPlayer = random_num(0, 1)
    g_bestScore = -9999, g_worstScore = 9999;
 
    static id, player;
    for( new i = 0; i < playerCount; i++ )
    {
        player = players[i]

        if( cs_get_user_team(player) == g_lessTeam || IsLastPlayer(player) )
            continue
     
        else if( IsSatisfactoryPlayer(player) )
            id = player
    }
 
    PutLastPlayer( id )
    return id
}

bool:IsLastPlayer( id )
{
    for( new i = 0; i < LAST_PLAYERS_COUNT; i++ )
        if( g_lastPlayers[i] == id )
            return true

    return false
}

PutLastPlayer( id )
{
    if( g_num > (LAST_PLAYERS_COUNT - 1) )
        g_num = 0;
     
    g_lastPlayers[g_num] = id
    g_num++
}

bool:IsSatisfactoryPlayer( id )
{
    g_playerScore = ( get_user_frags(id) - get_user_deaths(id) )
 
    switch( skillPlayer )
    {
        case 0:
        {
            if( g_playerScore <= g_worstScore )
            {
                g_worstScore = g_playerScore
                return true
            }
        }
        case 1:
        {
            if( g_playerScore >= g_bestScore )
            {
                g_bestScore = g_playerScore
                return true
            }
        }
    }
    return false
}
Я вижу что проверка идет в этом блоке

Код:
public check() {
    ...
    
    // Transfer Player
    new id = GetPlayer( players, playerCount, g_lessTeam )

    if( !is_user_bot(id) ) return PLUGIN_CONTINUE
    else if (is_user_alive(id)) return PLUGIN_CONTINUE

    else if( g_lessTeam == CS_TEAM_CT && user_has_weapon(id, CSW_C4) )
    engclient_cmd( id, "drop", "weapon_c4" )

    else if( g_lessTeam == CS_TEAM_T && cs_get_user_defuse(id) )
    cs_set_user_defuse( id, 0 )

    cs_set_user_team( id, g_lessTeam )
    ShowMessage( id )

    return PLUGIN_CONTINUE
}
и дописал, но видимо криво, тк проверка на жив ли юзер не работает, можете подсказать, что я делаю не так?
 
Последнее редактирование модератором:
Сообщения
1,420
Реакции
2,511
Помог
58 раз(а)
Попробуйте заменить на 67 строчке:
Код:
-- if (!is_user_connected(i) || is_user_hltv(i))
++ if (is_user_alive(i) || is_user_bot(i) || is_user_hltv(i))
 
Сообщения
702
Реакции
54
Millervlg, да вроде вот
Код:
/*

*    CSDM Balancer V1.0 by Zer0CooL

*    http://forum.alfa-strike.net

*/



#include <amxmodx>

#include <cstrike>



#define LAST_PLAYERS_COUNT 4



////////////////// √лобальные переменные//////////////////////

static Float:g_checkInterval, g_maxDisbalance, g_skillPlayer,

g_minPlayers, g_maxPlayers, skillPlayer,

CsTeams:g_lessTeam, g_playerScore, g_worstScore,

g_bestScore, g_lastPlayers[LAST_PLAYERS_COUNT];

new g_num;

//////////////////////////////////////////////////////////////



public plugin_init()

{

    register_plugin( "CSDM Balancer", "1.0", "Zer0CooL" )

    register_dictionary( "csdmbalancer.txt" )

 

    register_cvar    ( "dmb_sound",             "0"    )

    register_cvar    ( "dmb_minplayers",     "4"    )

    register_cvar    ( "dmb_skillplayer",     "1"    )

    register_cvar    ( "dmb_enableplugin",     "1"    )

    register_cvar    ( "dmb_checkinterval",    "180.0" )

    register_cvar    ( "dmb_maxdisbalance",    "1"    )

}



public plugin_cfg()

{

    g_maxPlayers        =   get_maxplayers    ()

    g_minPlayers        =    get_cvar_num    ( "dmb_minplayers"      )

    skillPlayer         =

    g_skillPlayer        =     get_cvar_num      ( "dmb_skillplayer"   )

    g_maxDisbalance        =     get_cvar_num      ( "dmb_maxdisbalance" )

    g_checkInterval     =     get_cvar_float    ( "dmb_checkinterval" )

 

    if( get_cvar_num("dmb_enableplugin") < 1 || g_maxPlayers < 4 )

        return 0

 

    if( g_maxDisbalance < 1 )

        g_maxDisbalance = 1

    

    if( g_minPlayers < 4 )

        g_minPlayers = 4

    

    if( g_checkInterval < 10 )

        g_checkInterval = 10.0

 

    server_cmd( "mp_autoteambalance 0;mp_limitteams %d", g_maxDisbalance )

 

    set_task( g_checkInterval, "check", 0, _, _, "b" )

    return 0

}



public check()

{

    static players[32];

    new playerCount = 0,

    T_Count = 0, CT_Count = 0;

 

    for( new i = 1; i <= g_maxPlayers; i++ )

    {

            if (!is_user_alive(i) || is_user_bot(i) || !is_user_hltv(i))

            continue

 

        switch( cs_get_user_team(i) )

        {

            case CS_TEAM_CT: CT_Count++;

            case CS_TEAM_T: T_Count++;

            default: continue;

        }

    

        players[playerCount] = i

        playerCount++

    }

 

    if( playerCount < g_minPlayers ) return PLUGIN_CONTINUE

 

    else if( (CT_Count - T_Count) > g_maxDisbalance )

        g_lessTeam = CS_TEAM_T

 

    else if( (T_Count - CT_Count) > g_maxDisbalance )

        g_lessTeam = CS_TEAM_CT

    

    else return PLUGIN_CONTINUE

 

    //    Transfer Player

    new id = GetPlayer( players, playerCount, g_lessTeam )

 

    else if( g_lessTeam == CS_TEAM_CT && user_has_weapon(id, CSW_C4) )

        engclient_cmd( id, "drop", "weapon_c4" )

 

    else if( g_lessTeam == CS_TEAM_T && cs_get_user_defuse(id) )

        cs_set_user_defuse( id, 0 )

 

    cs_set_user_team( id, g_lessTeam )

    ShowMessage( id )

 

    return PLUGIN_CONTINUE

}



ShowMessage( id )

{

    static name[32], teamName[19];

    get_user_name( id, name, charsmax(name) )

 

    teamName = g_lessTeam == CS_TEAM_CT ? "Counter-Terrorists" : "Terrorists";

 

    client_print    ( 0, print_chat, "%L", LANG_PLAYER, "CHAT_MESSAGE", name, teamName )

    console_print    ( 0, "%s has been transfered to %s.", name, teamName )

 

    if( !is_user_bot(id) )

    {

        set_hudmessage    ( 255, 140, 0, -1.0, 0.40, 2, 0.02, 5.0, 0.01, 0.1, 2 )

        show_hudmessage    ( id, "%L", LANG_PLAYER, "HUD_MESSAGE", teamName )

    }

    else

        user_kill( id )

}



GetPlayer( const players[], playerCount, CsTeams:g_lessTeam )

{

    if( g_skillPlayer > 1 ) skillPlayer = random_num(0, 1)

    g_bestScore = -9999, g_worstScore = 9999;

 

    static id, player;

    for( new i = 0; i < playerCount; i++ )

    {

        player = players[i]



        if( cs_get_user_team(player) == g_lessTeam || IsLastPlayer(player) )

            continue

    

        else if( IsSatisfactoryPlayer(player) )

            id = player

    }

 

    PutLastPlayer( id )

    return id

}



bool:IsLastPlayer( id )

{

    for( new i = 0; i < LAST_PLAYERS_COUNT; i++ )

        if( g_lastPlayers[i] == id )

            return true



    return false

}



PutLastPlayer( id )

{

    if( g_num > (LAST_PLAYERS_COUNT - 1) )

        g_num = 0;

    

    g_lastPlayers[g_num] = id

    g_num++

}



bool:IsSatisfactoryPlayer( id )

{

    g_playerScore = ( get_user_frags(id) - get_user_deaths(id) )

 

    switch( skillPlayer )

    {

        case 0:

        {

            if( g_playerScore <= g_worstScore )

            {

                g_worstScore = g_playerScore

                return true

            }

        }

        case 1:

        {

            if( g_playerScore >= g_bestScore )

            {

                g_bestScore = g_playerScore

                return true

            }

        }

    }

    return false

}
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу