#include <morecolors>
#pragma tabsize 0
#pragma semicolon 1
#pragma newdecls required
// Offset
int g_iRenderOffset;
// ConVar
float g_fProtectionTime;
char g_szProtectionColor[PLATFORM_MAX_PATH];
bool g_bIsProtectionEnabled, g_bIsProtectionNotifyEnabled;
public Plugin myinfo = {
name = "Spawn Protection",
author = "Fair Party (rew. by xyligan)",
version = "2 (fix)"
}
public void OnPluginStart() {
if ((g_iRenderOffset = FindSendPropInfo("CBasePlayer", "m_clrRender")) == -1) {
SetFailState("CBasePlayer::m_clrRender");
}
ConVar cvar;
cvar = CreateConVar("sp_on", "1", "Включить/Выключить плагин [0 - Выключить | 1 - Включить]", _, true, 0.0, true, 1.0);
cvar.AddChangeHook(CVarChanged_Protection_Enabled);
g_bIsProtectionEnabled = cvar.BoolValue;
cvar = CreateConVar("sp_time", "5", "Время в сек. на протяжении которого игрок будет защищен от убийства", _, true, 0.0, true, 100.0);
cvar.AddChangeHook(CVarChanged_Protection_Time);
g_fProtectionTime = cvar.FloatValue;
cvar = CreateConVar("sp_notify", "1", "Включить/Выключить оповещения [0 - Выключить | 1 - Включить]", _, true, 0.0, true, 1.0);
cvar.AddChangeHook(CVarChanged_Protection_Notify_Enabled);
g_bIsProtectionNotifyEnabled = cvar.BoolValue;
cvar = CreateConVar("sp_color", "0 255 0 120", "Цвет игрока во время наличия защиты");
cvar.AddChangeHook(CVarChanged_Protection_Color);
cvar.GetString(g_szProtectionColor, sizeof(g_szProtectionColor));
AutoExecConfig(true, "spawn_protection");
HookEvent("player_spawn", Event_PlayerSpawn);
}
public void CVarChanged_Protection_Enabled(ConVar cvar, const char[] oldValue, const char[] newValue) {
g_bIsProtectionEnabled = cvar.BoolValue;
}
public void CVarChanged_Protection_Time(ConVar CVar, const char[] oldValue, const char[] newValue) {
g_fProtectionTime = CVar.FloatValue;
}
public void CVarChanged_Protection_Notify_Enabled(ConVar cvar, const char[] oldValue, const char[] newValue) {
g_bIsProtectionEnabled = cvar.BoolValue;
}
public void CVarChanged_Protection_Color(ConVar cvar, const char[] oldValue, const char[] newValue) {
cvar.GetString(g_szProtectionColor, sizeof(g_szProtectionColor));
}
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontbroadcast) {
if (g_bIsProtectionEnabled) {
int client = GetClientOfUserId(event.GetInt("userid"));
if (!IsPlayerAlive(client))return Plugin_Continue;
char colors[4][4];
ExplodeString(g_szProtectionColor, " ", colors, sizeof colors, sizeof colors[]);
SetEntProp(client, Prop_Data, "m_takedamage", 0, 1);
SetRendering(client, RENDERFX_DISTORT, StringToInt(colors[0]), StringToInt(colors[1]), StringToInt(colors[2]), RENDER_TRANSADD, StringToInt(colors[3]));
CreateTimer(g_fProtectionTime, Timer_RemoveProtection, GetClientUserId(client));
if (g_bIsProtectionNotifyEnabled) {
CPrintToChat(client, "{green}[{fullred}Защита игроков{green}] {fullred}Вы {white}будете {fullred}защищены {white}в течение {fullred}%f {white}сек.", RoundToNearest(g_fProtectionTime));
}
}
return Plugin_Continue;
}
public Action Timer_RemoveProtection(Handle hTimer, int iUserID) {
int client = GetClientOfUserId(iUserID);
if (client && IsClientInGame(client)) {
SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
SetRendering(client);
if (g_bIsProtectionNotifyEnabled) {
CPrintToChat(client, "{green}[{fullred}Защита игроков{green}] {fullred}Защита {white}теперь {fullred}отключена{white}...");
}
}
}
stock void SetRendering(int client, RenderFx hFx = RENDERFX_NONE, int iR = 255, int iG = 255, int iB = 255, RenderMode hRender = RENDER_NORMAL, int iAmount = 255) {
SetEntProp(client, Prop_Send, "m_nRenderFX", hFx, 1);
SetEntProp(client, Prop_Send, "m_nRenderMode", hRender, 1);
SetEntData(client, g_iRenderOffset, iR, 1, true);
SetEntData(client, g_iRenderOffset + 1, iG, 1, true);
SetEntData(client, g_iRenderOffset + 2, iB, 1, true);
SetEntData(client, g_iRenderOffset + 3, iAmount, 1, true);
}