Код
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Hide Day"
#define VERSION "1.0"
#define AUTHOR "Bizz"
#pragma semicolon 1
new msgScreenFade, maxplayers, bool:is_hide, bool:is_hide_after, Float:user_speed[33], MsgSync;
const left_time = 35; // Second
const OFFSET_CSTEAMS = 114;
const OFFSET_LINUX = 5;
enum (+= 100)
{
LIMIT_ID = 3000
}
enum
{
FM_CS_TEAM_UNASSIGNED = 0,
FM_CS_TEAM_T,
FM_CS_TEAM_CT,
FM_CS_TEAM_SPECTATOR
}
new const race_go[] = "jb/race_go.mp3";
public plugin_precache()
{
engfunc(EngFunc_PrecacheSound, race_go);
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_dictionary("hide_day.txt");
register_clcmd("say /hide", "clcmd_hide", ADMIN_BAN, "Start hide day");
register_event("HLTV", "event_round_start", "a", "1=0", "2=0");
RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1);
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage");
register_message(get_user_msgid("CurWeapon"), "message_cur_weapon");
msgScreenFade = get_user_msgid("ScreenFade");
maxplayers = get_maxplayers();
MsgSync = CreateHudSyncObj();
}
public event_round_start()
{
remove_task(LIMIT_ID);
RemoveLimit();
is_hide_after = false;
}
public message_cur_weapon(msg_id, msg_dest, msg_entity)
{
if (!is_hide || !is_user_alive(msg_entity) || fm_cs_get_user_team(msg_entity) != FM_CS_TEAM_CT) return;
set_pev(msg_entity, pev_maxspeed, 1.0);
}
public fw_PlayerSpawn_Post(id)
{
if (!is_hide || !is_user_alive(id) || fm_cs_get_user_team(id) != FM_CS_TEAM_CT) return;
SetLimit(id);
}
public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
if (victim == attacker || !is_user_connected(attacker)) return HAM_IGNORED;
if (is_hide && fm_cs_get_user_team(attacker) == FM_CS_TEAM_CT) return HAM_SUPERCEDE;
if ((is_hide_after || is_hide) && fm_cs_get_user_team(attacker) == FM_CS_TEAM_T && GetCountAliveT() > 1) return HAM_SUPERCEDE;
return HAM_IGNORED;
}
public clcmd_hide(id, level, cid)
{
if (is_hide || !cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED;
client_cmd(id, "jbe_open"); // Open jail doors
client_cmd(0, "mp3 play ^"sound/%s^"", race_go); // Sound
static i;
for (i = 1; i <= maxplayers; i++)
{
if (!is_user_alive(i) || fm_cs_get_user_team(i) != FM_CS_TEAM_CT) continue;
SetLimit(i);
}
set_task(float(left_time), "RemoveLimit", LIMIT_ID);
is_hide = true;
HudLeft();
return PLUGIN_HANDLED;
}
SetLimit(id)
{
message_begin(MSG_ONE, msgScreenFade, _, id);
write_short(1<<12);
write_short(1<<8);
write_short(1<<0);
write_byte(0);
write_byte(0);
write_byte(0);
write_byte(255);
message_end();
pev(id, pev_maxspeed, user_speed[id]);
set_pev(id, pev_maxspeed, 1.0);
set_task(0.8, "DelayFade", id);
}
RemoveFade(id)
{
message_begin(MSG_ONE, msgScreenFade, _, id);
write_short(1<<12);
write_short(1<<8);
write_short(1<<1);
write_byte(0);
write_byte(0);
write_byte(0);
write_byte(255);
message_end();
set_pev(id, pev_maxspeed, user_speed[id]);
}
public DelayFade(id)
{
message_begin(MSG_ONE, msgScreenFade, _, id);
write_short(1<<0);
write_short(1<<0);
write_short(1<<2);
write_byte(0);
write_byte(0);
write_byte(0);
write_byte(255);
message_end();
}
public RemoveLimit()
{
static i;
for (i = 1; i <= maxplayers; i++)
{
if (!is_user_alive(i) || fm_cs_get_user_team(i) != FM_CS_TEAM_CT) continue;
RemoveFade(i);
}
is_hide = false;
is_hide_after = true;
}
public HudLeft()
{
static show_time;
if (!is_hide)
{
if (is_hide_after)
{
set_hudmessage(0, 255, 0, 0.35, 0.20, 0, 6.0, 5.0, 0.0, 0.0, -1);
show_hudmessage(0, "%L", LANG_PLAYER, "HUD_GO");
}
show_time = 0;
return;
}
if (!show_time) show_time = left_time;
set_hudmessage(0, 255, 0, 0.31, 0.10, 0, 6.0, 1.1, 0.0, 0.0, -1);
ShowSyncHudMsg(0, MsgSync, "%L", LANG_PLAYER, "HUD_LEFT", show_time--);
set_task(1.0, "HudLeft");
}
stock fm_cs_get_user_team(id)
{
return get_pdata_int(id, OFFSET_CSTEAMS, OFFSET_LINUX);
}
stock GetCountAliveT()
{
static i, count;
for (i = 1, count = 0; i <= maxplayers; i++)
if (is_user_alive(i) && fm_cs_get_user_team(i) == FM_CS_TEAM_T) count++;
return count;
}