• Пожалуйста, создайте название темы отражающее ее смысл
  • Для ускорения решения Вашего вопроса заполните обязательные поля и подробно опишите возникшую проблему

Помощь Меняет ники игроков | не всегда пишет ХУД

TauJieP

Участник
Источник плагина (исходный код)
Код:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <csx>
// #include <dhudmessage>
#include <fakemeta>
#include <engine>

#define add_bit(%1,%2) (%1 |= (1 << (%2 - 1)))
#define is_bit(%1,%2) (%1 & (1 << (%2 - 1)))
#define remove_bit(%1,%2) (%1 &= ~(1 << (%2 - 1)))

#pragma semicolon 1

#define PLUGIN "CS:GO"
#define VERSION "1.0.1.1"
#define AUTHOR "Freedo.m"

#define NORMAL_KILL 1.0
#define HS_KILL 1.3
#define GRENADE_KILL 1.5
#define KNIFE_KILL 2.5
#define BOMB_PLANTED 1.25
#define BOMB_DEFUSED 1.5
#define ASSIST_KILL 0.5
#define MVP_PRIZE 1000

enum any:MVP_STATS
{
    Float:VALUE,
    NORMAL,
    HS,
    bool:GRENADE,
    bool:KNIFE,
    bool:PLANTED,
    bool:DEFUSED,
    ASSIST
};

new max_bpammo[31] =
{
    0,
    52,  //CSW_P228
    0,
    90,  //CSW_SCOUT
    1,   //CSW_HEGRENADE
    32,  //CSW_XM1014
    1,   //CSW_C4
    100, //CSW_MAC10
    90,  //CSW_AUG
    1,   //CSW_SMOKEGRENADE
    120, //CSW_ELITE
    100, //CSW_FIVESEVEN
    100, //CSW_UMP45
    90,  //CSW_SG550
    90,  //CSW_GALIL
    90,  //CSW_FAMAS
    100, //CSW_USP
    120, //CSW_GLOCK18
    30,  //CSW_AWP
    120, //CSW_MP5NAVY
    200, //CSW_M249
    32,  //CSW_M3
    90,  //CSW_M4A1
    120, //CSW_TMP
    90,  //CSW_G3SG1
    2,   //CSW_FLASHBANG
    35,  //CSW_DEAGLE
    90,  //CSW_SG552
    90,  //CSW_AK47
    0,   //CSW_KNIFE
    100  //CSW_P90
};

new clip_size[31] =
{
    0,
    13,  //CSW_P228
    0,
    10,  //CSW_SCOUT
    0,   //CSW_HEGRENADE
    7,   //CSW_XM1014
    0,   //CSW_C4
    30,  //CSW_MAC10
    30,  //CSW_AUG
    0,   //CSW_SMOKEGRENADE
    30,  //CSW_ELITE
    20,  //CSW_FIVESEVEN
    25,  //CSW_UMP45
    30,  //CSW_SG550
    35,  //CSW_GALIL
    25,  //CSW_FAMAS
    12,  //CSW_USP
    20,  //CSW_GLOCK18
    10,  //CSW_AWP
    30,  //CSW_MP5NAVY
    100, //CSW_M249
    8,   //CSW_M3
    30,  //CSW_M4A1
    30,  //CSW_TMP
    20,  //CSW_G3SG1
    0,   //CSW_FLASHBANG
    7,   //CSW_DEAGLE
    30,  //CSW_SG552
    30,  //CSW_AK47
    0,   //CSW_KNIFE
    50   //CSW_P90
};

new ammo_type[31] =
{
    0,
    9,  //CSW_P228
    0,
    2,  //CSW_SCOUT
    12, //CSW_HEGRENADE
    5,  //CSW_XM1014
    14, //CSW_C4
    6,  //CSW_MAC10
    4,  //CSW_AUG
    13, //CSW_SMOKEGRENADE
    10, //CSW_ELITE
    7,  //CSW_FIVESEVEN
    6,  //CSW_UMP45
    4,  //CSW_SG550
    4,  //CSW_GALIL
    4,  //CSW_FAMAS
    6,  //CSW_USP
    10, //CSW_GLOCK18
    1,  //CSW_AWP
    10, //CSW_MP5NAVY
    3,  //CSW_M249
    5,  //CSW_M3
    4,  //CSW_M4A1
    10, //CSW_TMP
    2,  //CSW_G3SG1
    11, //CSW_FLASHBANG
    8,  //CSW_DEAGLE
    4,  //CSW_SG552
    2,  //CSW_AK47
    0,  //CSW_KNIFE
    7   //CSW_P90
};

