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("timeleft", Command_Timeleft);
79 RegConsoleCmd("nextmap", Command_Nextmap);
80 RegConsoleCmd("motd", Command_Motd);
81 RegConsoleCmd("ff", Command_FriendlyFire);
83 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
85 decl String:folder[64];
86 GetGameFolderName(folder, sizeof(folder));
88 if (strcmp(folder, "insurgency") == 0)
90 HookEvent("game_newmap", Event_GameStart);
94 HookEvent("game_start", Event_GameStart);
97 if (strcmp(folder, "nucleardawn") == 0)
99 HookEvent("round_win", Event_RoundEnd);
103 HookEvent("round_end", Event_RoundEnd);
106 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
107 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
108 HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
110 g_Cvar_WinLimit = FindConVar("mp_winlimit");
111 g_Cvar_FragLimit = FindConVar("mp_fraglimit");
112 g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
114 mapchooser = LibraryExists("mapchooser");
122 /* Round count tracking */
123 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
125 /* Game got restarted - reset our round count tracking */
129 public Event_GameStart(Handle:event, const String:name[], bool:dontBroadcast)
131 /* Game got restarted - reset our round count tracking */
135 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
137 if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
142 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
143 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
148 public OnLibraryRemoved(const String:name[])
150 if (StrEqual(name, "mapchooser"))
156 public OnLibraryAdded(const String:name[])
158 if (StrEqual(name, "mapchooser"))
164 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
166 new Float:newval = StringToFloat(newValue);
170 if (g_Timer_TimeShow != INVALID_HANDLE)
172 KillTimer(g_Timer_TimeShow);
178 if (g_Timer_TimeShow != INVALID_HANDLE)
180 KillTimer(g_Timer_TimeShow);
181 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
184 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
187 public Action:Timer_DisplayTimeleft(Handle:timer)
189 ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS);
192 public Action:Command_Timeleft(client, args)
194 ShowTimeLeft(client, TIMELEFT_ONE);
196 return Plugin_Handled;
199 public Action:Command_Nextmap(client, args)
201 if (client && !IsClientInGame(client))
202 return Plugin_Handled;
206 GetNextMap(map, sizeof(map));
208 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
210 ReplyToCommand(client, "[SM] %t", "Pending Vote");
214 ReplyToCommand(client, "[SM] %t", "Next Map", map);
217 return Plugin_Handled;
220 public Action:Command_Motd(client, args)
224 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
225 return Plugin_Handled;
228 if (!IsClientInGame(client))
229 return Plugin_Handled;
231 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
233 return Plugin_Handled;
236 public Action:Command_FriendlyFire(client, args)
240 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
241 return Plugin_Handled;
244 if (!IsClientInGame(client))
245 return Plugin_Handled;
247 ShowFriendlyFire(client);
249 return Plugin_Handled;
252 public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[])
254 if (strcmp(sArgs, "timeleft", false) == 0)
256 ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
258 else if (strcmp(sArgs, "thetime", false) == 0)
260 decl String:ctime[64];
261 FormatTime(ctime, 64, NULL_STRING);
263 if(GetConVarInt(g_Cvar_TriggerShow))
265 PrintToChatAll("[SM] %t", "Thetime", ctime);
269 PrintToChat(client,"[SM] %t", "Thetime", ctime);
272 else if (strcmp(sArgs, "ff", false) == 0)
274 ShowFriendlyFire(client);
276 else if (strcmp(sArgs, "currentmap", false) == 0)
279 GetCurrentMap(map, sizeof(map));
281 if(GetConVarInt(g_Cvar_TriggerShow))
283 PrintToChatAll("[SM] %t", "Current Map", map);
287 PrintToChat(client,"[SM] %t", "Current Map", map);
290 else if (strcmp(sArgs, "nextmap", false) == 0)
293 GetNextMap(map, sizeof(map));
295 if(GetConVarInt(g_Cvar_TriggerShow))
297 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
299 PrintToChatAll("[SM] %t", "Pending Vote");
303 PrintToChatAll("[SM] %t", "Next Map", map);
308 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
310 PrintToChat(client, "[SM] %t", "Pending Vote");
314 PrintToChat(client, "[SM] %t", "Next Map", map);
318 else if (strcmp(sArgs, "motd", false) == 0)
320 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
324 ShowTimeLeft(client, who)
326 new bool:lastround = false;
327 new bool:written = false;
328 new bool:notimelimit = false;
330 decl String:finalOutput[1024];
333 if (who == TIMELEFT_ALL_ALWAYS
334 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
340 if (GetMapTimeLeft(timeleft))
347 mins = timeleft / 60;
348 secs = timeleft % 60;
350 FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
352 else if (GetMapTimeLimit(timelimit) && timelimit == 0)
358 /* 0 timeleft so this must be the last round */
365 if (g_Cvar_WinLimit != INVALID_HANDLE)
367 new winlimit = GetConVarInt(g_Cvar_WinLimit);
373 new len = strlen(finalOutput);
374 if (len < sizeof(finalOutput))
378 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppendPlural" ,client, winlimit);
382 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client);
390 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimitPlural", client, winlimit);
394 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client);
402 if (g_Cvar_FragLimit != INVALID_HANDLE)
404 new fraglimit = GetConVarInt(g_Cvar_FragLimit);
410 new len = strlen(finalOutput);
411 if (len < sizeof(finalOutput))
415 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppendPlural", client, fraglimit);
419 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client);
427 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimitPlural", client, fraglimit);
431 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client);
439 if (g_Cvar_MaxRounds != INVALID_HANDLE)
441 new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
445 new remaining = maxrounds - g_TotalRounds;
449 new len = strlen(finalOutput);
450 if (len < sizeof(finalOutput))
454 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppendPlural", client, remaining);
458 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client);
466 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRoundsPlural", client, remaining);
470 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client);
481 FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
483 else if (notimelimit && !written)
485 FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
488 if (who == TIMELEFT_ALL_ALWAYS
489 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
491 PrintToChatAll("[SM] %s", finalOutput);
493 else if (client != 0 && IsClientInGame(client))
495 PrintToChat(client, "[SM] %s", finalOutput);
500 PrintToServer("[SM] %s", finalOutput);
504 ShowFriendlyFire(client)
506 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
508 decl String:phrase[24];
509 if (GetConVarBool(g_Cvar_FriendlyFire))
511 strcopy(phrase, sizeof(phrase), "Friendly Fire On");
515 strcopy(phrase, sizeof(phrase), "Friendly Fire Off");
518 if(GetConVarInt(g_Cvar_TriggerShow))
520 PrintToChatAll("[SM] %t", phrase);
524 PrintToChat(client,"[SM] %t", phrase);