Fixed build.
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 HookEvent("round_end", Event_RoundEnd);
101 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
102 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
103 HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
105 g_Cvar_WinLimit = FindConVar("mp_winlimit");
106 g_Cvar_FragLimit = FindConVar("mp_fraglimit");
107 g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
109 mapchooser = LibraryExists("mapchooser");
117 /* Round count tracking */
118 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
120 /* Game got restarted - reset our round count tracking */
124 public Event_GameStart(Handle:event, const String:name[], bool:dontBroadcast)
126 /* Game got restarted - reset our round count tracking */
130 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
132 if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
137 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
138 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
143 public OnLibraryRemoved(const String:name[])
145 if (StrEqual(name, "mapchooser"))
151 public OnLibraryAdded(const String:name[])
153 if (StrEqual(name, "mapchooser"))
159 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
161 new Float:newval = StringToFloat(newValue);
165 if (g_Timer_TimeShow != INVALID_HANDLE)
167 KillTimer(g_Timer_TimeShow);
173 if (g_Timer_TimeShow != INVALID_HANDLE)
175 KillTimer(g_Timer_TimeShow);
176 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
179 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
182 public Action:Timer_DisplayTimeleft(Handle:timer)
184 ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS);
187 public Action:Command_Timeleft(client, args)
189 ShowTimeLeft(client, TIMELEFT_ONE);
191 return Plugin_Handled;
194 public Action:Command_Nextmap(client, args)
198 GetNextMap(map, sizeof(map));
200 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
202 ReplyToCommand(client, "[SM] %t", "Pending Vote");
206 ReplyToCommand(client, "[SM] %t", "Next Map", map);
209 return Plugin_Handled;
212 public Action:Command_Motd(client, args)
216 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
217 return Plugin_Handled;
220 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
222 return Plugin_Handled;
225 public Action:Command_Say(client, const String:command[], argc)
227 decl String:text[192];
229 if (GetCmdArgString(text, sizeof(text)) < 1)
231 return Plugin_Continue;
234 if (text[strlen(text)-1] == '"')
236 text[strlen(text)-1] = '\0';
240 if (strcmp(command, "say2", false) == 0)
243 if (strcmp(text[startidx], "timeleft", false) == 0)
245 ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
247 else if (strcmp(text[startidx], "thetime", false) == 0)
249 decl String:ctime[64];
250 FormatTime(ctime, 64, NULL_STRING);
252 if(GetConVarInt(g_Cvar_TriggerShow))
254 PrintToChatAll("[SM] %t", "Thetime", ctime);
258 PrintToChat(client,"[SM] %t", "Thetime", ctime);
261 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
263 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
265 decl String:message[64];
266 if (GetConVarBool(g_Cvar_FriendlyFire))
268 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
272 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
275 if(GetConVarInt(g_Cvar_TriggerShow))
277 PrintToChatAll("[SM] %s", message);
281 PrintToChat(client,"[SM] %s", message);
285 else if (strcmp(text[startidx], "currentmap", false) == 0)
288 GetCurrentMap(map, sizeof(map));
290 if(GetConVarInt(g_Cvar_TriggerShow))
292 PrintToChatAll("[SM] %t", "Current Map", map);
296 PrintToChat(client,"[SM] %t", "Current Map", map);
299 else if (strcmp(text[startidx], "nextmap", false) == 0)
302 GetNextMap(map, sizeof(map));
304 if(GetConVarInt(g_Cvar_TriggerShow))
306 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
308 PrintToChatAll("[SM] %t", "Pending Vote");
312 PrintToChatAll("[SM] %t", "Next Map", map);
317 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
319 PrintToChat(client, "[SM] %t", "Pending Vote");
323 PrintToChat(client, "[SM] %t", "Next Map", map);
327 else if (strcmp(text[startidx], "motd", false) == 0)
329 ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
332 return Plugin_Continue;
335 ShowTimeLeft(client, who)
337 new bool:lastround = false;
338 new bool:written = false;
339 new bool:notimelimit = false;
341 decl String:finalOutput[1024];
344 if (who == TIMELEFT_ALL_ALWAYS
345 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
351 if (GetMapTimeLeft(timeleft))
358 mins = timeleft / 60;
359 secs = timeleft % 60;
361 FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
363 else if (GetMapTimeLimit(timelimit) && timelimit == 0)
369 /* 0 timeleft so this must be the last round */
376 if (g_Cvar_WinLimit != INVALID_HANDLE)
378 new winlimit = GetConVarInt(g_Cvar_WinLimit);
384 new len = strlen(finalOutput);
385 if (len < sizeof(finalOutput))
389 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppendPlural" ,client, winlimit);
393 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client);
401 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimitPlural", client, winlimit);
405 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client);
413 if (g_Cvar_FragLimit != INVALID_HANDLE)
415 new fraglimit = GetConVarInt(g_Cvar_FragLimit);
421 new len = strlen(finalOutput);
422 if (len < sizeof(finalOutput))
426 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppendPlural", client, fraglimit);
430 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client);
438 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimitPlural", client, fraglimit);
442 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client);
450 if (g_Cvar_MaxRounds != INVALID_HANDLE)
452 new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
456 new remaining = maxrounds - g_TotalRounds;
460 new len = strlen(finalOutput);
461 if (len < sizeof(finalOutput))
465 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppendPlural", client, remaining);
469 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client);
477 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRoundsPlural", client, remaining);
481 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client);
492 FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
494 else if (notimelimit && !written)
496 FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
499 if (who == TIMELEFT_ALL_ALWAYS
500 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
502 PrintToChatAll("[SM] %s", finalOutput);
504 else if (client != 0)
506 PrintToChat(client, "[SM] %s", finalOutput);
511 PrintToServer("[SM] %s", finalOutput);