new ammo_name[15][] =
{
    "",
    "ammo_338magnum",
    "ammo_762nato",
    "ammo_556natobox",
    "ammo_556nato",
    "ammo_buckshot",
    "ammo_45acp",
    "ammo_57mm",
    "ammo_50ae",
    "ammo_357sig",
    "ammo_9mm",
    "",
    "",
    "",
    ""
};

new message_saytext, message_deathmsg, message_money, message_weap_pickup, last_message_id, last_message_type, maxplayers, blockinfo;
new last_message[33], last_weap_pickup[33], bought_weapon[33];
new damages[33][33], names[33][32], any:mvp[33][MVP_STATS], assists[33];

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);

    message_saytext = get_user_msgid("SayText");
    message_deathmsg = get_user_msgid("DeathMsg");
    message_weap_pickup = get_user_msgid("WeapPickup");
    message_money = get_user_msgid("Money");

    register_clcmd("fullupdate", "clcmd_fullupdate");

    register_message(message_deathmsg, "fwd_diemsg");

    register_event("Damage", "fwd_damage", "be", "2!0", "3=0", "4!0");
    register_event("DeathMsg", "fwd_die", "ae");

    register_logevent("fwd_roundend", 2, "1=Round_End");

    RegisterHam(Ham_Spawn, "player", "fwd_spawn", 1);

    register_forward(FM_MessageBegin, "fwd_message_begin", 1);
    register_forward(FM_WriteByte, "fwd_write_byte", 1);

    maxplayers = get_maxplayers();

    return PLUGIN_CONTINUE;
}

public fwd_roundend()
{
    return set_task(0.1, "calc_mvp");
}

public calc_mvp()
{
    new mvpid, Float:cmvp;
    for(new id = 1; id <= maxplayers; id++)
    {
        if(is_user_connected(id) && mvp[id][VALUE] > 1.5 && mvp[id][VALUE] > cmvp)
        {
            mvpid = id;
            cmvp = mvp[id][VALUE];
        }
    }

    if(mvpid)
    {
        cs_set_user_money(mvpid, min(cs_get_user_money(mvpid) + MVP_PRIZE, 16000), 1);

        new bool:inits;

        new name[32], mvp_message[256];
        get_user_name(mvpid, name, 31);
        set_dhudmessage(0, 200, 0, -1.0, 0.65, 2, 6.0, 4.0, 0.01, 1.0);
        new len = formatex(mvp_message, 256, "Лучший игрок: %s^n%d убийств.", name, mvp[mvpid][NORMAL]);
        if(mvp[mvpid][HS])
        {
            len += formatex(mvp_message[len], 255 - len, ", %d в голову", mvp[mvpid][HS]);
        }
        if(mvp[mvpid][ASSIST])
        {
            len += formatex(mvp_message[len], 255 - len, ", %d помощи", mvp[mvpid][ASSIST]);
        }
        if(mvp[mvpid][GRENADE])
        {
            len += formatex(mvp_message[len], 255 - len, "^nубийств с гранаты");
            inits = true;
        }
        if(mvp[mvpid][KNIFE])
        {
            if(!inits)
            {
                inits = true;
                len += formatex(mvp_message[len], 255 - len, "^n с ножа");
            }
            else
            {
                len += formatex(mvp_message[len], 255 - len, ", с ножаl");
            }
        }
        if(mvp[mvpid][PLANTED])
        {
            if(!inits)
            {
                inits = true;
                len += formatex(mvp_message[len], 255 - len, "^nЗаложил бомбу");
            }
            else
            {
                len += formatex(mvp_message[len], 255 - len, ", заложил бомбу");
            }
        }
        if(mvp[mvpid][DEFUSED])
        {
            if(!inits)
            {
                inits = true;
                len += formatex(mvp_message[len], 255 - len, "^nРазминировал бомбу");
            }
            else
            {
                len += formatex(mvp_message[len], 255 - len, ", разменировал бомбу");
            }
        }

        show_dhudmessage(0, "%s", mvp_message);
    }

    for(new i = 1; i <= maxplayers; i++)
    {
        mvp[i][VALUE] = 0.0;
        mvp[i][NORMAL] = 0;
        mvp[i][HS] = 0;
        mvp[i][ASSIST] = 0;
        mvp[i][GRENADE] = false;
        mvp[i][KNIFE] = false;
        mvp[i][PLANTED] = false;
        mvp[i][DEFUSED] = false;
    }

    return PLUGIN_CONTINUE;
}

