Change SetEntData to SetEntProp, Fix giving helmet wrongly.
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
5 * by David "BAILOPAN" Anderson, http://www.bailopan.net/cssdm/
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #define K_RENDER_NORMAL 0
30 #define K_RENDER_TRANS_COLOR 1
34 new Handle:g_TColorVar;
35 new Handle:g_CTColorVar;
36 new Handle:g_ProtTimeVar;
37 new g_NormColor[4] = {255, 255, 255, 255};
38 new g_TColor[4] = {255, 0, 0, 128};
39 new g_CTColor[4] = {0, 0, 255, 128};
41 new g_RenderModeOffset;
42 new g_RenderClrOffset;
45 new Handle:g_PlayerTimers[MAXPLAYERS+1];
46 new g_PlayerHealth[MAXPLAYERS+1];
49 public Plugin:myinfo =
51 name = "CS:S DM Spawn Protection",
52 author = "AlliedModders LLC",
53 description = "Spawn protection for CS:S DM",
54 version = CSSDM_VERSION,
55 url = "http://www.bailopan.net/cssdm/"
58 public OnPluginStart()
60 g_ProtVar = CreateConVar("cssdm_spawn_protection", "1", "Sets whether spawn protection is enabled");
61 g_CTColorVar = CreateConVar("cssdm_prot_ctcolor", "0 0 255 128", "Sets the spawn color of CTs");
62 g_TColorVar = CreateConVar("cssdm_prot_tcolor", "255 0 0 128", "Sets the spawn color of Ts");
63 g_ProtTimeVar = CreateConVar("cssdm_prot_time", "2", "Sets time in seconds players are protected for");
65 HookConVarChange(g_CTColorVar, OnColorChange);
66 HookConVarChange(g_TColorVar, OnColorChange);
68 g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
69 g_RenderModeOffset = FindSendPropOffs("CCSPlayer", "m_nRenderMode");
70 g_RenderClrOffset = FindSendPropOffs("CCSPlayer", "m_clrRender");
73 public OnColorChange(Handle:convar, const String:oldValue[], const String:newValue[])
75 decl String:colors[4][12];
77 new num_strings = ExplodeString(newValue, " ", colors, 4, 12);
79 for (new i=0; i<num_strings; i++)
81 clr[i] = StringToInt(colors[i]);
84 if (convar == g_CTColorVar)
87 } else if (convar == g_TColorVar) {
92 public OnClientDisconnect(client)
94 if (g_PlayerTimers[client] != INVALID_HANDLE)
96 CloseHandle(g_PlayerTimers[client]);
97 g_PlayerTimers[client] = INVALID_HANDLE;
101 public Action:DM_OnClientDeath(client)
103 if (g_PlayerTimers[client] != INVALID_HANDLE)
105 CloseHandle(g_PlayerTimers[client]);
106 g_PlayerTimers[client] = INVALID_HANDLE;
109 return Plugin_Continue;
112 public Action:StopProtection(Handle:timer, any:client)
114 g_PlayerTimers[client] = INVALID_HANDLE;
116 SetEntData(client, g_HealthOffset, g_PlayerHealth[client]);
117 UTIL_Render(client, g_NormColor);
122 public DM_OnClientPostSpawned(client)
124 if (!GetConVarInt(g_ProtVar)
125 || !IsClientInGame(client)
126 || g_PlayerTimers[client] != INVALID_HANDLE)
131 g_PlayerTimers[client] = CreateTimer(GetConVarFloat(g_ProtTimeVar), StopProtection, client);
133 /* Start protection */
134 g_PlayerHealth[client] = GetEntData(client, g_HealthOffset);
135 SetEntData(client, g_HealthOffset, 1012); /* This overflows to show "500" */
137 new team = GetClientTeam(client);
138 if (team == CSSDM_TEAM_T)
140 UTIL_Render(client, g_TColor);
141 } else if (team == CSSDM_TEAM_CT) {
142 UTIL_Render(client, g_CTColor);
146 UTIL_Render(client, const color[4])
148 new mode = (color[3] == 255) ? K_RENDER_NORMAL : K_RENDER_TRANS_COLOR;
150 SetEntData(client, g_RenderModeOffset, mode, 1);
151 SetEntDataArray(client, g_RenderClrOffset, color, 4, 1);
152 ChangeEdictState(client);