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 RegConsoleCmd("say", Command_Say);
79 RegConsoleCmd("say_team", Command_Say);
81 RegConsoleCmd("timeleft", Command_Timeleft);
82 RegConsoleCmd("nextmap", Command_Nextmap);
83 RegConsoleCmd("motd", Command_Motd);
85 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
87 decl String:folder[64];
88 GetGameFolderName(folder, sizeof(folder));
90 if (strcmp(folder, "insurgency") == 0)
92 HookEvent("game_newmap", Event_GameStart);
96 HookEvent("game_start", Event_GameStart);
99 HookEvent("round_end", Event_RoundEnd);
100 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
101 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
102 HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
104 g_Cvar_WinLimit = FindConVar("mp_winlimit");
105 g_Cvar_FragLimit = FindConVar("mp_fraglimit");
106 g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
108 mapchooser = LibraryExists("mapchooser");
116 /* Round count tracking */
117 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
119 /* Game got restarted - reset our round count tracking */
123 public Event_GameStart(Handle:event, const String:name[], bool:dontBroadcast)
125 /* Game got restarted - reset our round count tracking */
129 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
131 if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
136 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
137 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
142 public OnLibraryRemoved(const String:name[])
144 if (StrEqual(name, "mapchooser"))
150 public OnLibraryAdded(const String:name[])
152 if (StrEqual(name, "mapchooser"))
158 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
160 new Float:newval = StringToFloat(newValue);
164 if (g_Timer_TimeShow != INVALID_HANDLE)
166 KillTimer(g_Timer_TimeShow);
172 if (g_Timer_TimeShow != INVALID_HANDLE)
174 KillTimer(g_Timer_TimeShow);
175 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
178 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
181 public Action:Timer_DisplayTimeleft(Handle:timer)
183 ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS);
186 public Action:Command_Timeleft(client, args)
188 ShowTimeLeft(client, TIMELEFT_ONE);
190 return Plugin_Handled;
193 public Action:Command_Nextmap(client, args)
197 GetNextMap(map, sizeof(map));
199 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
201 ReplyToCommand(client, "[SM] %t", "Pending Vote");
205 ReplyToCommand(client, "[SM] %t", "Next Map", map);
208 return Plugin_Handled;
211 public Action:Command_Motd(client, args)
215 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
216 return Plugin_Handled;
219 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
221 return Plugin_Handled;
224 public Action:Command_Say(client, args)
226 decl String:text[192], String:command[64];
228 if (GetCmdArgString(text, sizeof(text)) < 1)
230 return Plugin_Continue;
233 if (text[strlen(text)-1] == '"')
235 text[strlen(text)-1] = '\0';
239 if (strcmp(command, "say2", false) == 0)
242 if (strcmp(text[startidx], "timeleft", false) == 0)
244 ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
246 else if (strcmp(text[startidx], "thetime", false) == 0)
248 decl String:ctime[64];
249 FormatTime(ctime, 64, NULL_STRING);
251 if(GetConVarInt(g_Cvar_TriggerShow))
253 PrintToChatAll("[SM] %t", "Thetime", ctime);
257 PrintToChat(client,"[SM] %t", "Thetime", ctime);
260 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
262 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
264 decl String:message[64];
265 if (GetConVarBool(g_Cvar_FriendlyFire))
267 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
271 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
274 if(GetConVarInt(g_Cvar_TriggerShow))
276 PrintToChatAll("[SM] %s", message);
280 PrintToChat(client,"[SM] %s", message);
284 else if (strcmp(text[startidx], "currentmap", false) == 0)
287 GetCurrentMap(map, sizeof(map));
289 if(GetConVarInt(g_Cvar_TriggerShow))
291 PrintToChatAll("[SM] %t", "Current Map", map);
295 PrintToChat(client,"[SM] %t", "Current Map", map);
298 else if (strcmp(text[startidx], "nextmap", false) == 0)
301 GetNextMap(map, sizeof(map));
303 if(GetConVarInt(g_Cvar_TriggerShow))
305 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
307 PrintToChatAll("[SM] %t", "Pending Vote");
311 PrintToChatAll("[SM] %t", "Next Map", map);
316 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
318 PrintToChat(client, "[SM] %t", "Pending Vote");
322 PrintToChat(client, "[SM] %t", "Next Map", map);
326 else if (strcmp(text[startidx], "motd", false) == 0)
328 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
331 return Plugin_Continue;
334 ShowTimeLeft(client, who)
336 new bool:lastround = false;
337 new bool:written = false;
338 new bool:notimelimit = false;
340 decl String:finalOutput[1024];
343 if (who == TIMELEFT_ALL_ALWAYS
344 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
350 if (GetMapTimeLeft(timeleft))
357 mins = timeleft / 60;
358 secs = timeleft % 60;
360 FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
362 else if (GetMapTimeLimit(timelimit) && timelimit == 0)
368 /* 0 timeleft so this must be the last round */
375 if (g_Cvar_WinLimit != INVALID_HANDLE)
377 new winlimit = GetConVarInt(g_Cvar_WinLimit);
383 new len = strlen(finalOutput);
384 if (len < sizeof(finalOutput))
388 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppendPlural" ,client, winlimit);
392 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client);
400 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimitPlural", client, winlimit);
404 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client);
412 if (g_Cvar_FragLimit != INVALID_HANDLE)
414 new fraglimit = GetConVarInt(g_Cvar_FragLimit);
420 new len = strlen(finalOutput);
421 if (len < sizeof(finalOutput))
425 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppendPlural", client, fraglimit);
429 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client);
437 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimitPlural", client, fraglimit);
441 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client);
449 if (g_Cvar_MaxRounds != INVALID_HANDLE)
451 new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
455 new remaining = maxrounds - g_TotalRounds;
459 new len = strlen(finalOutput);
460 if (len < sizeof(finalOutput))
464 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppendPlural", client, remaining);
468 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client);
476 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRoundsPlural", client, remaining);
480 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client);
491 FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
493 else if (notimelimit && !written)
495 FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
498 if (who == TIMELEFT_ALL_ALWAYS
499 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
501 PrintToChatAll("[SM] %s", finalOutput);
503 else if (client != 0)
505 PrintToChat(client, "[SM] %s", finalOutput);
510 PrintToServer("[SM] %s", finalOutput);