3 * Implements basic information chat triggers like ff and timeleft
4 * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 public Plugin:myinfo =
28 name = "Basic Info Triggers",
29 author = "AlliedModders LLC",
30 description = "Adds ff, timeleft, thetime, and others.",
31 version = SOURCEMOD_VERSION,
32 url = "http://www.sourcemod.net/"
35 new Float:g_fStartTime;
36 new Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
37 new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
38 new Handle:g_Cvar_Timelimit = INVALID_HANDLE;
39 new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
41 new Handle:g_Timer_TimeShow = INVALID_HANDLE;
43 public OnPluginStart()
45 LoadTranslations("common.phrases");
46 LoadTranslations("basetriggers.phrases");
48 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);
49 g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
50 g_Cvar_Timelimit = FindConVar("mp_timelimit");
51 g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
53 RegConsoleCmd("say", Command_Say);
54 RegConsoleCmd("say_team", Command_Say);
56 HookEvent("round_end", Event_RoundEnd, EventHookMode_Post);
58 HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
61 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
63 new Float:newval = StringToFloat(newValue);
67 if (g_Timer_TimeShow != INVALID_HANDLE)
69 KillTimer(g_Timer_TimeShow);
75 if (g_Timer_TimeShow != INVALID_HANDLE)
77 KillTimer(g_Timer_TimeShow);
78 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
81 g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
84 public Action:Timer_DisplayTimeleft(Handle:timer)
87 new timeleft = RoundToNearest(GetTimeLeft());
95 PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
98 public Action:Command_Say(client, args)
100 decl String:text[192], String:command[64];
102 GetCmdArgString(text, sizeof(text));
104 if (text[strlen(text)-1] == '"')
106 text[strlen(text)-1] = '\0';
110 if (strcmp(command, "say2", false) == 0)
113 if (strcmp(text[startidx], "timeleft", false) == 0)
116 new timeleft = RoundToNearest(GetTimeLeft());
120 mins = timeleft / 60;
121 secs = timeleft % 60;
124 if(GetConVarInt(g_Cvar_TriggerShow))
126 PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
130 PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
134 else if (strcmp(text[startidx], "thetime", false) == 0)
136 decl String:ctime[64];
137 FormatTime(ctime, 64, "%m/%d/%Y - %H:%M:%S");
139 if(GetConVarInt(g_Cvar_TriggerShow))
141 PrintToChatAll("[SM] %t", "Thetime", ctime);
145 PrintToChat(client,"[SM] %t", "Thetime", ctime);
148 else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
150 if (g_Cvar_FriendlyFire != INVALID_HANDLE)
152 decl String:message[64];
153 if (GetConVarBool(g_Cvar_FriendlyFire))
155 Format(message, sizeof(message), "%T", "Friendly Fire On", client);
159 Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
162 if(GetConVarInt(g_Cvar_TriggerShow))
164 PrintToChatAll("[SM] %s", message);
168 PrintToChat(client,"[SM] %s", message);
172 else if (strcmp(text[startidx], "currentmap", false) == 0)
175 GetCurrentMap(map, sizeof(map));
177 if(GetConVarInt(g_Cvar_TriggerShow))
179 PrintToChatAll("[SM] %t", "Current Map", map);
183 PrintToChat(client,"[SM] %t", "Current Map", map);
187 return Plugin_Continue;
190 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
192 new reason = GetEventInt(event, "reason");
195 g_fStartTime = GetEngineTime();
201 g_fStartTime = GetEngineTime();
206 new Float:fLimit = GetConVarFloat(g_Cvar_Timelimit);
207 new Float:fElapsed = GetEngineTime() - g_fStartTime;
209 return (fLimit*60.0) - fElapsed;