stock show_given_bpammo(id, weap_id, ammount)
{
    if(ammount <= 0)
    {
        return PLUGIN_CONTINUE;
    }

    message_begin(MSG_ONE, get_user_msgid("AmmoPickup"), {0, 0, 0}, id);
    write_byte(ammo_type[weap_id]);
    write_byte(ammount);
    return message_end();
}

public bool:fill_bpammo_show(id, weap_id)
{
    new given_ammo = max_bpammo[weap_id];
    if(weapon_has_ammo(weap_id))
    {
        given_ammo -= cs_get_user_bpammo(id, weap_id);
    }
    if(fill_bpammo(id, weap_id))
    {
        show_given_bpammo(id, weap_id, given_ammo);
        return true;
    }

    return false;
}

public client_putinserver(id)
{
    return get_user_name(id, names[id], 31);
}

public fwd_message_begin(msg_dest, msg_type, const Float:origin[3], id)
{
    if(id < 1 || id > 32)
    {
        return FMRES_IGNORED;
    }

    if(msg_type == message_money && last_message[id] == message_weap_pickup)
    {
        new arg[2];
        arg[0] = id;
        arg[1] = last_weap_pickup[last_message_id];
        set_task(0.1, "do_weapon_buy", _, arg, 2);
    }

    last_message_id = id;
    last_message_type = msg_type;
    last_message[id] = msg_type;

    return FMRES_IGNORED;
}

public do_weapon_buy(arg[])
{
    if(!is_user_connected(arg[0]))
    {
        return PLUGIN_CONTINUE;
    }

    if(fill_weapon(arg[0], arg[1]))
    {
        fill_bpammo_show(arg[0], arg[1]);
    }

    return PLUGIN_CONTINUE;
}

stock bool:weapon_has_ammo(weap_id)
{
    return ammo_name[ammo_type[weap_id]][0] != 0;
}

stock bool:fill_bpammo(id, weap_id)
{
    new ammo = max_bpammo[weap_id];
    if(weapon_has_ammo(weap_id))
    {
        cs_set_user_bpammo(id, weap_id, ammo);
        return true;
    }

    return false;
}

stock bool:fill_weapon(id, weap_id)
{
    new clip_sz = clip_size[weap_id];
    if(clip_sz != 0)
    {
        new weap_name[41];
        get_weaponname(weap_id, weap_name, 40);
        new wpn = find_ent_by_owner(-1, weap_name, id);
        if(wpn != 0)
        {
            cs_set_weapon_ammo(wpn, clip_sz);
            return true;
        }
    }

    return false;
}

public fwd_write_byte(value)
{
    if(last_message_type == message_weap_pickup)
    {
        last_weap_pickup[last_message_id] = value;
    }

    return FMRES_IGNORED;
}

public client_disconnected(id)
{
    arrayset(damages[id], 0, 33);
    assists[id] = 0;
    last_message[id] = 0;
    last_weap_pickup[id] = 0;
    bought_weapon[id] = 0;
    mvp[id][VALUE] = 0.0;
    mvp[id][NORMAL] = 0;
    mvp[id][HS] = 0;
    mvp[id][ASSIST] = 0;
    mvp[id][GRENADE] = false;
    mvp[id][KNIFE] = false;
    mvp[id][PLANTED] = false;
    mvp[id][DEFUSED] = false;
    return PLUGIN_CONTINUE;
}

