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 Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
48 new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
49 new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
51 new Handle:g_Timer_TimeShow = INVALID_HANDLE;
53 public OnPluginStart()
55 LoadTranslations("common.phrases");
56 LoadTranslations("basetriggers.phrases");
58 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);
59 g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
60 g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
62 RegConsoleCmd("say", Command_Say);
63 RegConsoleCmd("say_team", Command_Say);
65 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
68 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
70 new Float:newval = StringToFloat(newValue);
74 if (g_Timer_TimeShow != INVALID_HANDLE)
76 KillTimer(g_Timer_TimeShow);
82 if (g_Timer_TimeShow != INVALID_HANDLE)
84 KillTimer(g_Timer_TimeShow);
85 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
88 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
91 public Action:Timer_DisplayTimeleft(Handle:timer)
94 if (GetMapTimeLeft(timeleft))
100 mins = timeleft / 60;
101 secs = timeleft % 60;
104 PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
108 public Action:Command_Say(client, args)
110 decl String:text[192], String:command[64];
112 if (GetCmdArgString(text, sizeof(text)) < 1)
114 return Plugin_Continue;
117 if (text[strlen(text)-1] == '"')
119 text[strlen(text)-1] = '\0';
123 if (strcmp(command, "say2", false) == 0)
126 if (strcmp(text[startidx], "timeleft", false) == 0)
129 if (GetMapTimeLeft(timeleft))
135 mins = timeleft / 60;
136 secs = timeleft % 60;
139 if(GetConVarInt(g_Cvar_TriggerShow))
141 PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
145 PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
150 else if (strcmp(text[startidx], "thetime", false) == 0)
152 decl String:ctime[64];
153 FormatTime(ctime, 64, NULL_STRING);
155 if(GetConVarInt(g_Cvar_TriggerShow))
157 PrintToChatAll("[SM] %t", "Thetime", ctime);
161 PrintToChat(client,"[SM] %t", "Thetime", ctime);
164 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
166 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
168 decl String:message[64];
169 if (GetConVarBool(g_Cvar_FriendlyFire))
171 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
175 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
178 if(GetConVarInt(g_Cvar_TriggerShow))
180 PrintToChatAll("[SM] %s", message);
184 PrintToChat(client,"[SM] %s", message);
188 else if (strcmp(text[startidx], "currentmap", false) == 0)
191 GetCurrentMap(map, sizeof(map));
193 if(GetConVarInt(g_Cvar_TriggerShow))
195 PrintToChatAll("[SM] %t", "Current Map", map);
199 PrintToChat(client,"[SM] %t", "Current Map", map);
203 return Plugin_Continue;