3 * Base CS:S DM admin/control functions.
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 new Handle:cssdm_respawn_command;
30 new Handle:cssdm_force_mapchanges;
31 new Handle:cssdm_mapchange_file;
32 new Handle:cssdm_refill_ammo;
33 new Handle:mp_timelimit;
34 new Handle:g_ChangeMapTimer = INVALID_HANDLE;
35 new bool:g_AmmoHooks = false;
36 new g_ActiveWepOffs = -1;
39 new Float:g_DeathTimes[MAXPLAYERS+1];
42 public Plugin:myinfo =
44 name = "CS:S DM Basics",
45 author = "AlliedModders LLC",
46 description = "Basic CS:S DM Commands/Features",
47 version = CSSDM_VERSION,
48 url = "http://www.bailopan.net/cssdm/"
51 public OnPluginStart()
53 LoadTranslations("cssdm.phrases");
55 RegConsoleCmd("say", Command_Say);
56 RegConsoleCmd("say_team", Command_Say);
58 cssdm_respawn_command = CreateConVar("cssdm_respawn_command", "1", "Sets whether clients can manually respawn");
59 cssdm_force_mapchanges = CreateConVar("cssdm_force_mapchanges", "0", "Sets whether CS:S DM should force mapchanges");
60 cssdm_mapchange_file = CreateConVar("cssdm_mapchange_file", "mapcycle.txt", "Sets the mapchange file for CS:S DM");
61 cssdm_refill_ammo = CreateConVar("cssdm_refill_ammo", "1", "Sets whether CS:S DM automatically refills ammo");
62 mp_timelimit = FindConVar("mp_timelimit");
64 HookConVarChange(cssdm_force_mapchanges, CvarChange_RestartMapTimer);
65 HookConVarChange(mp_timelimit, CvarChange_RestartMapTimer);
66 HookConVarChange(cssdm_refill_ammo, CvarChange_RefillAmmo);
68 g_ActiveWepOffs = FindSendPropOffs("CCSPlayer", "m_hActiveWeapon");
71 public OnConfigsExecuted()
75 g_AmmoHooks = GetConVarInt(cssdm_refill_ammo) ? true : false;
76 if (g_AmmoHooks && g_ActiveWepOffs > 0)
78 HookEvent("weapon_reload", Event_CheckDepleted);
79 HookEvent("weapon_fire_on_empty", Event_CheckDepleted);
85 if (g_ChangeMapTimer != INVALID_HANDLE)
87 CloseHandle(g_ChangeMapTimer);
88 g_ChangeMapTimer = INVALID_HANDLE;
92 UnhookEvent("weapon_reload", Event_CheckDepleted);
93 UnhookEvent("weapon_fire_on_reload", Event_CheckDepleted);
97 public CvarChange_RefillAmmo(Handle:cvar, const String:oldvalue[], const String:newvalue[])
99 if (GetConVarInt(cvar) && !g_AmmoHooks && g_ActiveWepOffs > 0)
101 HookEvent("weapon_reload", Event_CheckDepleted);
102 HookEvent("weapon_fire_on_reload", Event_CheckDepleted);
103 } else if (!GetConVarInt(cvar) && g_AmmoHooks) {
104 UnhookEvent("weapon_reload", Event_CheckDepleted);
105 UnhookEvent("weapon_fire_on_reload", Event_CheckDepleted);
109 public Event_CheckDepleted(Handle:event, const String:name[], bool:dontBroadcast)
111 new client = GetClientOfUserId(GetEventInt(event, "userid"));
112 if (!client || !IsClientInGame(client))
117 new entity = GetEntDataEnt(client, g_ActiveWepOffs);
123 new ammoType = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");
125 /* Give something reasonable -- the game will chop it off */
126 DM_GiveClientAmmo(client, ammoType, 30, false);
129 public CvarChange_RestartMapTimer(Handle:cvar, const String:oldvalue[], const String:newvalue[])
136 if (g_ChangeMapTimer != INVALID_HANDLE)
138 CloseHandle(g_ChangeMapTimer);
139 g_ChangeMapTimer = INVALID_HANDLE;
142 if (GetConVarInt(cssdm_force_mapchanges))
144 /* Find how much time is left in the map */
145 new Float:seconds = (GetConVarInt(mp_timelimit) * 60.0) - GetGameTime();
146 g_ChangeMapTimer = CreateTimer(seconds, Timer_ChangeMap);
150 public Action:Timer_ChangeMap(Handle:timer)
152 g_ChangeMapTimer = INVALID_HANDLE;
154 decl String:changefile[64];
155 GetConVarString(cssdm_mapchange_file, changefile, sizeof(changefile));
157 new Handle:file = OpenFile(changefile, "rt");
160 LogError("[CSSDM] Could not open mapchange file \"%s\"", changefile);
164 decl String:curmap[64];
165 GetCurrentMap(curmap, sizeof(curmap));
167 new String:firstmap[64];
168 new String:lastmap[64];
169 decl String:buffer[64];
170 new bool:matched = false;
171 while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
174 if (buffer[0] == '\0' || (!IsCharAlpha(buffer[0]) && !IsCharNumeric(buffer[0])))
178 if (!IsMapValid(buffer))
182 if (firstmap[0] == '\0')
184 strcopy(firstmap, sizeof(firstmap), buffer);
186 strcopy(lastmap, sizeof(lastmap), buffer);
187 if (strcmp(buffer, curmap) == 0)
190 } else if (matched) {
196 if (!matched || (strcmp(buffer, curmap) == 0))
198 strcopy(lastmap, sizeof(lastmap), firstmap);
201 if (lastmap[0] != '\0')
203 ServerCommand("changelevel %s", lastmap);
209 public Action:Timer_Welcome(Handle:timer, any:userid)
211 new client = GetClientOfUserId(userid);
213 if (!client || !IsClientInGame(client))
218 PrintToChat(client, "[CSSDM] Counter-Strike Source: Deathmatch (version %s)", CSSDM_VERSION);
219 PrintToChat(client, "[CSSDM] Visit http://www.bailopan.net/cssdm/ to download.");
224 public OnClientPutInServer(client)
226 g_DeathTimes[client] = 0.0;
227 CreateTimer(10.0, Timer_Welcome, GetClientUserId(client));
230 public Action:DM_OnClientDeath(client)
232 g_DeathTimes[client] = GetGameTime();
233 return Plugin_Continue;
236 public Action:Command_Say(client, args)
238 if (!DM_IsRunning() || !GetConVarInt(cssdm_respawn_command))
240 return Plugin_Continue;
243 decl String:command[32];
244 GetCmdArg(1, command, sizeof(command));
246 if (strcmp(command, "respawn") == 0)
248 if (!IsClientInGame(client))
250 PrintToChat(client, "[CSSDM] %t", "NoRespawn NotInGame");
251 return Plugin_Handled;
254 if (DM_IsClientAlive(client))
256 PrintToChat(client, "[CSSDM] %t", "NoRespawn Alive");
257 return Plugin_Handled;
260 new team = GetClientTeam(client);
261 if (team != CSSDM_TEAM_T && team != CSSDM_TEAM_CT)
263 PrintToChat(client, "[CSSDM] %t", "NoRespawn Team");
264 return Plugin_Handled;
267 new Float:elapsed = GetGameTime() - g_DeathTimes[client];
268 new Float:wait_time = DM_GetSpawnWaitTime();
269 if (elapsed < wait_time)
271 PrintToChat(client, "[CSSDM] %t", "NoRespawn Wait", wait_time - elapsed);
272 return Plugin_Handled;
275 /* We passed the tests... respawn! */
276 DM_RespawnClient(client);
278 return Plugin_Handled;
281 return Plugin_Continue;