public clcmd_fullupdate()
{
    return PLUGIN_HANDLED;
}

public client_infochanged(id)
{
    if(is_bit(blockinfo, id))
    {
        return PLUGIN_CONTINUE;
    }

    return get_user_info(id, "name", names[id], 31);
}

public fwd_spawn(id)
{
    if(!is_user_alive(id))
    {
        return HAM_IGNORED;
    }

    set_task(0.1, "ammo_spawn", id);

    new name[32];
    get_user_name(id, name, 31);
    if(!equal(name, names[id]))
    {
        set_msg_block(message_saytext, BLOCK_ONCE);
        set_user_info(id, "name", names[id]);
    }

    arrayset(damages[id], 0, 33);
    last_message[id] = 0;
    last_weap_pickup[id] = 0;
    bought_weapon[id] = 0;
    mvp[id][VALUE] = 0.0;
    mvp[id][NORMAL] = 0;
    mvp[id][HS] = 0;
    mvp[id][ASSIST] = 0;
    mvp[id][GRENADE] = false;
    mvp[id][KNIFE] = false;
    mvp[id][PLANTED] = false;
    mvp[id][DEFUSED] = false;

    return HAM_IGNORED;
}

public ammo_spawn(id)
{
    if(!is_user_connected(id))
    {
        return PLUGIN_CONTINUE;
    }

    new weap_ids[32], num_weaps;
    get_user_weapons(id, weap_ids, num_weaps);

    for(new i = 0; i < num_weaps; i++)
    {
        new weap_id = weap_ids[i];

        if(fill_weapon(id, weap_id))
        {
            fill_bpammo_show(id, weap_id);
        }
    }

    return PLUGIN_CONTINUE;
}

public fwd_damage(id)
{
   if(!is_user_connected(id))
      return PLUGIN_CONTINUE;
    
   if(!(1 <= id <= maxplayers))
      return PLUGIN_CONTINUE;
 
   new aid = get_user_attacker(id);
    
   if(!(1 <= aid <= maxplayers))
      return PLUGIN_CONTINUE;
 
   damages[aid][id] += read_data(2);
 
   return PLUGIN_CONTINUE;
}

public fwd_die()
{
    new vid = read_data(2);
    new kid = read_data(1);
    new ihs = read_data(3);

    new weapon[24];
    read_data(4, weapon, 23);
    if(!(1 <= vid <= maxplayers))
    {
        do_deathmsg(kid, vid, ihs, weapon);
        return PLUGIN_CONTINUE;
    }

    mvp[vid][VALUE] -= 0.5;

    if(kid != vid)
    {
        if((1 <= kid <= maxplayers) && get_user_team(kid) != get_user_team(vid))
        {
            mvp[kid][NORMAL]++;

            if(equal(weapon, "knife"))
            {
                mvp[kid][VALUE] += calculate_mvp(kid, KNIFE_KILL);
                mvp[kid][KNIFE] = true;
            }
            else if(equal(weapon, "grenade"))
            {
                mvp[kid][VALUE] += calculate_mvp(kid, GRENADE_KILL);
                mvp[kid][GRENADE] = true;
            }
            else if(ihs)
            {
                mvp[kid][VALUE] += calculate_mvp(kid, HS_KILL);
                mvp[kid][HS]++;
            }
            else
            {
                mvp[kid][VALUE] += calculate_mvp(kid, NORMAL_KILL);
            }
        }

        new assistid, maxdmg;

        for(new id = 1; id <= maxplayers; id++)
        {
            if(id != kid && is_user_connected(id) && damages[id][vid] >= 50 && damages[id][vid] > maxdmg)
            {
                assistid = id;
                maxdmg = damages[id][vid];
            }

            damages[id][vid] = 0;
        }

        if(assistid)
        {

            mvp[assistid][VALUE] += ASSIST_KILL;
            mvp[assistid][ASSIST]++;

            if(++assists[assistid] == 2)
            {
                set_pev(assistid, pev_frags, float(pev(assistid, pev_frags)) + 1.0);

                assists[assistid] = 0;
            }

            cs_set_user_money(assistid, min(cs_get_user_money(assistid) + 150, 16000), 1);

            if(!(1 <= kid <= maxplayers))
            {
                do_deathmsg(kid, vid, ihs, weapon);
                return PLUGIN_CONTINUE;
            }

            new kname[32], aname[32], newnames[32], wpn[32];

            if(is_user_alive(kid))
            {
                get_user_name(kid, kname, 31);
                get_user_name(assistid, aname, 31);

                copy(names[kid], 31, kname);

                if((strlen(kname) + strlen(aname)) <= 29) {
                    formatex(newnames, 31, "%s + %s", kname, aname);
                } else {
                    formatex(newnames, 28, "%s + %s", kname, aname);
                    add(newnames, 31, "...");
                }

                set_msg_block(message_saytext, BLOCK_ONCE);
                add_bit(blockinfo, kid);

                set_user_info(kid, "name", newnames);
            }

            if(equali(weapon, "grenade"))
            {
                wpn = "weapon_hegrenade";
            }
            else
            {
                formatex(wpn, 31, "weapon_%s", weapon);
            }

            new args[4];
            args[0] = vid;
            args[1] = kid;
            args[2] = ihs;
            args[3] = get_weaponid(wpn);

            set_task(0.1, "fwd_diepost", 0, args, 4);
        }
        else
        {
            do_deathmsg(kid, vid, ihs, weapon);
        }
    }
    else
    {
        do_deathmsg(kid, vid, ihs, weapon);
    }

    return PLUGIN_CONTINUE;
}

