2 * dm_spawn_protection.sp
3 * Adds spawn protection to CS:S DM.
4 * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #define K_RENDER_NORMAL 0
29 #define K_RENDER_TRANS_COLOR 1
33 new Handle:g_TColorVar;
34 new Handle:g_CTColorVar;
35 new Handle:g_ProtTimeVar;
36 new g_NormColor[4] = {255, 255, 255, 255};
37 new g_TColor[4] = {255, 0, 0, 128};
38 new g_CTColor[4] = {0, 0, 255, 128};
40 new g_RenderModeOffset;
41 new g_RenderClrOffset;
44 new Handle:g_PlayerTimers[MAXPLAYERS+1];
45 new g_PlayerHealth[MAXPLAYERS+1];
48 public Plugin:myinfo =
50 name = "CS:S DM Spawn Protection",
51 author = "AlliedModders LLC",
52 description = "Spawn protection for CS:S DM",
53 version = CSSDM_VERSION,
54 url = "http://www.bailopan.net/cssdm/"
57 public OnPluginStart()
59 g_ProtVar = CreateConVar("cssdm_spawn_protection", "1", "Sets whether spawn protection is enabled");
60 g_CTColorVar = CreateConVar("cssdm_prot_ctcolor", "0 0 255 128", "Sets the spawn color of CTs");
61 g_TColorVar = CreateConVar("cssdm_prot_tcolor", "255 0 0 128", "Sets the spawn color of Ts");
62 g_ProtTimeVar = CreateConVar("cssdm_prot_time", "2", "Sets time in seconds players are protected for");
64 HookConVarChange(g_CTColorVar, OnColorChange);
65 HookConVarChange(g_TColorVar, OnColorChange);
67 g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
68 g_RenderModeOffset = FindSendPropOffs("CCSPlayer", "m_nRenderMode");
69 g_RenderClrOffset = FindSendPropOffs("CCSPlayer", "m_clrRender");
72 public OnColorChange(Handle:convar, const String:oldValue[], const String:newValue[])
74 decl String:colors[4][12];
76 new num_strings = ExplodeString(newValue, " ", colors, 4, 12);
78 for (new i=0; i<num_strings; i++)
80 clr[i] = StringToInt(colors[i]);
83 if (convar == g_CTColorVar)
86 } else if (convar == g_TColorVar) {
91 public OnClientDisconnect(client)
93 if (g_PlayerTimers[client] != INVALID_HANDLE)
95 CloseHandle(g_PlayerTimers[client]);
96 g_PlayerTimers[client] = INVALID_HANDLE;
100 public Action:DM_OnClientDeath(client)
102 if (g_PlayerTimers[client] != INVALID_HANDLE)
104 CloseHandle(g_PlayerTimers[client]);
105 g_PlayerTimers[client] = INVALID_HANDLE;
108 return Plugin_Continue;
111 public Action:StopProtection(Handle:timer, any:client)
113 g_PlayerTimers[client] = INVALID_HANDLE;
115 SetEntData(client, g_HealthOffset, g_PlayerHealth[client]);
116 UTIL_Render(client, g_NormColor);
121 public DM_OnClientPostSpawned(client)
123 if (!GetConVarInt(g_ProtVar) || !IsClientInGame(client))
128 g_PlayerTimers[client] = CreateTimer(GetConVarFloat(g_ProtTimeVar), StopProtection, client);
130 /* Start protection */
131 g_PlayerHealth[client] = GetEntData(client, g_HealthOffset);
132 SetEntData(client, g_HealthOffset, 1012); /* This overflows to show "500" */
134 new team = GetClientTeam(client);
135 if (team == CSSDM_TEAM_T)
137 UTIL_Render(client, g_TColor);
138 } else if (team == CSSDM_TEAM_CT) {
139 UTIL_Render(client, g_CTColor);
143 UTIL_Render(client, const color[4])
145 new mode = (color[3] == 255) ? K_RENDER_NORMAL : K_RENDER_TRANS_COLOR;
147 SetEntData(client, g_RenderModeOffset, mode, 1);
148 SetEntDataArray(client, g_RenderClrOffset, color, 4, 1);
149 ChangeEdictState(client);