// #define API // включить API (возможности для других плагинов)
// #define MODELS // мертвецы смогут иметь уникальные модельки (может быть небольшой конфликт с вашими админ/вип моделями)
#include <amxmodx>
#include <fakemeta>
#include <reapi>
// ========================================================================== //
new const BODY_CLASSNAME[] = "player_corpse";
#define StartRevive(%1) (set_entvar(%1, var_iuser1, 1))
#define StopRevive(%1) (set_entvar(%1, var_iuser1, 0))
#define IsReviving(%1) (get_entvar(%1, var_iuser1) == 1)
#define IsValidTeam(%1) (TEAM_TERRORIST <= get_member(%1, m_iTeam) <= TEAM_CT)
new const SOUND_REVIVED[] = "weapons/c4_disarmed.wav"; // звук при завершении возрождения
#if defined MODELS
new const MODEL_REVIVED_T[] = "vip"; // модель воскрешенного игрока Т
new const MODEL_REVIVED_CT[] = "vip"; // модель воскрешенного игрока КТ
#endif
// ========================================================================== //
enum any:CVARS
{
ACCESS_FLAG[10],
DURATION,
ROUND,
Float:ROUND_TIME,
PER_ROUND,
MAX_USER,
SHOOT,
Float:SPEED,
Float:DISTANCE,
Float:FLOOD,
Float:DELAY,
SPAWN,
Float:SPEED,
Float:HEALTH,
GUN[24],
COST,
PROGRESS_BAR,
BOMB,
ONE_VS_ONE,
VIP,
DIFF,
SOUND_MODE,
NOTIFICATION
}; new g_CvarValue[CVARS];
enum any:PLAYER_DATA
{
Corpse,
ReviveIndex,
ReviveCount,
Float:flDelay,
Float:flSpawnDelay
}; new g_PlayersData[MAX_PLAYERS + 1][PLAYER_DATA];
#if defined API
enum any:Forwards
{
Fw_Return,
Fw_Revive_Start,
Fw_Revived
}; new gForwards[Forwards];
#endif
// other
new iRoundPlayed, mBombPlanted, iFlagsBitSum;
public plugin_precache()
{
precache_sound(SOUND_REVIVED);
#if defined MODELS
new model_path[128];
formatex(model_path, charsmax(model_path), "models/player/%s/%s.mdl", MODEL_REVIVED_T, MODEL_REVIVED_T);
precache_model(model_path);
formatex(model_path, charsmax(model_path), "models/player/%s/%sT.mdl", MODEL_REVIVED_T, MODEL_REVIVED_T);
if (file_exists(model_path)) precache_model(model_path);
formatex(model_path, charsmax(model_path), "models/player/%s/%s.mdl", MODEL_REVIVED_CT, MODEL_REVIVED_CT);
precache_model(model_path);
formatex(model_path, charsmax(model_path), "models/player/%s/%sT.mdl", MODEL_REVIVED_CT, MODEL_REVIVED_CT);
if (file_exists(model_path)) precache_model(model_path);
#endif
}
public plugin_init()
{
register_plugin("Revive Players", "1.0.0", "Emma Jule");
register_dictionary("revive_teammates.txt");
register_message(get_user_msgid("ClCorpse"), "MsgHookClCorpse");
register_forward(FM_CmdStart, "fw_CmdStart");
RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn_Post", true);
RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound", false);
#if defined MODELS
RegisterHookChain(RG_CBasePlayer_SetClientUserInfoModel, "CBasePlayer_SetClientUserInfoModel", false);
#endif
CreateCvars();
#if defined API
gForwards[Fw_Revive_Start] = CreateMultiForward("rt_start_revive", ET_CONTINUE, FP_CELL, FP_CELL);
gForwards[Fw_Revived] = CreateMultiForward("rt_revived", ET_IGNORE, FP_CELL, FP_CELL);
}
public plugin_natives()
{
// register_library("ReviveTeammates");
register_native("is_user_revivng", "native_is_reviving");
}
public native_is_reviving(plugin_id, num_params)
{
// this dangerous
return is_nullent(g_PlayersData[get_param(1)][ReviveIndex]) ? false : true;
}
#else
}
#endif
public client_disconnected(id)
{
if (task_exists(id)) remove_task(id);
CorpseRemove(id);
}
public CBasePlayer_Spawn_Post(const id)
{
CorpseRemove(id);
arrayset(g_PlayersData[id], 0, PLAYER_DATA);
#if defined MODELS
rg_reset_user_model(id);
rh_update_user_info(id);
#endif
}
public CSGameRules_RestartRound()
{
iRoundPlayed = get_member_game(m_bCompleteReset) ? 0 : ++iRoundPlayed;
mBombPlanted = false;
}
public fw_CmdStart(id, uc_handle)
{
// it's checking time..
if (!is_user_alive(id))
return;
if (get_member_game(m_bRoundTerminating))
return;
if (iRoundPlayed < g_CvarValue[ROUND])
return;
if (abs(get_member_game(m_iNumTerroristWins) - get_member_game(m_iNumCTWins)) > g_CvarValue[DIFF])
return;
if (~get_user_flags(id) & iFlagsBitSum)
return;
if (g_CvarValue[VIP] && get_member(id, m_bIsVIP))
return;
if (g_CvarValue[BOMB] && mBombPlanted)
return;
new Float:gametime = get_gametime();
if (gametime - Float:get_member_game(m_fRoundStartTime) < g_CvarValue[ROUND_TIME])
return;
if (g_CvarValue[ONE_VS_ONE] && rg_is_1v1())
return;
if (get_member(id, m_iAccount) < g_CvarValue[COST])
return;
if (g_CvarValue[PER_ROUND] && g_PlayersData[id][ReviveCount] >= g_CvarValue[PER_ROUND])
return;
if (g_PlayersData[id][flDelay] > gametime)
return;
if (get_uc(uc_handle, UC_Buttons) & IN_USE && ~get_entvar(id, var_oldbuttons) & IN_USE && !g_PlayersData[id][ReviveIndex])
{
start_revive(id);
}
else if (get_entvar(id, var_oldbuttons) & IN_USE && ~get_uc(uc_handle, UC_Buttons) & IN_USE && g_PlayersData[id][ReviveIndex])
{
stop_revive(id);
}
}
public CBasePlayer_ResetMaxSpeed_Post(const this)
{
if (g_PlayersData[this][ReviveIndex])
{
set_entvar(this, var_maxspeed, g_CvarValue[SPEED]);
}
}
#if defined MODELS
public CBasePlayer_SetClientUserInfoModel(const id, infobuffer[], szNewModel[])
{
if (get_member(id, m_iNumSpawns) > 1)
{
new szModel[32]; copy(szModel, charsmax(szModel), get_member(id, m_iTeam) == TEAM_CT ? MODEL_REVIVED_CT : MODEL_REVIVED_T);
if (strcmp(szNewModel, szModel) != 0) SetHookChainArg(3, ATYPE_STRING, szModel);
}
return HC_CONTINUE;
}
#endif
// Bomb Featrues
public PlantBomb()
{
mBombPlanted = true;
}
start_revive(id)
{
if (g_PlayersData[id][ReviveIndex])
{
stop_revive(id);
}
new pArray[MAX_PLAYERS], pNum;
get_players(pArray, pNum, "be", get_member(id, m_iTeam) == TEAM_CT ? "CT" : "TERRORIST");
if (!pArray[0] || !pNum)
return;
new Float:flPlayerOrigin[3]; get_entvar(id, var_origin, flPlayerOrigin);
for (new i, pPlayer, pEnt, Float:flEntityOrigin[3]; i < pNum; i++)
{
pPlayer = pArray[i];
pEnt = g_PlayersData[pPlayer][Corpse];
if (is_nullent(pEnt))
continue;
if (IsReviving(pEnt))
continue;
/* ?
if (get_entvar(pEnt, var_owner) != pPlayer)
continue;
*/
get_entvar(pEnt, var_origin, flEntityOrigin);
if (vector_distance(flPlayerOrigin, flEntityOrigin) > g_CvarValue[DISTANCE])
continue;
if (g_CvarValue[DELAY])
{
if (g_PlayersData[pPlayer][flSpawnDelay] > get_gametime())
continue;
}
if (g_CvarValue[MAX_USER])
{
if (get_member(pPlayer, m_iNumSpawns) > g_CvarValue[MAX_USER])
continue;
}
#if defined API
ExecuteForward(gForwards[Fw_Revive_Start], gForwards[Fw_Return], pPlayer, id);
if (gForwards[Fw_Return] >= PLUGIN_HANDLED)
continue;
#endif
client_print(id, print_center, "%l", "RT_REVIVING", pPlayer);
client_print(pPlayer, print_center, "%l", "RT_REVIVING2", id);
StartRevive(pEnt);
g_PlayersData[id][ReviveIndex] = pEnt;
if (g_CvarValue[SPEED])
{
rg_reset_maxspeed(id);
}
if (g_CvarValue[PROGRESS_BAR])
{
rg_send_bartime(id, g_CvarValue[DURATION], bool:(g_CvarValue[PROGRESS_BAR] == 1));
}
if (!g_CvarValue[SHOOT])
{
set_member(id, m_bIsDefusing, true);
}
set_task(float(g_CvarValue[DURATION]), "respawn_friendly", id);
RequestFrame("CBasePlayer_PreThink", id);
break;
}
}
stop_revive(id)
{
if (!g_PlayersData[id][ReviveIndex])
return;
new ent = g_PlayersData[id][ReviveIndex];
StopRevive(ent);
g_PlayersData[id][ReviveIndex] = 0;
g_PlayersData[id][flDelay] = get_gametime() + g_CvarValue[FLOOD];
if (g_CvarValue[SPEED])
{
rg_reset_maxspeed(id);
}
if (g_CvarValue[PROGRESS_BAR])
{
rg_send_bartime(id, 0);
}
if (!g_CvarValue[SHOOT])
{
set_member(id, m_bIsDefusing, false);
}
// I think that mistake(
if (task_exists(id)) remove_task(id);
}
public CBasePlayer_PreThink(id)
{
if (!is_user_alive(id))
{
stop_revive(id);
}
else
{
if (!g_PlayersData[id][ReviveIndex])
return;
new Float:origin[3], Float:origin2[3];
get_entvar(id, var_origin, origin);
get_entvar(g_PlayersData[id][ReviveIndex], var_origin, origin2);
if (vector_distance(origin, origin2) > g_CvarValue[DISTANCE])
{
stop_revive(id);
client_print_color(id, print_team_red, "%l %l", "RT_PREFIX", "RT_DISTANCE_FAIL");
}
else
{
RequestFrame("CBasePlayer_PreThink", id);
}
}
}
public respawn_friendly(id)
{
new ent = g_PlayersData[id][ReviveIndex];
if (is_nullent(ent))
return;
stop_revive(id);
new player = get_entvar(ent, var_owner);
if (get_member_game(m_bRoundTerminating) || get_member(player, m_iTeam) != get_entvar(ent, var_team))
return;
// cvars gameplay checking
if (g_CvarValue[BOMB] && mBombPlanted || g_CvarValue[ONE_VS_ONE] && rg_is_1v1() || get_member(id, m_iAccount) < g_CvarValue[COST])
return;
rg_round_respawn(player);
if (g_CvarValue[SPAWN])
{
new Float:fOrigin[3]; get_entvar(ent, var_origin, fOrigin);
engfunc(EngFunc_SetOrigin, player, fOrigin);
set_entvar(player, var_flags, get_entvar(player, var_flags) | FL_DUCKING);
set_entvar(player, var_view_ofs, Float:{ 0.0, 0.0, 12.0 });
}
set_entvar(player, var_health, g_CvarValue[HEALTH]);
if (g_CvarValue[GUN][0])
{
new item = rg_give_item(player, fmt("weapon_%s", g_CvarValue[GUN]), GT_APPEND);
if (!is_nullent(item))
{
new WeaponIdType:weaponId = get_member(item, m_iId);
set_member(player, m_rgAmmo, rg_get_weapon_info(weaponId, WI_MAX_ROUNDS), rg_get_weapon_info(weaponId, WI_AMMO_TYPE));
}
}
else
{
rg_remove_all_items(player);
rg_give_default_items(player);
}
switch (g_CvarValue[NOTIFICATION])
{
case 1: client_print_color(0, id, "%l %l", "RT_PREFIX", "RT_NOTIFY_ALL", id, player);
case 2:
{
client_print_color(id, player, "%l %l", "RT_PREFIX", "RT_NOTIFY_OWNER", player);
client_print_color(player, id, "%l %l", "RT_PREFIX", "RT_NOTIFY_REVIVED", id);
}
}
switch (g_CvarValue[SOUND_MODE])
{
case 1: rh_emit_sound2(id, 0, CHAN_BODY, SOUND_REVIVED);
case 2:
{
rg_send_audio(id, SOUND_REVIVED);
rg_send_audio(player, SOUND_REVIVED);
}
}
#if defined API
ExecuteForward(gForwards[Fw_Revived], gForwards[Fw_Return], player, id);
#endif
rg_add_account(id, -g_CvarValue[COST]);
g_PlayersData[id][ReviveCount]++;
g_PlayersData[player][flSpawnDelay] = get_gametime() + g_CvarValue[DELAY];
}
public MsgHookClCorpse()
{
new ent = rg_create_entity("info_target");
if (is_nullent(ent))
return PLUGIN_CONTINUE;
new player = get_msg_arg_int(12);
if (!IsValidTeam(player))
return PLUGIN_CONTINUE;
g_PlayersData[player][Corpse] = ent;
new Float:origin[3], Float:angles[3];
get_entvar(player, var_origin, origin);
get_entvar(player, var_angles, angles);
/*
for (new i; i < 2; i++)
{
origin[i] = float(get_msg_arg_int(2 + i)) / 128.0;
angles[i] = get_msg_arg_float(5 + i);
}
*/
new model[32]; get_msg_arg_string(1, model, charsmax(model));
engfunc(EngFunc_SetModel, ent, fmt("models/player/%s/%s.mdl", model, model));
engfunc(EngFunc_SetSize, ent, Float:{ -24.0, -24.0, 0.0 }, Float:{ 24.0, 24.0, 24.0 });
engfunc(EngFunc_SetOrigin, ent, origin);
//engfunc(EngFunc_DropToFloor, ent);
set_entvar(ent, var_classname, BODY_CLASSNAME);
set_entvar(ent, var_angles, angles);
set_entvar(ent, var_body, get_msg_arg_int(10));
set_entvar(ent, var_framerate, 1.0);
set_entvar(ent, var_animtime, 0.0);
set_entvar(ent, var_sequence, get_msg_arg_int(9));
set_entvar(ent, var_owner, player);
set_entvar(ent, var_team, get_msg_arg_int(11));
StopRevive(ent);
return PLUGIN_HANDLED;
}
CreateCvars()
{
// флаг доступа
bind_pcvar_string(create_cvar("rt_access_flag", "", .description = "Флаг(и) доступа администратора (^"^" - доступно всем)"), g_CvarValue[ACCESS_FLAG], charsmax(g_CvarValue[ACCESS_FLAG]));
iFlagsBitSum = read_flags(g_CvarValue[ACCESS_FLAG]);
// время события
bind_pcvar_num(create_cvar("rt_duration", "5", .description = "Время через которое воскреснит союзник", .has_min = true, .min_val = 1.0, .has_max = true, .max_val = 10.0), g_CvarValue[DURATION]);
// ограничение по раундам
bind_pcvar_num(create_cvar("rt_round", "3", .description = "С какого раунда это будет доступно?", .has_min = true), g_CvarValue[ROUND]);
// ограничение по времени
bind_pcvar_float(create_cvar("rt_round_time", "10.0", .description = "Это будет доступно через Х сек. от начала раунда [0 - выкл]", .has_min = true, .has_max = true, .max_val = 30.0), g_CvarValue[ROUND_TIME]);
// ограничение по кол-ву
bind_pcvar_num(create_cvar("rt_per_round", "0", .description = "Максимальное кол-во раз сколько может игрок воскресить союзников за раунд [0 - бесконечно]", .has_min = true), g_CvarValue[PER_ROUND]);
// ограничение по кол-ву
bind_pcvar_num(create_cvar("rt_max_respawns", "0", .description = "Максимальное кол-во раз сколько может воскреснуть игрок за раунд [0 - бесконечно]", .has_min = true), g_CvarValue[MAX_USER]);
// запрещаем стрельбу
bind_pcvar_num(create_cvar("rt_can_shoot", "1", .description = "Могу ли я стрелять во время события", .has_min = true, .has_max = true, .max_val = 1.0), g_CvarValue[SHOOT]);
// скорость
bind_pcvar_float(create_cvar("rt_speed", "150.0", .description = "Скорость игрока во время события [0 - будет неизменной]", .has_min = true, .has_max = true, .max_val = 250.0), g_CvarValue[SPEED]);
if (g_CvarValue[SPEED]) RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "CBasePlayer_ResetMaxSpeed_Post", true);
// дистанция
bind_pcvar_float(create_cvar("rt_distance", "150.0", .description = "Максимальная допустимая дистанция", .has_min = true, .min_val = 64.0, .has_max = true, .max_val = 300.0), g_CvarValue[DISTANCE]);
// спам
bind_pcvar_float(create_cvar("rt_flood", "1.0", .description = "Через сколько могу использовать вновь (spam protect)", .has_min = true, .min_val = 0.1), g_CvarValue[FLOOD]);
// ограничение по времени
bind_pcvar_float(create_cvar("rt_delay", "15.0", .description = "Через сколько можно будет воскрешать умершего игрока", .has_min = true, .has_max = true, .max_val = 15.0), g_CvarValue[DELAY]);
// спаун-режим
bind_pcvar_num(create_cvar("rt_spawn_mode", "1", .description = "Режим возрождения^n^n0. возрождается на базе^n1. возрождается там где умер", .has_min = true, .has_max = true, .max_val = 1.0), g_CvarValue[SPAWN]);
// здоровье
bind_pcvar_float(create_cvar("rt_health", "50.0", .description = "здоровье воскрешенного игрока", .has_min = true, .min_val = 1.0, .has_max = true, .max_val = 255.0), g_CvarValue[HEALTH]);
// аммуниция
bind_pcvar_string(create_cvar("rt_weapon", "", .description = "Оружиме воскрешенного игрока (^"^" - как обычно Т - glock | CT - usp)"), g_CvarValue[GUN], charsmax(g_CvarValue[GUN]));
if (!CheckIsCvarPossible(g_CvarValue[GUN])) server_print("[Revive Teammates] Некорректно заполнен квар rt_weapon");
// стоимость
bind_pcvar_num(create_cvar("rt_cost", "0", .description = "Стоимость услуги [0 - соответственно бесплатно]", .has_min = true), g_CvarValue[COST]);
// полоска
bind_pcvar_num(create_cvar("rt_progress_bar", "1", .description = "Линия прогресса^n^n0. выкл^n1. вкл^n2. вкл (но те кто наблюдают за игроком не увидят это)", .has_min = true, .has_max = true, .max_val = 2.0), g_CvarValue[PROGRESS_BAR]);
// бомба
bind_pcvar_num(create_cvar("rt_bomb", "0", .description = "Блокируем возрождения когда бобма установленна?", .has_min = true, .has_max = true, .max_val = 1.0),g_CvarValue[BOMB]);
if (g_CvarValue[BOMB] && get_member_game(m_bMapHasBombTarget)) RegisterHookChain(RG_PlantBomb, "PlantBomb", true);
// 1 vs 1
bind_pcvar_num(create_cvar("rt_1v1", "0", .description = "Блокируем возрождения когда остались 1 vs 1?", .has_min = true, .has_max = true, .max_val = 1.0), g_CvarValue[ONE_VS_ONE]);
// VIP
bind_pcvar_num(create_cvar("rt_vip", "1", .description = "Сможет ли VIP игрок воскрешать союзников? (на as_* картах)", .has_min = true, .has_max = true, .max_val = 1.0), g_CvarValue[VIP]);
// балансер
bind_pcvar_num(create_cvar("rt_score_diff", "20", .description = "Если разница между победами команд превышает это значение, то мы блокируем воскрешения?", .has_min = true, .min_val = 3.0), g_CvarValue[DIFF]);
// звуки
bind_pcvar_num(create_cvar("rt_sounds", "1", .description = "Звуки событий (изменить их вы можете в исходном коде^n^n0. выкл^n1. через rh_emit_sound2^n2. через rg_send_audio (исключительно игроку)", .has_min = true, .has_max = true, .max_val = 2.0), g_CvarValue[SOUND_MODE]);
// уведомления
bind_pcvar_num(create_cvar("rt_notifications", "1", .description = "Уведомления..^n^n0. выкл^n1. видно всем^n2. только воскресившему игроку и тот кто воскрешал его", .has_min = true, .has_max = true, .max_val = 2.0), g_CvarValue[NOTIFICATION]);
// расположение: ..ddir/addons/amxmodx/configs/plugins/ReviveTeammates.cfg
AutoExecConfig(.name = "ReviveTeammates");
}
CorpseRemove(id)
{
new corpse = g_PlayersData[id][Corpse];
if (!is_nullent(corpse)) set_entvar(corpse, var_flags, FL_KILLME);
g_PlayersData[id][Corpse] = 0;
}
CheckIsCvarPossible(const cvar[])
{
if (!cvar[0])
return true;
// ConnorMcLeod
new const weaponEntities[][] = { "p228", "scout", "xm1014", "mac10", "aug", "elite",
"fiveseven", "ump45", "sg550", "galil", "famas", "usp", "glock18", "awp", "mp5navy",
"m249", "m3", "m4a1", "tmp", "g3sg1", "deagle", "sg552", "ak47", "p90" };
for (new i; i < sizeof(weaponEntities); i++)
if (strcmp(weaponEntities[i], cvar) == 0)
return true;
return false;
}
stock bool:rg_is_1v1()
{
new alive_t, alive_ct; rg_initialize_player_counts(alive_t, alive_ct);
return bool:(alive_t == 1 && alive_ct == 1);
}