Corrected case in a nominations phrase.
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 */
67 public OnPluginStart()
69 LoadTranslations("common.phrases");
70 LoadTranslations("basetriggers.phrases");
72 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);
73 g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
74 g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
76 RegConsoleCmd("say", Command_Say);
77 RegConsoleCmd("say_team", Command_Say);
79 RegConsoleCmd("timeleft", Command_Timeleft);
80 RegConsoleCmd("nextmap", Command_Nextmap);
82 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
85 g_Cvar_WinLimit = FindConVar("mp_winlimit");
86 g_Cvar_FragLimit = FindConVar("mp_fraglimit");
87 g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
89 mapchooser = LibraryExists("mapchooser");
92 public OnLibraryRemoved(const String:name[])
94 if (StrEqual(name, "mapchooser"))
100 public OnLibraryAdded(const String:name[])
102 if (StrEqual(name, "mapchooser"))
108 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
110 new Float:newval = StringToFloat(newValue);
114 if (g_Timer_TimeShow != INVALID_HANDLE)
116 KillTimer(g_Timer_TimeShow);
122 if (g_Timer_TimeShow != INVALID_HANDLE)
124 KillTimer(g_Timer_TimeShow);
125 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
128 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
131 public Action:Timer_DisplayTimeleft(Handle:timer)
133 ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS);
136 public Action:Command_Timeleft(client, args)
138 ShowTimeLeft(client, TIMELEFT_ONE);
140 return Plugin_Handled;
143 public Action:Command_Nextmap(client, args)
147 GetNextMap(map, sizeof(map));
149 if(GetConVarInt(g_Cvar_TriggerShow))
151 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
153 PrintToChatAll("[SM] %t", "Pending Vote");
157 PrintToChatAll("[SM] %t", "Next Map", map);
162 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
164 ReplyToCommand(client, "[SM] %t", "Pending Vote");
168 ReplyToCommand(client, "[SM] %t", "Next Map", map);
172 return Plugin_Handled;
175 public Action:Command_Say(client, args)
177 decl String:text[192], String:command[64];
179 if (GetCmdArgString(text, sizeof(text)) < 1)
181 return Plugin_Continue;
184 if (text[strlen(text)-1] == '"')
186 text[strlen(text)-1] = '\0';
190 if (strcmp(command, "say2", false) == 0)
193 if (strcmp(text[startidx], "timeleft", false) == 0)
195 ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
197 else if (strcmp(text[startidx], "thetime", false) == 0)
199 decl String:ctime[64];
200 FormatTime(ctime, 64, NULL_STRING);
202 if(GetConVarInt(g_Cvar_TriggerShow))
204 PrintToChatAll("[SM] %t", "Thetime", ctime);
208 PrintToChat(client,"[SM] %t", "Thetime", ctime);
211 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
213 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
215 decl String:message[64];
216 if (GetConVarBool(g_Cvar_FriendlyFire))
218 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
222 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
225 if(GetConVarInt(g_Cvar_TriggerShow))
227 PrintToChatAll("[SM] %s", message);
231 PrintToChat(client,"[SM] %s", message);
235 else if (strcmp(text[startidx], "currentmap", false) == 0)
238 GetCurrentMap(map, sizeof(map));
240 if(GetConVarInt(g_Cvar_TriggerShow))
242 PrintToChatAll("[SM] %t", "Current Map", map);
246 PrintToChat(client,"[SM] %t", "Current Map", map);
249 else if (strcmp(text[startidx], "nextmap", false) == 0)
252 GetNextMap(map, sizeof(map));
254 if(GetConVarInt(g_Cvar_TriggerShow))
256 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
258 PrintToChatAll("[SM] %t", "Pending Vote");
262 PrintToChatAll("[SM] %t", "Next Map", map);
267 if (mapchooser && !HasEndOfMapVoteFinished())
269 PrintToChat(client, "[SM] %t", "Pending Vote");
273 PrintToChat(client, "[SM] %t", "Next Map", map);
278 return Plugin_Continue;
281 ShowTimeLeft(client, who)
283 new bool:lastround = false;
284 new bool:written = false;
285 new bool:notimelimit = false;
287 decl String:finalOutput[1024];
290 if (who == TIMELEFT_ALL_ALWAYS
291 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
297 if (GetMapTimeLeft(timeleft))
304 mins = timeleft / 60;
305 secs = timeleft % 60;
307 FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
309 else if (GetMapTimeLimit(timelimit) && timelimit == 0)
315 /* 0 timeleft so this must be the last round */
322 if (g_Cvar_WinLimit != INVALID_HANDLE)
324 new winlimit = GetConVarInt(g_Cvar_WinLimit);
330 new len = strlen(finalOutput);
331 if (len < sizeof(finalOutput))
333 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client, winlimit, (winlimit == 1)? "":"s");
338 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client, winlimit, (winlimit == 1)? "":"s");
344 if (g_Cvar_FragLimit != INVALID_HANDLE)
346 new fraglimit = GetConVarInt(g_Cvar_FragLimit);
352 new len = strlen(finalOutput);
353 if (len < sizeof(finalOutput))
355 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client, fraglimit, (fraglimit == 1)? "":"s");
360 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client, fraglimit, (fraglimit == 1)? "":"s");
366 if (g_Cvar_MaxRounds != INVALID_HANDLE)
368 new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
374 new len = strlen(finalOutput);
375 if (len < sizeof(finalOutput))
377 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client, maxrounds, (maxrounds == 1)? "":"s");
382 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client, maxrounds, (maxrounds == 1)? "":"s");
391 FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
393 else if (notimelimit && !written)
395 FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
398 if (who == TIMELEFT_ALL_ALWAYS
399 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
401 PrintToChatAll("[SM] %s", finalOutput);
403 else if (client != 0)
405 PrintToChat(client, "[SM] %s", finalOutput);
410 PrintToServer("[SM] %s", finalOutput);