#include <amxmodx>
#include <engine>
//#define SCREENFADE // Затемнять экран при регенерации здоровья
//#define RENDERING // Подсветка игрока при регенерации здоровья
#define MIN_PLAYERS 4 // Минимальное кол-во игроков для работы плагина
#define ROUND_ACCESS 1 // С какого раунда доступен талисман
#define GIVE_HEALTH 5 // Кол-во выдаваемого здоровья
#define MAX_HEALTH 130 // Максимальное кол-во выдаваемого здоровья игроку
#define INTERVAL_REGENERATION 2.0 // Интервал между восстановлением
new const g_szModel[] = "models/Energy4000.mdl";
new g_iPlayerId, g_iRoundCounter, szName[32];
#if defined SCREENFADE
new g_MsgScreenFade;
new Float:g_fTimeGlare[33];
#endif
public plugin_init()
{
register_plugin("Crux Ansata", "2.0", "DUKKHAZ0R | AcE");
register_touch("Energy4000", "player", "fw_TouchEntity");
register_logevent("eRoundStart", 2, "1=Round_Start");
register_event("DeathMsg", "eDeathMsg", "a", "1>0");
register_event("TextMsg", "eRoundRestart", "a", "2&#Game_C", "2&#Game_w");
#if defined SCREENFADE
register_event("ScreenFade", "EventScreenFade", "b", "4=255", "5=255", "6=255");
g_MsgScreenFade = get_user_msgid("ScreenFade");
#endif
set_task(INTERVAL_REGENERATION, "RegenerationHealth", .flags="b");
}
#if defined SCREENFADE
public EventScreenFade(id)
g_fTimeGlare[id] = read_data(1) / 4096.0 + get_gametime();
#endif
public plugin_precache()
precache_model(g_szModel);
public client_disconnect(id)
{
if(g_iPlayerId == id)
SpawnAnsata(id);
}
public eRoundRestart()
{
g_iRoundCounter = 0;
if(g_iPlayerId)
{
#if defined RENDERING
set_rendering(g_iPlayerId);
#endif
g_iPlayerId = 0;
}
}
public eRoundStart()
{
if(++g_iRoundCounter < ROUND_ACCESS || get_playersnum() < MIN_PLAYERS || g_iPlayerId)
return;
static iEnt;
while((iEnt = find_ent_by_class(iEnt, "Energy4000")))
remove_entity(iEnt);
static apPlayers[32], iPlayers;
get_players(apPlayers, iPlayers, "ach");
g_iPlayerId = apPlayers[random(iPlayers)];
get_user_name(g_iPlayerId, szName, charsmax(szName));
ChatColor(0, "^4[Talisman] ^3%s ^1выпал талисман жизни.", szName);
#if defined RENDERING
set_rendering(g_iPlayerId, kRenderFxGlowShell, 7, 202, 43, kRenderNormal, 25);
#endif
}
public eDeathMsg()
{
if(read_data(2) != g_iPlayerId)
return
#if defined RENDERING
set_rendering(g_iPlayerId);
#endif
SpawnAnsata(g_iPlayerId);
}
public fw_TouchEntity(iEnt, id)
{
if(!is_valid_ent(iEnt))
return;
remove_entity(iEnt);
get_user_name(g_iPlayerId = id, szName, charsmax(szName));
ChatColor(0, "^4[Talisman] ^3%s ^1поднял талисман жизни.", szName);
#if defined RENDERING
set_rendering(g_iPlayerId, kRenderFxGlowShell, 7, 202, 43, kRenderNormal, 25);
#endif
}
public RegenerationHealth()
{
if(!g_iPlayerId || get_playersnum() < MIN_PLAYERS)
return;
static Float:fHealth, MsgId_Health; fHealth = entity_get_float(g_iPlayerId, EV_FL_health);
if(!MsgId_Health) MsgId_Health = get_user_msgid("Health");
if(fHealth > 0 && fHealth < 155)
{
static Float:fNewHealth; fNewHealth = float_min(fHealth + GIVE_HEALTH, MAX_HEALTH.0);
entity_set_float(g_iPlayerId, EV_FL_health, fNewHealth);
message_begin(MSG_ONE_UNRELIABLE, MsgId_Health, _, g_iPlayerId);
write_byte(floatround(fNewHealth));
message_end();
#if defined SCREENFADE
if (get_gametime() >= g_fTimeGlare[g_iPlayerId])
{
message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, _, g_iPlayerId)
write_short(1<<10); write_short(1<<10); write_short(0x0000); write_byte(0);
write_byte(255); write_byte(0); write_byte(40); message_end();
}
#endif
}
}
stock SpawnAnsata(id)
{
static Float:fOrigin[3];
entity_get_vector(id, EV_VEC_origin, fOrigin);
new iEnt = create_entity("info_target");
if(!is_valid_ent(iEnt))
return;
entity_set_vector(iEnt, EV_VEC_origin, fOrigin);
entity_set_string(iEnt, EV_SZ_classname, "Energy4000");
entity_set_int(iEnt, EV_INT_solid, SOLID_TRIGGER);
entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_NONE);
entity_set_int(iEnt, EV_INT_effects, 8);
entity_set_model(iEnt, g_szModel);
entity_set_size(iEnt, Float:{-16.0,-16.0,-16.0}, Float:{16.0,16.0,16.0});
ChatColor(g_iPlayerId = 0, "^4[Talisman] ^3%s ^1потерял талисман жизни.", szName);
}
stock ChatColor(const id, const szMessage[], any:...)
{
static szBuffer[191], apPlayers[32], iPlayers; iPlayers = 1;
vformat(szBuffer, charsmax(szBuffer), szMessage, 3);
if(id)
{
if(!is_user_connected(id)) return;
apPlayers[0] = id;
iPlayers = 1;
}
else get_players(apPlayers, iPlayers, "ch");
for(new i;i < iPlayers; i++)
{
message_begin(MSG_ONE_UNRELIABLE, 76, .player = apPlayers[i]);
write_byte(apPlayers[i]);
write_string(szBuffer);
message_end();
}
}
stock Float:float_min(Float:value1, Float:value2)
return ((value1 < value2) ? value1 : value2);