Updated HL2DM gamedata.
3 * =============================================================================
4 * SourceMod Basic Info Triggers Plugin
5 * Implements basic information chat triggers like ff and timeleft.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
40 #define REQUIRE_PLUGIN
42 public Plugin:myinfo =
44 name = "Basic Info Triggers",
45 author = "AlliedModders LLC",
46 description = "Adds ff, timeleft, thetime, and others.",
47 version = SOURCEMOD_VERSION,
48 url = "http://www.sourcemod.net/"
51 new Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
52 new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
53 new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
55 new Handle:g_Timer_TimeShow = INVALID_HANDLE;
57 new Handle:g_Cvar_WinLimit = INVALID_HANDLE;
58 new Handle:g_Cvar_FragLimit = INVALID_HANDLE;
59 new Handle:g_Cvar_MaxRounds = INVALID_HANDLE;
61 #define TIMELEFT_ALL_ALWAYS 0 /* Print to all players */
62 #define TIMELEFT_ALL_MAYBE 1 /* Print to all players if sm_trigger_show allows */
63 #define TIMELEFT_ONE 2 /* Print to a single player */
69 public OnPluginStart()
71 LoadTranslations("common.phrases");
72 LoadTranslations("basetriggers.phrases");
74 g_Cvar_TriggerShow = CreateConVar("sm_trigger_show", "1", "Display triggers message to all players? (0 off, 1 on, def. 1)", 0, true, 0.0, true, 1.0);
75 g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
76 g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
78 AddCommandListener(Command_Say, "say");
79 AddCommandListener(Command_Say, "say2");
80 AddCommandListener(Command_Say, "say_team");
82 RegConsoleCmd("timeleft", Command_Timeleft);
83 RegConsoleCmd("nextmap", Command_Nextmap);
84 RegConsoleCmd("motd", Command_Motd);
86 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
88 decl String:folder[64];
89 GetGameFolderName(folder, sizeof(folder));
91 if (strcmp(folder, "insurgency") == 0)
93 HookEvent("game_newmap", Event_GameStart);
97 HookEvent("game_start", Event_GameStart);
100 if (strcmp(folder, "nucleardawn") == 0)
102 HookEvent("round_win", Event_RoundEnd);
106 HookEvent("round_end", Event_RoundEnd);
109 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
110 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
111 HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
113 g_Cvar_WinLimit = FindConVar("mp_winlimit");
114 g_Cvar_FragLimit = FindConVar("mp_fraglimit");
115 g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
117 mapchooser = LibraryExists("mapchooser");
125 /* Round count tracking */
126 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
128 /* Game got restarted - reset our round count tracking */
132 public Event_GameStart(Handle:event, const String:name[], bool:dontBroadcast)
134 /* Game got restarted - reset our round count tracking */
138 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
140 if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
145 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
146 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
151 public OnLibraryRemoved(const String:name[])
153 if (StrEqual(name, "mapchooser"))
159 public OnLibraryAdded(const String:name[])
161 if (StrEqual(name, "mapchooser"))
167 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
169 new Float:newval = StringToFloat(newValue);
173 if (g_Timer_TimeShow != INVALID_HANDLE)
175 KillTimer(g_Timer_TimeShow);
181 if (g_Timer_TimeShow != INVALID_HANDLE)
183 KillTimer(g_Timer_TimeShow);
184 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
187 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
190 public Action:Timer_DisplayTimeleft(Handle:timer)
192 ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS);
195 public Action:Command_Timeleft(client, args)
197 ShowTimeLeft(client, TIMELEFT_ONE);
199 return Plugin_Handled;
202 public Action:Command_Nextmap(client, args)
204 if (client && !IsClientInGame(client))
205 return Plugin_Handled;
209 GetNextMap(map, sizeof(map));
211 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
213 ReplyToCommand(client, "[SM] %t", "Pending Vote");
217 ReplyToCommand(client, "[SM] %t", "Next Map", map);
220 return Plugin_Handled;
223 public Action:Command_Motd(client, args)
227 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
228 return Plugin_Handled;
231 if (!IsClientInGame(client))
232 return Plugin_Handled;
234 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
236 return Plugin_Handled;
239 public Action:Command_Say(client, const String:command[], argc)
241 decl String:text[192];
243 if (GetCmdArgString(text, sizeof(text)) < 1)
245 return Plugin_Continue;
248 if (text[strlen(text)-1] == '"')
250 text[strlen(text)-1] = '\0';
254 if (strcmp(command, "say2", false) == 0)
257 if (strcmp(text[startidx], "timeleft", false) == 0)
259 ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
261 else if (strcmp(text[startidx], "thetime", false) == 0)
263 decl String:ctime[64];
264 FormatTime(ctime, 64, NULL_STRING);
266 if(GetConVarInt(g_Cvar_TriggerShow))
268 PrintToChatAll("[SM] %t", "Thetime", ctime);
272 PrintToChat(client,"[SM] %t", "Thetime", ctime);
275 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
277 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
279 decl String:phrase[24];
280 if (GetConVarBool(g_Cvar_FriendlyFire))
282 strcopy(phrase, sizeof(phrase), "Friendly Fire On");
286 strcopy(phrase, sizeof(phrase), "Friendly Fire Off");
289 if(GetConVarInt(g_Cvar_TriggerShow))
291 PrintToChatAll("[SM] %t", phrase);
295 PrintToChat(client,"[SM] %t", phrase);
299 else if (strcmp(text[startidx], "currentmap", false) == 0)
302 GetCurrentMap(map, sizeof(map));
304 if(GetConVarInt(g_Cvar_TriggerShow))
306 PrintToChatAll("[SM] %t", "Current Map", map);
310 PrintToChat(client,"[SM] %t", "Current Map", map);
313 else if (strcmp(text[startidx], "nextmap", false) == 0)
316 GetNextMap(map, sizeof(map));
318 if(GetConVarInt(g_Cvar_TriggerShow))
320 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
322 PrintToChatAll("[SM] %t", "Pending Vote");
326 PrintToChatAll("[SM] %t", "Next Map", map);
331 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
333 PrintToChat(client, "[SM] %t", "Pending Vote");
337 PrintToChat(client, "[SM] %t", "Next Map", map);
341 else if (strcmp(text[startidx], "motd", false) == 0)
343 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
346 return Plugin_Continue;
349 ShowTimeLeft(client, who)
351 new bool:lastround = false;
352 new bool:written = false;
353 new bool:notimelimit = false;
355 decl String:finalOutput[1024];
358 if (who == TIMELEFT_ALL_ALWAYS
359 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
365 if (GetMapTimeLeft(timeleft))
372 mins = timeleft / 60;
373 secs = timeleft % 60;
375 FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
377 else if (GetMapTimeLimit(timelimit) && timelimit == 0)
383 /* 0 timeleft so this must be the last round */
390 if (g_Cvar_WinLimit != INVALID_HANDLE)
392 new winlimit = GetConVarInt(g_Cvar_WinLimit);
398 new len = strlen(finalOutput);
399 if (len < sizeof(finalOutput))
403 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppendPlural" ,client, winlimit);
407 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client);
415 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimitPlural", client, winlimit);
419 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client);
427 if (g_Cvar_FragLimit != INVALID_HANDLE)
429 new fraglimit = GetConVarInt(g_Cvar_FragLimit);
435 new len = strlen(finalOutput);
436 if (len < sizeof(finalOutput))
440 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppendPlural", client, fraglimit);
444 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client);
452 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimitPlural", client, fraglimit);
456 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client);
464 if (g_Cvar_MaxRounds != INVALID_HANDLE)
466 new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
470 new remaining = maxrounds - g_TotalRounds;
474 new len = strlen(finalOutput);
475 if (len < sizeof(finalOutput))
479 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppendPlural", client, remaining);
483 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client);
491 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRoundsPlural", client, remaining);
495 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client);
506 FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
508 else if (notimelimit && !written)
510 FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
513 if (who == TIMELEFT_ALL_ALWAYS
514 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
516 PrintToChatAll("[SM] %s", finalOutput);
518 else if (client != 0 && IsClientInGame(client))
520 PrintToChat(client, "[SM] %s", finalOutput);
525 PrintToServer("[SM] %s", finalOutput);