3 * =============================================================================
4 * SourceMod Basic Info Triggers Plugin
5 * Implements basic information chat triggers like ff and timeleft.
7 * SourceMod (C)2004-2007 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>.
38 public Plugin:myinfo =
40 name = "Basic Info Triggers",
41 author = "AlliedModders LLC",
42 description = "Adds ff, timeleft, thetime, and others.",
43 version = SOURCEMOD_VERSION,
44 url = "http://www.sourcemod.net/"
47 new Float:g_fStartTime;
48 new Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
49 new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
50 new Handle:g_Cvar_Timelimit = INVALID_HANDLE;
51 new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
53 new Handle:g_Timer_TimeShow = INVALID_HANDLE;
55 public OnPluginStart()
57 LoadTranslations("common.phrases");
58 LoadTranslations("basetriggers.phrases");
60 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);
61 g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
62 g_Cvar_Timelimit = FindConVar("mp_timelimit");
63 g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
65 RegConsoleCmd("say", Command_Say);
66 RegConsoleCmd("say_team", Command_Say);
68 HookEvent("round_end", Event_RoundEnd, EventHookMode_Post);
70 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
73 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
75 new Float:newval = StringToFloat(newValue);
79 if (g_Timer_TimeShow != INVALID_HANDLE)
81 KillTimer(g_Timer_TimeShow);
87 if (g_Timer_TimeShow != INVALID_HANDLE)
89 KillTimer(g_Timer_TimeShow);
90 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
93 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
96 public Action:Timer_DisplayTimeleft(Handle:timer)
99 new timeleft = RoundToNearest(GetTimeLeft());
103 mins = timeleft / 60;
104 secs = timeleft % 60;
107 PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
110 public Action:Command_Say(client, args)
112 decl String:text[192], String:command[64];
114 GetCmdArgString(text, sizeof(text));
116 if (text[strlen(text)-1] == '"')
118 text[strlen(text)-1] = '\0';
122 if (strcmp(command, "say2", false) == 0)
125 if (strcmp(text[startidx], "timeleft", false) == 0)
128 new timeleft = RoundToNearest(GetTimeLeft());
132 mins = timeleft / 60;
133 secs = timeleft % 60;
136 if(GetConVarInt(g_Cvar_TriggerShow))
138 PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
142 PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
146 else if (strcmp(text[startidx], "thetime", false) == 0)
148 decl String:ctime[64];
149 FormatTime(ctime, 64, NULL_STRING);
151 if(GetConVarInt(g_Cvar_TriggerShow))
153 PrintToChatAll("[SM] %t", "Thetime", ctime);
157 PrintToChat(client,"[SM] %t", "Thetime", ctime);
160 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
162 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
164 decl String:message[64];
165 if (GetConVarBool(g_Cvar_FriendlyFire))
167 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
171 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
174 if(GetConVarInt(g_Cvar_TriggerShow))
176 PrintToChatAll("[SM] %s", message);
180 PrintToChat(client,"[SM] %s", message);
184 else if (strcmp(text[startidx], "currentmap", false) == 0)
187 GetCurrentMap(map, sizeof(map));
189 if(GetConVarInt(g_Cvar_TriggerShow))
191 PrintToChatAll("[SM] %t", "Current Map", map);
195 PrintToChat(client,"[SM] %t", "Current Map", map);
199 return Plugin_Continue;
202 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
204 new reason = GetEventInt(event, "reason");
207 g_fStartTime = GetEngineTime();
213 g_fStartTime = GetEngineTime();
218 new Float:fLimit = GetConVarFloat(g_Cvar_Timelimit);
219 new Float:fElapsed = GetEngineTime() - g_fStartTime;
221 return (fLimit*60.0) - fElapsed;