Remove flag that appears to have broken linux build further.
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.
30 new Handle:cssdm_respawn_command;
31 new Handle:cssdm_force_mapchanges;
32 new Handle:cssdm_mapchange_file;
33 new Handle:cssdm_refill_ammo;
34 new Handle:mp_timelimit;
35 new Handle:g_ChangeMapTimer = INVALID_HANDLE;
36 new bool:g_AmmoHooks = false;
37 new g_ActiveWepOffs = -1;
40 new Float:g_DeathTimes[MAXPLAYERS+1];
41 new bool:g_bHasNoAmmoInClip1[MAXPLAYERS+1] = {false,...};
44 public Plugin:myinfo =
46 name = "CS:S DM Basics",
47 author = "AlliedModders LLC",
48 description = "Basic CS:S DM Commands/Features",
49 version = CSSDM_VERSION,
50 url = "http://www.bailopan.net/cssdm/"
53 public OnPluginStart()
55 LoadTranslations("cssdm.phrases");
57 RegConsoleCmd("say", Command_Say);
58 RegConsoleCmd("say_team", Command_Say);
60 cssdm_respawn_command = CreateConVar("cssdm_respawn_command", "1", "Sets whether clients can manually respawn");
61 cssdm_force_mapchanges = CreateConVar("cssdm_force_mapchanges", "0", "Sets whether CS:S DM should force mapchanges");
62 cssdm_mapchange_file = CreateConVar("cssdm_mapchange_file", "mapcycle.txt", "Sets the mapchange file for CS:S DM");
63 cssdm_refill_ammo = CreateConVar("cssdm_refill_ammo", "1", "Sets whether CS:S DM automatically refills ammo");
64 mp_timelimit = FindConVar("mp_timelimit");
66 HookConVarChange(cssdm_force_mapchanges, CvarChange_RestartMapTimer);
67 HookConVarChange(mp_timelimit, CvarChange_RestartMapTimer);
68 HookConVarChange(cssdm_refill_ammo, CvarChange_RefillAmmo);
70 g_ActiveWepOffs = FindSendPropOffs("CCSPlayer", "m_hActiveWeapon");
77 g_AmmoHooks = GetConVarInt(cssdm_refill_ammo) ? true : false;
78 if (g_AmmoHooks && g_ActiveWepOffs > 0)
80 HookEvent("weapon_reload", Event_CheckDepleted);
81 HookEvent("weapon_fire_on_empty", Event_CheckDepleted);
85 public DM_OnShutdown()
87 if (g_ChangeMapTimer != INVALID_HANDLE)
89 CloseHandle(g_ChangeMapTimer);
90 g_ChangeMapTimer = INVALID_HANDLE;
99 UnhookEvent("weapon_reload", Event_CheckDepleted);
100 UnhookEvent("weapon_fire_on_empty", Event_CheckDepleted);
105 public CvarChange_RefillAmmo(Handle:cvar, const String:oldvalue[], const String:newvalue[])
107 if (GetConVarInt(cvar) && !g_AmmoHooks && g_ActiveWepOffs > 0)
109 HookEvent("weapon_reload", Event_CheckDepleted);
110 HookEvent("weapon_fire_on_empty", Event_CheckDepleted);
111 } else if (!GetConVarInt(cvar) && g_AmmoHooks) {
112 UnhookEvent("weapon_reload", Event_CheckDepleted);
113 UnhookEvent("weapon_fire_on_empty", Event_CheckDepleted);
117 public Event_CheckDepleted(Handle:event, const String:name[], bool:dontBroadcast)
119 new client = GetClientOfUserId(GetEventInt(event, "userid"));
120 if (!client || !IsClientInGame(client))
125 new entity = GetEntDataEnt2(client, g_ActiveWepOffs);
131 new ammoType = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");
133 /* Give something reasonable -- the game will chop it off */
134 DM_GiveClientAmmo(client, ammoType, 200, false);
137 public CvarChange_RestartMapTimer(Handle:cvar, const String:oldvalue[], const String:newvalue[])
144 if (g_ChangeMapTimer != INVALID_HANDLE)
146 CloseHandle(g_ChangeMapTimer);
147 g_ChangeMapTimer = INVALID_HANDLE;
150 if (GetConVarInt(cssdm_force_mapchanges))
152 /* Find how much time is left in the map */
153 new Float:seconds = (GetConVarInt(mp_timelimit) * 60.0) - GetGameTime();
154 g_ChangeMapTimer = CreateTimer(seconds, Timer_ChangeMap);
158 public Action:Timer_ChangeMap(Handle:timer)
160 g_ChangeMapTimer = INVALID_HANDLE;
162 decl String:changefile[64];
163 GetConVarString(cssdm_mapchange_file, changefile, sizeof(changefile));
165 new Handle:file = OpenFile(changefile, "rt");
168 LogError("[CSSDM] Could not open mapchange file \"%s\"", changefile);
172 decl String:curmap[64];
173 GetCurrentMap(curmap, sizeof(curmap));
175 new String:firstmap[64];
176 new String:lastmap[64];
177 decl String:buffer[64];
178 new bool:matched = false;
179 while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
182 if (buffer[0] == '\0' || (!IsCharAlpha(buffer[0]) && !IsCharNumeric(buffer[0])))
186 if (!IsMapValid(buffer))
190 if (firstmap[0] == '\0')
192 strcopy(firstmap, sizeof(firstmap), buffer);
194 strcopy(lastmap, sizeof(lastmap), buffer);
195 if (strcmp(buffer, curmap) == 0)
198 } else if (matched) {
204 if (!matched || (strcmp(buffer, curmap) == 0))
206 strcopy(lastmap, sizeof(lastmap), firstmap);
209 if (lastmap[0] != '\0')
211 ServerCommand("changelevel %s", lastmap);
217 public Action:Timer_Welcome(Handle:timer, any:userid)
219 new client = GetClientOfUserId(userid);
221 if (!client || !IsClientInGame(client))
226 PrintToChat(client, "[CSSDM] Counter-Strike Source: Deathmatch (version %s)", CSSDM_VERSION);
227 PrintToChat(client, "[CSSDM] Visit http://www.bailopan.net/cssdm to download.");
232 public OnClientPutInServer(client)
234 g_DeathTimes[client] = 0.0;
235 CreateTimer(10.0, Timer_Welcome, GetClientUserId(client));
237 g_bHasNoAmmoInClip1[client] = false;
240 public Action:DM_OnClientDeath(client)
242 g_DeathTimes[client] = GetGameTime();
243 return Plugin_Continue;
246 public Action:Command_Say(client, args)
248 if (!DM_IsRunning() || !GetConVarInt(cssdm_respawn_command))
250 return Plugin_Continue;
253 decl String:command[32];
254 GetCmdArg(1, command, sizeof(command));
256 if (strcmp(command, "respawn") == 0)
258 if (!IsClientInGame(client))
260 PrintToChat(client, "[CSSDM] %t", "NoRespawn NotInGame");
261 return Plugin_Handled;
264 if (DM_IsClientAlive(client))
266 PrintToChat(client, "[CSSDM] %t", "NoRespawn Alive");
267 return Plugin_Handled;
270 new team = GetClientTeam(client);
271 if (team != CSSDM_TEAM_T && team != CSSDM_TEAM_CT)
273 PrintToChat(client, "[CSSDM] %t", "NoRespawn Team");
274 return Plugin_Handled;
277 new Float:elapsed = GetGameTime() - g_DeathTimes[client];
278 new Float:wait_time = DM_GetSpawnWaitTime();
279 if (elapsed < wait_time)
281 PrintToChat(client, "[CSSDM] %t", "NoRespawn Wait", wait_time - elapsed);
282 return Plugin_Handled;
285 /* We passed the tests... respawn! */
286 DM_RespawnClient(client);
288 return Plugin_Handled;
291 return Plugin_Continue;
294 public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
297 return Plugin_Continue;
299 new entity = GetEntDataEnt2(client, g_ActiveWepOffs);
302 g_bHasNoAmmoInClip1[client] = false;
303 return Plugin_Continue;
306 // He's out of ammo -> reloading
307 new iClip1 = GetEntProp(entity, Prop_Send, "m_iClip1");
310 g_bHasNoAmmoInClip1[client] = true;
312 // He got ammo in clip1 again but hadn't before -> reloaded.
313 else if(g_bHasNoAmmoInClip1[client])
315 g_bHasNoAmmoInClip1[client] = false;
317 new ammoType = GetEntProp(entity, Prop_Send, "m_iPrimaryAmmoType");
321 return Plugin_Continue;
325 DM_GiveClientAmmo(client, ammoType, 200, false);
328 return Plugin_Continue;