1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/basetriggers.sp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,204 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Basic Info Triggers Plugin
1.8 + * Implements basic information chat triggers like ff and timeleft.
1.9 + *
1.10 + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.11 + * =============================================================================
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify it under
1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
1.15 + * Free Software Foundation.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 + * details.
1.21 + *
1.22 + * You should have received a copy of the GNU General Public License along with
1.23 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 + *
1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 + * by the Valve Corporation. You must obey the GNU General Public License in
1.29 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 + * this exception to all derivative works. AlliedModders LLC defines further
1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 + * or <http://www.sourcemod.net/license.php>.
1.33 + *
1.34 + * Version: $Id$
1.35 + */
1.36 +
1.37 +#pragma semicolon 1
1.38 +
1.39 +#include <sourcemod>
1.40 +
1.41 +public Plugin:myinfo =
1.42 +{
1.43 + name = "Basic Info Triggers",
1.44 + author = "AlliedModders LLC",
1.45 + description = "Adds ff, timeleft, thetime, and others.",
1.46 + version = SOURCEMOD_VERSION,
1.47 + url = "http://www.sourcemod.net/"
1.48 +};
1.49 +
1.50 +new Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
1.51 +new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
1.52 +new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
1.53 +
1.54 +new Handle:g_Timer_TimeShow = INVALID_HANDLE;
1.55 +
1.56 +public OnPluginStart()
1.57 +{
1.58 + LoadTranslations("common.phrases");
1.59 + LoadTranslations("basetriggers.phrases");
1.60 +
1.61 + 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);
1.62 + g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
1.63 + g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
1.64 +
1.65 + RegConsoleCmd("say", Command_Say);
1.66 + RegConsoleCmd("say_team", Command_Say);
1.67 +
1.68 + HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
1.69 +}
1.70 +
1.71 +public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
1.72 +{
1.73 + new Float:newval = StringToFloat(newValue);
1.74 +
1.75 + if (newval < 1.0)
1.76 + {
1.77 + if (g_Timer_TimeShow != INVALID_HANDLE)
1.78 + {
1.79 + KillTimer(g_Timer_TimeShow);
1.80 + }
1.81 +
1.82 + return;
1.83 + }
1.84 +
1.85 + if (g_Timer_TimeShow != INVALID_HANDLE)
1.86 + {
1.87 + KillTimer(g_Timer_TimeShow);
1.88 + g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
1.89 + }
1.90 + else
1.91 + g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
1.92 +}
1.93 +
1.94 +public Action:Timer_DisplayTimeleft(Handle:timer)
1.95 +{
1.96 + new timeleft;
1.97 + if (GetMapTimeLeft(timeleft))
1.98 + {
1.99 + new mins, secs;
1.100 +
1.101 + if (timeleft > 0)
1.102 + {
1.103 + mins = timeleft / 60;
1.104 + secs = timeleft % 60;
1.105 + }
1.106 +
1.107 + PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
1.108 + }
1.109 +}
1.110 +
1.111 +public Action:Command_Say(client, args)
1.112 +{
1.113 + decl String:text[192], String:command[64];
1.114 + new startidx = 0;
1.115 + if (GetCmdArgString(text, sizeof(text)) < 1)
1.116 + {
1.117 + return Plugin_Continue;
1.118 + }
1.119 +
1.120 + if (text[strlen(text)-1] == '"')
1.121 + {
1.122 + text[strlen(text)-1] = '\0';
1.123 + startidx = 1;
1.124 + }
1.125 +
1.126 + if (strcmp(command, "say2", false) == 0)
1.127 + startidx += 4;
1.128 +
1.129 + if (strcmp(text[startidx], "timeleft", false) == 0)
1.130 + {
1.131 + new timeleft;
1.132 + if (GetMapTimeLeft(timeleft))
1.133 + {
1.134 + new mins, secs;
1.135 +
1.136 + if (timeleft > 0)
1.137 + {
1.138 + mins = timeleft / 60;
1.139 + secs = timeleft % 60;
1.140 + }
1.141 +
1.142 + if(GetConVarInt(g_Cvar_TriggerShow))
1.143 + {
1.144 + PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
1.145 + }
1.146 + else
1.147 + {
1.148 + PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
1.149 + }
1.150 + }
1.151 +
1.152 + }
1.153 + else if (strcmp(text[startidx], "thetime", false) == 0)
1.154 + {
1.155 + decl String:ctime[64];
1.156 + FormatTime(ctime, 64, NULL_STRING);
1.157 +
1.158 + if(GetConVarInt(g_Cvar_TriggerShow))
1.159 + {
1.160 + PrintToChatAll("[SM] %t", "Thetime", ctime);
1.161 + }
1.162 + else
1.163 + {
1.164 + PrintToChat(client,"[SM] %t", "Thetime", ctime);
1.165 + }
1.166 + }
1.167 + else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
1.168 + {
1.169 + if (g_Cvar_FriendlyFire != INVALID_HANDLE)
1.170 + {
1.171 + decl String:message[64];
1.172 + if (GetConVarBool(g_Cvar_FriendlyFire))
1.173 + {
1.174 + Format(message, sizeof(message), "%T", "Friendly Fire On", client);
1.175 + }
1.176 + else
1.177 + {
1.178 + Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
1.179 + }
1.180 +
1.181 + if(GetConVarInt(g_Cvar_TriggerShow))
1.182 + {
1.183 + PrintToChatAll("[SM] %s", message);
1.184 + }
1.185 + else
1.186 + {
1.187 + PrintToChat(client,"[SM] %s", message);
1.188 + }
1.189 + }
1.190 + }
1.191 + else if (strcmp(text[startidx], "currentmap", false) == 0)
1.192 + {
1.193 + decl String:map[64];
1.194 + GetCurrentMap(map, sizeof(map));
1.195 +
1.196 + if(GetConVarInt(g_Cvar_TriggerShow))
1.197 + {
1.198 + PrintToChatAll("[SM] %t", "Current Map", map);
1.199 + }
1.200 + else
1.201 + {
1.202 + PrintToChat(client,"[SM] %t", "Current Map", map);
1.203 + }
1.204 + }
1.205 +
1.206 + return Plugin_Continue;
1.207 +}
1.208 \ No newline at end of file