#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <reapi>
new const CORPSE_CLASSNAME[] = "ent_corpse";
new const SOUND_1[] = "helprevive.wav";
new const Float:CORPSE_MINS[3] = {-48.0, -48.0, 0.0};
new const Float:CORPSE_MAXS[3] = {48.0, 48.0, 24.0};
new Float:FinishButtonTime[33];
new Float:NextPlaySoundTime[33];
new bool:inProgress[33] = false;
new gmsgBarTime;
new MyTarget[33];
new rescount[33];
new g_iCorpse[MAX_PLAYERS + 1]; // у каждого игрока может быть свой энтити трупа
new Float:CorFOrigin[33][3];
public plugin_init(){
register_message(get_user_msgid("ClCorpse"), "@MSG_ClCorpse");
RegisterHookChain(RG_CSGameRules_RestartRound, "event_round_start", false);
RegisterHookChain(RG_CBasePlayer_Spawn, "@CBasePlayer_Spawn_Post", true);
gmsgBarTime = get_user_msgid("BarTime");
}
public event_round_start()
for(new i=1;i<33;i++)
rescount[i]=0;
public plugin_precache(){
precache_sound(SOUND_1); // pssss
}
public client_disconnected(id)
Corpse_Remove(id);
@CBasePlayer_Spawn_Post(id){
Corpse_Remove(id);
inProgress[id] = false;
MyTarget[id] = 0;
NextPlaySoundTime[id] = 0.0;
}
@MSG_ClCorpse(id, dest, player){
new playerId = get_msg_arg_int(12);
if(lastmanstanding(playerId))
return PLUGIN_HANDLED;
if(rescount[playerId] > 0)
return PLUGIN_HANDLED;
new model[PLATFORM_MAX_PATH];
new Float:vecOrigin[3];
new Float:vecAngles[3];
get_msg_arg_string(1, model, charsmax(model));
format(model, charsmax(model), "models/player/%s/%s.mdl", model, model);
for (new i = 0; i < 3; i++){
vecOrigin[i] = float(get_msg_arg_int(2 + i)) / 128.0;
vecAngles[i] = get_msg_arg_float(5 + i);
}
new sequence = get_msg_arg_int(9);
new team = get_msg_arg_int(11);
get_entvar(playerId,var_origin,CorFOrigin);
Corpse_Create(model, vecOrigin, vecAngles, sequence, team, playerId);
return PLUGIN_HANDLED;
}
Corpse_Create(model[], Float:vecOrigin[3], Float:vecAngles[3], sequence, team, owner)
{
new corpse_entity = rg_create_entity("info_target");
if (is_nullent(corpse_entity))
return;
g_iCorpse[owner] = corpse_entity;
set_entvar(corpse_entity, var_origin, vecOrigin);
engfunc(EngFunc_SetModel, corpse_entity, model);
engfunc(EngFunc_SetSize, corpse_entity, CORPSE_MINS, CORPSE_MAXS);
set_entvar(corpse_entity, var_movetype, MOVETYPE_NOCLIP);
set_entvar(corpse_entity, var_solid, SOLID_TRIGGER);
set_entvar(corpse_entity, var_classname, CORPSE_CLASSNAME);
set_entvar(corpse_entity, var_angles, vecAngles);
set_entvar(corpse_entity, var_team, team);
set_entvar(corpse_entity, var_owner, owner);
set_entvar(corpse_entity, var_sequence, sequence);
set_entvar(corpse_entity, var_frame, 30.0);
set_entvar(corpse_entity, var_framerate, 4.0);
set_entvar(corpse_entity, var_animtime, 0.0);
set_entvar(corpse_entity, var_nextthink, 0.2);
SetTouch(corpse_entity, "@Corpse_Touch");
SetThink(corpse_entity, "@Corpse_Think");
}
Corpse_Remove(owner){
new corpse_entity = g_iCorpse[owner];
g_iCorpse[owner] = 0;
if (is_nullent(corpse_entity))
return;
SetTouch(corpse_entity, "");
SetThink(corpse_entity, "");
set_entvar(corpse_entity, var_flags, FL_KILLME);
}
@Corpse_Think(corpse_entity){
if(!is_entity(corpse_entity))
return;
new player[32], players, Float:distance;
new owner = get_entvar(corpse_entity, var_owner);
new Float:origin1[3], Float:origin2[3];
get_entvar(corpse_entity, var_origin, origin1);
get_players(player, players, "ach");
new count = 0;
for (new i = 0; i < players; i++){
if(get_entvar(corpse_entity, var_team) != get_member(player[i], m_iTeam))
continue;
if(inProgress[player[i]]) // если этот игрок уже ресает кого то, то пропускаем его
continue;
if(MyTarget[player[i]] > 0 && MyTarget[player[i]] != owner) // если этот игрок уже стоит рядом с другим трупом, пропускаем его // например, 2 трупа рядом
continue;
get_entvar(player[i], var_origin, origin2);
distance = get_distance_f(origin1, origin2);
if(distance < 150.0){ // воспроизводим звук
set_entvar(corpse_entity, var_renderfx, kRenderFxGlowShell);
set_entvar(corpse_entity, var_rendercolor, {100.0,190.0,100.0});
set_entvar(corpse_entity, var_rendermode, kRenderNormal);
set_entvar(corpse_entity, var_renderamt, 80);
playsound_msg(player[i], corpse_entity);
}
if(distance < 50.0){
MyTarget[player[i]] = owner;
count++;
}
else MyTarget[player[i]] = 0;
}
if(count == 0){
set_entvar(corpse_entity, var_renderfx, kRenderFxNone);
set_entvar(corpse_entity, var_rendercolor, 255,255,255);
set_entvar(corpse_entity, var_rendermode, kRenderNormal);
set_entvar(corpse_entity, var_renderamt, 0.0);
}
set_entvar(corpse_entity, var_nextthink, get_gametime() + 0.2);
}
public playsound_msg(id, corpse_entity){
if(inProgress[id])
return;
if(NextPlaySoundTime[id] <= get_gametime()){
rh_emit_sound2(corpse_entity, 0, CHAN_AUTO, SOUND_1, VOL_NORM, ATTN_NORM);
NextPlaySoundTime[id] = get_gametime() + 6.0;
}
}
@Corpse_Touch(corpse_entity, player){
if(!is_entity(corpse_entity) || !is_user_connected(player))
return;
if(get_member(player, m_iTeam) != get_entvar(corpse_entity, var_team))
return;
new owner = get_entvar(corpse_entity, var_owner);
if(get_entvar(player, var_button) & IN_USE){
if(inProgress[player] == false){
FinishButtonTime[player] = get_gametime() + 6.0;
inProgress[player] = true;
message_begin( MSG_ONE_UNRELIABLE, gmsgBarTime, {0,0,0}, player );
write_byte(6); // duration
write_byte(0);
message_end();
set_entvar(player,var_maxspeed, 1.0);
engclient_cmd(player, "weapon_knife");
return;
}
else{
if(FinishButtonTime[player] <= get_gametime()){
Corpse_Remove(owner);
new name[32],tname[32];get_user_name(player,name,31);get_user_name(owner,tname,31);
ChatColor(0,"^4[TEST] ^1[%s] ^4%s ^1воскресил игрока ^4%s!",get_member(player, m_iTeam) == 1 ? "T" : "CT", name,tname);
rg_round_respawn(owner);
rescount[owner] += 1;
set_entvar(owner, var_origin, CorFOrigin);
inProgress[player] = false;
set_entvar(player,var_maxspeed, 250.0);
return;
}
else{
set_entvar(player,var_maxspeed, 1.0);
engclient_cmd(player, "weapon_knife");
}
}
}
else{
if(inProgress[player] == true){
inProgress[player] = false;
message_begin( MSG_ONE_UNRELIABLE, gmsgBarTime, {0,0,0}, player );
write_byte(0); // duration
write_byte(0);
message_end();
set_entvar(player,var_maxspeed, 250.0);
}
}
}
stock bool:lastmanstanding(id){ // типа если это последний игрок, то всё это нафиг нам не нужно...
new player[32], players;
if(get_member(id, m_iTeam) == 1)
get_players(player, players, "ache","TERRORIST");
else
get_players(player, players, "ache","CT");
if(players < 1)
return true;
return false;
}
stock ChatColor(const id, const szMessage[], any:...){
static msg[191];
vformat(msg, 190, szMessage, 3);
replace_all(msg, 190, "!g", "^4");
replace_all(msg, 190, "!y", "^1");
replace_all(msg, 190, "!t", "^3");
format(msg, 190, "^x01%s", msg);
msg[190] = '^0';
if(id && is_user_connected(id)) {
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, id);
write_byte(id);
write_string(msg);
message_end();
}
else{
for(new i = 1; i <= get_maxplayers(); i++){
if(!is_user_connected(i))
continue;
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, i);
write_byte(i);
write_string(msg);
message_end();
}
}
return 1;
}