#include <amxmodx>
#include <reapi>
enum CVARS
{
SCREENFADE,
SCREENFADE_COLOR_R,
SCREENFADE_COLOR_G,
SCREENFADE_COLOR_B,
MIN_PLAYERS,
ROUND_ACCESS,
Float:GIVE_HEALTH,
Float:INTERVAL_REGENERATION
};
new g_eCvars[CVARS];
new const g_szModel[] = "models/talisman.mdl";
new g_iPlayerId, g_iRoundCounter, szName[32];
new g_ModelInDexTalisman;
public plugin_init()
{
register_plugin("[RE] Talisman", "1.0", "BiZaJe");
register_dictionary("talisman.txt");
RegisterHookChain(RG_CSGameRules_RestartRound, "HC_CSGameRules_RestartRound_Pre", .post = false);
RegisterHookChain(RG_CBasePlayer_Killed, "HC_CBasePlayer_Killed_Post", .post = true);
RegisterCvars();
set_task(g_eCvars[INTERVAL_REGENERATION], "RegenerationHealth", .flags="b");
}
public plugin_precache()
{
g_ModelInDexTalisman = precache_model(g_szModel);
}
public client_disconnected(id)
{
if(g_iPlayerId == id)
TalismanSpawn(id);
}
public HC_CSGameRules_RestartRound_Pre()
{
if(get_member_game(m_bCompleteReset)){
g_iRoundCounter = 0;
}
g_iRoundCounter++;
if(g_iRoundCounter < g_eCvars[ROUND_ACCESS] || get_playersnum() < g_eCvars[MIN_PLAYERS] || g_iPlayerId){
return;
}
static iEnt;
while((iEnt = rg_find_ent_by_class(iEnt, "talisman"))){
set_entvar(iEnt, var_flags, get_entvar(iEnt, var_flags) | FL_KILLME);
set_entvar(iEnt, var_nextthink, get_gametime());
}
static apPlayers[32], iPlayers;
get_players(apPlayers, iPlayers, "ah");
if(!iPlayers){
return;
}
g_iPlayerId = apPlayers[random_num(0, iPlayers-1)];
get_user_name(g_iPlayerId, szName, charsmax(szName));
client_print_color(0, print_team_default, "%L %L", 0, "TALISMAN_PREFIX", 0, "TALISMAN_DROPPED_OUT", szName);
}
public HC_CBasePlayer_Killed_Post(const this, pevAttacker, iGib)
{
if(this == g_iPlayerId)
TalismanSpawn(g_iPlayerId);
}
public Talisman_Think(iEnt, id)
{
if(!is_entity(iEnt) || g_iPlayerId)
return 1;
set_entvar(iEnt, var_flags, get_entvar(iEnt, var_flags) | FL_KILLME);
set_entvar(iEnt, var_nextthink, get_gametime());
get_user_name(g_iPlayerId = id, szName, charsmax(szName));
client_print_color(0, print_team_default, "%L %L", 0, "TALISMAN_PREFIX", 0, "TALISMAN_RAISED" ,szName);
return 1;
}
public RegenerationHealth()
{
if(!g_iPlayerId || get_playersnum() < g_eCvars[MIN_PLAYERS])
return;
static Float:fHealth, MsgId_Health; fHealth = get_entvar(g_iPlayerId, var_health);
if(!MsgId_Health) MsgId_Health = get_user_msgid("Health");
if(fHealth < 100 && is_user_alive(g_iPlayerId))
{
static Float:giveHealth; giveHealth = (fHealth + g_eCvars[GIVE_HEALTH]) < 100 ? g_eCvars[GIVE_HEALTH] : (100 - fHealth);
set_entvar(g_iPlayerId, var_health, fHealth + giveHealth);
message_begin(MSG_ONE_UNRELIABLE, MsgId_Health, _, g_iPlayerId);
write_byte(floatround(fHealth + giveHealth));
message_end();
if(g_eCvars[SCREENFADE]){
message_begin(MSG_ONE_UNRELIABLE, 98, _, g_iPlayerId);
write_short(1<<10);
write_short(1<<10);
write_short(0x0000);
write_byte(g_eCvars[SCREENFADE_COLOR_R]);
write_byte(g_eCvars[SCREENFADE_COLOR_G]);
write_byte(g_eCvars[SCREENFADE_COLOR_B]);
write_byte(40);
message_end();
}
}
}
public RegisterCvars(){
bind_pcvar_num(create_cvar(
"talisman_screenfede",
"1",
FCVAR_NONE,
"Darken the screen when regenerating health"),
g_eCvars[SCREENFADE]
);
bind_pcvar_num(create_cvar(
"talisman_screenfede_color_r",
"0",
FCVAR_NONE,
"screen darkening color (red shade)"),
g_eCvars[SCREENFADE_COLOR_G]
);
bind_pcvar_num(create_cvar(
"talisman_screenfede_color_g",
"255",
FCVAR_NONE,
"screen darkening color (green shade)"),
g_eCvars[SCREENFADE_COLOR_G]
);
bind_pcvar_num(create_cvar(
"talisman_screenfede_color_b",
"0",
FCVAR_NONE,
"screen darkening color (blue shade)"),
g_eCvars[SCREENFADE_COLOR_B]
);
bind_pcvar_num(create_cvar(
"talisman_min_player",
"2",
FCVAR_NONE,
"Minimum number of players to include"),
g_eCvars[MIN_PLAYERS]
);
bind_pcvar_float(create_cvar(
"talisman_give_health",
"5.0",
FCVAR_NONE,
"How much will restore health"),
g_eCvars[GIVE_HEALTH]
);
bind_pcvar_float(create_cvar(
"talisman_reg_interval",
"3.0",
FCVAR_NONE,
"After how many seconds will health be added"),
g_eCvars[INTERVAL_REGENERATION]
);
AutoExecConfig(true, "talisman");
}
stock TalismanSpawn(id)
{
static Float:fOrigin[3];
get_entvar(id, var_origin, fOrigin);
new iEnt = rg_create_entity("info_target", false);
if(!is_entity(iEnt))
return;
set_entvar(iEnt, var_origin, fOrigin);
set_entvar(iEnt, var_classname, "talisman");
set_entvar(iEnt, var_model, g_szModel);
set_entvar(iEnt, var_modelindex, g_ModelInDexTalisman);
set_entvar(iEnt, var_skin, random_num(0, 5));
set_entvar(iEnt, var_solid, SOLID_TRIGGER);
set_entvar(iEnt, var_movetype, MOVETYPE_BOUNCEMISSILE);
set_entvar(iEnt, var_effects, 8);
set_entvar(iEnt, var_mins, Float:{-16.0,-16.0,-16.0})
set_entvar(iEnt, var_maxs, Float:{16.0,16.0,16.0})
client_print_color(g_iPlayerId = 0, print_team_default, "%L %L", 0, "TALISMAN_PREFIX", 0, "TALISMAN_LOST", szName);
SetTouch(iEnt, "Talisman_Think");
}