Added /MP back to core and sdktools MSVC project files.
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);
84 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
86 HookEvent("round_end", Event_RoundEnd);
87 HookEvent("game_start", Event_GameStart);
88 HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
89 HookEventEx("teamplay_restart_round", Event_TFRestartRound);
90 HookEventEx("arena_win_panel", Event_TeamPlayWinPanel);
92 g_Cvar_WinLimit = FindConVar("mp_winlimit");
93 g_Cvar_FragLimit = FindConVar("mp_fraglimit");
94 g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
96 mapchooser = LibraryExists("mapchooser");
104 /* Round count tracking */
105 public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
107 /* Game got restarted - reset our round count tracking */
111 public Event_GameStart(Handle:event, const String:name[], bool:dontBroadcast)
113 /* Game got restarted - reset our round count tracking */
117 public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
119 if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
124 /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
125 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
130 public OnLibraryRemoved(const String:name[])
132 if (StrEqual(name, "mapchooser"))
138 public OnLibraryAdded(const String:name[])
140 if (StrEqual(name, "mapchooser"))
146 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
148 new Float:newval = StringToFloat(newValue);
152 if (g_Timer_TimeShow != INVALID_HANDLE)
154 KillTimer(g_Timer_TimeShow);
160 if (g_Timer_TimeShow != INVALID_HANDLE)
162 KillTimer(g_Timer_TimeShow);
163 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
166 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
169 public Action:Timer_DisplayTimeleft(Handle:timer)
171 ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS);
174 public Action:Command_Timeleft(client, args)
176 ShowTimeLeft(client, TIMELEFT_ONE);
178 return Plugin_Handled;
181 public Action:Command_Nextmap(client, args)
185 GetNextMap(map, sizeof(map));
187 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
189 ReplyToCommand(client, "[SM] %t", "Pending Vote");
193 ReplyToCommand(client, "[SM] %t", "Next Map", map);
196 return Plugin_Handled;
199 public Action:Command_Say(client, args)
201 decl String:text[192], String:command[64];
203 if (GetCmdArgString(text, sizeof(text)) < 1)
205 return Plugin_Continue;
208 if (text[strlen(text)-1] == '"')
210 text[strlen(text)-1] = '\0';
214 if (strcmp(command, "say2", false) == 0)
217 if (strcmp(text[startidx], "timeleft", false) == 0)
219 ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
221 else if (strcmp(text[startidx], "thetime", false) == 0)
223 decl String:ctime[64];
224 FormatTime(ctime, 64, NULL_STRING);
226 if(GetConVarInt(g_Cvar_TriggerShow))
228 PrintToChatAll("[SM] %t", "Thetime", ctime);
232 PrintToChat(client,"[SM] %t", "Thetime", ctime);
235 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
237 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
239 decl String:message[64];
240 if (GetConVarBool(g_Cvar_FriendlyFire))
242 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
246 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
249 if(GetConVarInt(g_Cvar_TriggerShow))
251 PrintToChatAll("[SM] %s", message);
255 PrintToChat(client,"[SM] %s", message);
259 else if (strcmp(text[startidx], "currentmap", false) == 0)
262 GetCurrentMap(map, sizeof(map));
264 if(GetConVarInt(g_Cvar_TriggerShow))
266 PrintToChatAll("[SM] %t", "Current Map", map);
270 PrintToChat(client,"[SM] %t", "Current Map", map);
273 else if (strcmp(text[startidx], "nextmap", false) == 0)
276 GetNextMap(map, sizeof(map));
278 if(GetConVarInt(g_Cvar_TriggerShow))
280 if (mapchooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
282 PrintToChatAll("[SM] %t", "Pending Vote");
286 PrintToChatAll("[SM] %t", "Next Map", map);
291 if (mapchooser && !HasEndOfMapVoteFinished())
293 PrintToChat(client, "[SM] %t", "Pending Vote");
297 PrintToChat(client, "[SM] %t", "Next Map", map);
302 return Plugin_Continue;
305 ShowTimeLeft(client, who)
307 new bool:lastround = false;
308 new bool:written = false;
309 new bool:notimelimit = false;
311 decl String:finalOutput[1024];
314 if (who == TIMELEFT_ALL_ALWAYS
315 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
321 if (GetMapTimeLeft(timeleft))
328 mins = timeleft / 60;
329 secs = timeleft % 60;
331 FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
333 else if (GetMapTimeLimit(timelimit) && timelimit == 0)
339 /* 0 timeleft so this must be the last round */
346 if (g_Cvar_WinLimit != INVALID_HANDLE)
348 new winlimit = GetConVarInt(g_Cvar_WinLimit);
354 new len = strlen(finalOutput);
355 if (len < sizeof(finalOutput))
359 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppendPlural" ,client, winlimit);
363 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client);
371 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimitPlural", client, winlimit);
375 FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client);
383 if (g_Cvar_FragLimit != INVALID_HANDLE)
385 new fraglimit = GetConVarInt(g_Cvar_FragLimit);
391 new len = strlen(finalOutput);
392 if (len < sizeof(finalOutput))
396 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppendPlural", client, fraglimit);
400 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client);
408 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimitPlural", client, fraglimit);
412 FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client);
420 if (g_Cvar_MaxRounds != INVALID_HANDLE)
422 new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
426 new remaining = maxrounds - g_TotalRounds;
430 new len = strlen(finalOutput);
431 if (len < sizeof(finalOutput))
435 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppendPlural", client, remaining);
439 FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client);
447 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRoundsPlural", client, remaining);
451 FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client);
462 FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
464 else if (notimelimit && !written)
466 FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
469 if (who == TIMELEFT_ALL_ALWAYS
470 || (who == TIMELEFT_ALL_MAYBE && GetConVarInt(g_Cvar_TriggerShow)))
472 PrintToChatAll("[SM] %s", finalOutput);
474 else if (client != 0)
476 PrintToChat(client, "[SM] %s", finalOutput);
481 PrintToServer("[SM] %s", finalOutput);