public fwd_diepost(arg[])
{
    new weapon[24];
    new kid = arg[1];

    if(!is_user_connected(kid) || !is_user_connected(arg[0]))
    {
        return PLUGIN_CONTINUE;
    }
    if(arg[3] < 0) return 0;
    get_weaponname(arg[3], weapon, 23);

    format(weapon, 22, "%s", weapon[7]);

    if(equal(weapon, "hegrenade"))
    {
        weapon = "grenade";
    }

    do_deathmsg(kid, arg[0], arg[2], weapon);

    set_msg_block(message_saytext, BLOCK_ONCE);
    set_user_info(kid, "name", names[kid]);
    remove_bit(blockinfo, kid);

    return PLUGIN_CONTINUE;
}

public bomb_planted(id)
{
    mvp[id][VALUE] += calculate_mvp(id, BOMB_PLANTED);
    mvp[id][PLANTED] = true;

    return PLUGIN_CONTINUE;
}

public bomb_defused(id)
{
    mvp[id][VALUE] += calculate_mvp(id, BOMB_DEFUSED);
    mvp[id][DEFUSED] = true;

    return PLUGIN_CONTINUE;
}

public fwd_diemsg()
{
    return PLUGIN_HANDLED;
}

stock do_deathmsg(kid, vid, ihd, const wpn[])
{
    message_begin(MSG_ALL, message_deathmsg);
    write_byte(kid);
    write_byte(vid);
    write_byte(ihd);
    write_string(wpn);
    return message_end();
}

stock Float:calculate_mvp(id, Float:val)
{
    new CsTeams:etm, CsTeams:itm = cs_get_user_team(id);
    if(itm == CS_TEAM_CT)
    {
        etm = CS_TEAM_T;
    }
    else if(itm == CS_TEAM_T)
    {
        etm = CS_TEAM_CT;
    }
    else
    {
        return 0.0;
    }

    new icnt = 1, ecnt = 1;

    for(new i = 1; i <= maxplayers; i++)
    {
        if(!is_user_alive(i) || i == id)
        {
            continue;
        }

        if(cs_get_user_team(i) == itm)
        {
            icnt++;
        }
        else if(cs_get_user_team(i) == etm)
        {
            ecnt++;
        }
    }

    return (val * floatclamp((float(ecnt) / float(icnt)), 0.75, 1.3));
}
Имеется плагин. Старый, но мне он нравится.
Проблема:
Плагин иногда меняет ники игроков Например: name1+name2. И не всегда выводит ХУД инфо о лучшем результате игрока.
 
Сверху