1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripting/spawnprotection.sp Sun Jun 24 21:58:09 2007 +0000
1.3 @@ -0,0 +1,150 @@
1.4 +/**
1.5 + * spawnprotection.sp
1.6 + * Adds spawn protection to CS:S DM.
1.7 + * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License
1.11 + * as published by the Free Software Foundation; either version 2
1.12 + * of the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.22 + *
1.23 + * Version: $Id$
1.24 + */
1.25 +
1.26 +#pragma semicolon 1
1.27 +#include <sourcemod>
1.28 +#include <sdktools>
1.29 +#include <cssdm>
1.30 +
1.31 +#define K_RENDER_NORMAL 0
1.32 +#define K_RENDER_TRANS_COLOR 1
1.33 +
1.34 +/* Plugin stuff */
1.35 +new Handle:g_ProtVar;
1.36 +new Handle:g_TColorVar;
1.37 +new Handle:g_CTColorVar;
1.38 +new Handle:g_ProtTimeVar;
1.39 +new g_NormColor[4] = {255, 255, 255, 255};
1.40 +new g_TColor[4] = {255, 0, 0, 128};
1.41 +new g_CTColor[4] = {0, 0, 255, 128};
1.42 +new g_HealthOffset;
1.43 +new g_RenderModeOffset;
1.44 +new g_RenderClrOffset;
1.45 +
1.46 +/* Player stuff */
1.47 +new Handle:g_PlayerTimers[MAXPLAYERS+1];
1.48 +new g_PlayerHealth[MAXPLAYERS+1];
1.49 +
1.50 +/** PUBLIC INFO */
1.51 +public Plugin:myinfo =
1.52 +{
1.53 + name = "CS:S DM Spawn Protection",
1.54 + author = "AlliedModders LLC",
1.55 + description = "Spawn protection for CS:S DM",
1.56 + version = CSSDM_VERSION,
1.57 + url = "http://www.bailopan.net/cssdm/"
1.58 +};
1.59 +
1.60 +public OnPluginStart()
1.61 +{
1.62 + g_ProtVar = CreateConVar("cssdm_spawn_protection", "1", "Sets whether spawn protection is enabled");
1.63 + g_CTColorVar = CreateConVar("cssdm_prot_ctcolor", "0 0 255 128", "Sets the spawn color of CTs");
1.64 + g_TColorVar = CreateConVar("cssdm_prot_tcolor", "255 0 0 128", "Sets the spawn color of Ts");
1.65 + g_ProtTimeVar = CreateConVar("cssdm_prot_time", "2", "Sets time in seconds players are protected for");
1.66 +
1.67 + HookConVarChange(g_CTColorVar, OnColorChange);
1.68 + HookConVarChange(g_TColorVar, OnColorChange);
1.69 +
1.70 + g_HealthOffset = FindSendPropOffs("CCSPlayer", "m_iHealth");
1.71 + g_RenderModeOffset = FindSendPropOffs("CCSPlayer", "m_nRenderMode");
1.72 + g_RenderClrOffset = FindSendPropOffs("CCSPlayer", "m_clrRender");
1.73 +}
1.74 +
1.75 +public OnColorChange(Handle:convar, const String:oldValue[], const String:newValue[])
1.76 +{
1.77 + decl String:colors[4][12];
1.78 + decl clr[4];
1.79 + new num_strings = ExplodeString(newValue, " ", colors, 4, 12);
1.80 +
1.81 + for (new i=0; i<num_strings; i++)
1.82 + {
1.83 + clr[i] = StringToInt(colors[i]);
1.84 + }
1.85 +
1.86 + if (convar == g_CTColorVar)
1.87 + {
1.88 + g_CTColor = clr;
1.89 + } else if (convar == g_TColorVar) {
1.90 + g_TColor = clr;
1.91 + }
1.92 +}
1.93 +
1.94 +public OnClientDisconnect(client)
1.95 +{
1.96 + if (g_PlayerTimers[client] != INVALID_HANDLE)
1.97 + {
1.98 + CloseHandle(g_PlayerTimers[client]);
1.99 + g_PlayerTimers[client] = INVALID_HANDLE;
1.100 + }
1.101 +}
1.102 +
1.103 +public Action:DM_OnClientDeath(client)
1.104 +{
1.105 + if (g_PlayerTimers[client] != INVALID_HANDLE)
1.106 + {
1.107 + CloseHandle(g_PlayerTimers[client]);
1.108 + g_PlayerTimers[client] = INVALID_HANDLE;
1.109 + }
1.110 +
1.111 + return Plugin_Continue;
1.112 +}
1.113 +
1.114 +public Action:StopProtection(Handle:timer, any:client)
1.115 +{
1.116 + g_PlayerTimers[client] = INVALID_HANDLE;
1.117 +
1.118 + SetEntData(client, g_HealthOffset, g_PlayerHealth[client]);
1.119 + UTIL_Render(client, g_NormColor);
1.120 +
1.121 + return Plugin_Stop;
1.122 +}
1.123 +
1.124 +public DM_OnClientPostSpawned(client)
1.125 +{
1.126 + if (!GetConVarInt(g_ProtVar) || !IsClientInGame(client))
1.127 + {
1.128 + return;
1.129 + }
1.130 +
1.131 + g_PlayerTimers[client] = CreateTimer(GetConVarFloat(g_ProtTimeVar), StopProtection, client);
1.132 +
1.133 + /* Start protection */
1.134 + g_PlayerHealth[client] = GetEntData(client, g_HealthOffset);
1.135 + SetEntData(client, g_HealthOffset, 1012); /* This overflows to show "500" */
1.136 +
1.137 + new team = GetClientTeam(client);
1.138 + if (team == CSSDM_TEAM_T)
1.139 + {
1.140 + UTIL_Render(client, g_TColor);
1.141 + } else if (team == CSSDM_TEAM_CT) {
1.142 + UTIL_Render(client, g_CTColor);
1.143 + }
1.144 +}
1.145 +
1.146 +UTIL_Render(client, const color[4])
1.147 +{
1.148 + new mode = (color[3] == 255) ? K_RENDER_NORMAL : K_RENDER_TRANS_COLOR;
1.149 +
1.150 + SetEntData(client, g_RenderModeOffset, mode, 1);
1.151 + SetEntDataArray(client, g_RenderClrOffset, color, 4, 1);
1.152 + ChangeEdictState(client);
1.153 +}