Import of basetriggers
authorMichael McKoy <ferret99gt@gmail.com>
Fri Jul 27 00:24:04 2007 +0000 (2007-07-27)
changeset 118243d08badb860
parent 1181 c2551c7f8a9b
child 1183 c8ff1fa5cf5c
Import of basetriggers
plugins/basetriggers.sp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/basetriggers.sp	Fri Jul 27 00:24:04 2007 +0000
     1.3 @@ -0,0 +1,206 @@
     1.4 +/**
     1.5 + * basetriggers.sp
     1.6 + * Implements basic information chat triggers like ff and timeleft
     1.7 + * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
     1.8 + *
     1.9 + * This program is free software; you can redistribute it and/or
    1.10 + * modify it under the terms of the GNU General Public License
    1.11 + * as published by the Free Software Foundation; either version 2
    1.12 + * of the License, or (at your option) any later version.
    1.13 + *
    1.14 + * This program is distributed in the hope that it will be useful,
    1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.17 + * GNU General Public License for more details.
    1.18 + * 
    1.19 + * You should have received a copy of the GNU General Public License
    1.20 + * along with this program; if not, write to the Free Software
    1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.22 + *
    1.23 + * Version: $Id$
    1.24 + */
    1.25 +#include <sourcemod>
    1.26 +
    1.27 +#pragma semicolon 1
    1.28 +
    1.29 +public Plugin:myinfo = 
    1.30 +{
    1.31 +	name = "Basic Info Triggers",
    1.32 +	author = "AlliedModders LLC",
    1.33 +	description = "Adds ff, timeleft, thetime, and others.",
    1.34 +	version = SOURCEMOD_VERSION,
    1.35 +	url = "http://www.sourcemod.net/"
    1.36 +};
    1.37 +
    1.38 +new Float:g_fStartTime;
    1.39 +new Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
    1.40 +new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
    1.41 +new Handle:g_Cvar_Timelimit = INVALID_HANDLE;
    1.42 +new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
    1.43 +
    1.44 +new Handle:g_Timer_TimeShow = INVALID_HANDLE;
    1.45 +
    1.46 +public OnPluginStart()
    1.47 +{
    1.48 +	LoadTranslations("common.phrases");
    1.49 +	LoadTranslations("plugin.basetriggers");
    1.50 +	
    1.51 +	g_Cvar_TriggerShow = CreateConVar("sm_trigger_show", "1", "Display timeleft to all players? (0 off, 1 on, def. 1)", 0, true, 0.0, true, 1.0);	
    1.52 +	g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
    1.53 +	g_Cvar_Timelimit = FindConVar("mp_timelimit");
    1.54 +	g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");
    1.55 +	
    1.56 +	RegConsoleCmd("say", Command_Say);
    1.57 +	RegConsoleCmd("say_team", Command_Say);
    1.58 +	
    1.59 +	HookEvent("round_end", Event_RoundEnd, EventHookMode_Post);
    1.60 +	
    1.61 +	HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
    1.62 +}
    1.63 +
    1.64 +public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
    1.65 +{
    1.66 +	new Float:newval = StringToFloat(newValue);
    1.67 +	
    1.68 +	if (newval < 1.0 && g_Timer_TimeShow != INVALID_HANDLE)
    1.69 +	{
    1.70 +		KillTimer(g_Timer_TimeShow);		
    1.71 +		return;
    1.72 +	}
    1.73 +	
    1.74 +	if (g_Timer_TimeShow != INVALID_HANDLE)
    1.75 +	{
    1.76 +		KillTimer(g_Timer_TimeShow);
    1.77 +		g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
    1.78 +	}
    1.79 +	else
    1.80 +		g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
    1.81 +}
    1.82 +
    1.83 +public Action:Timer_DisplayTimeleft(Handle:timer)
    1.84 +{
    1.85 +	new mins, secs;
    1.86 +	new timeleft = RoundToNearest(GetTimeLeft());
    1.87 +	
    1.88 +	if (timeleft > 0)
    1.89 +	{
    1.90 +		mins = timeleft / 60;
    1.91 +		secs = timeleft % 60;		
    1.92 +	}
    1.93 +
    1.94 +	PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
    1.95 +}
    1.96 +
    1.97 +public Action:Command_Say(client, args)
    1.98 +{
    1.99 +	decl String:text[192], String:command[64];
   1.100 +	new startidx = 0;
   1.101 +	GetCmdArgString(text, sizeof(text));
   1.102 +	
   1.103 +	if (text[strlen(text)-1] == '"')
   1.104 +	{
   1.105 +		text[strlen(text)-1] = '\0';
   1.106 +		startidx = 1;
   1.107 +	}
   1.108 +
   1.109 +	if (strcmp(command, "say2", false) == 0)
   1.110 +		startidx += 4;
   1.111 +
   1.112 +	if (strcmp(text[startidx], "timeleft", false) == 0)
   1.113 +	{
   1.114 +		new mins, secs;
   1.115 +		new timeleft = RoundToNearest(GetTimeLeft());
   1.116 +		
   1.117 +		if (timeleft > 0)
   1.118 +		{
   1.119 +			mins = timeleft / 60;
   1.120 +			secs = timeleft % 60;		
   1.121 +		}	
   1.122 +		
   1.123 +		if(GetConVarInt(g_Cvar_TriggerShow))
   1.124 +		{
   1.125 +			PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
   1.126 +		}
   1.127 +		else
   1.128 +		{
   1.129 +			PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
   1.130 +		}
   1.131 +		
   1.132 +	}
   1.133 +	else if (strcmp(text[startidx], "thetime", false) == 0)
   1.134 +	{
   1.135 +		decl String:ctime[64];
   1.136 +		FormatTime(ctime, 64, "%m/%d/%Y - %H:%M:%S");
   1.137 +		
   1.138 +		if(GetConVarInt(g_Cvar_TriggerShow))
   1.139 +		{
   1.140 +			PrintToChatAll("[SM] %t %s", "Thetime", ctime);
   1.141 +		}
   1.142 +		else
   1.143 +		{
   1.144 +			PrintToChat(client,"[SM] %t %s", "Thetime", ctime);
   1.145 +		}
   1.146 +	}
   1.147 +	else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
   1.148 +	{
   1.149 +		if (g_Cvar_FriendlyFire != INVALID_HANDLE)
   1.150 +		{
   1.151 +			decl String:message[64];
   1.152 +			if (GetConVarBool(g_Cvar_FriendlyFire))
   1.153 +			{
   1.154 +				Format(message, sizeof(message), "%T", "Friendly Fire On", client);
   1.155 +			}
   1.156 +			else
   1.157 +			{
   1.158 +				Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
   1.159 +			}
   1.160 +		
   1.161 +			if(GetConVarInt(g_Cvar_TriggerShow))
   1.162 +			{
   1.163 +				PrintToChatAll("[SM] %s", message);
   1.164 +			}
   1.165 +			else
   1.166 +			{
   1.167 +				PrintToChat(client,"[SM] %s", message);		
   1.168 +			}
   1.169 +		}
   1.170 +	}
   1.171 +	else if (strcmp(text[startidx], "currentmap", false) == 0)
   1.172 +	{
   1.173 +		decl String:map[64];
   1.174 +		GetCurrentMap(map, sizeof(map));
   1.175 +		
   1.176 +		if(GetConVarInt(g_Cvar_TriggerShow))
   1.177 +		{
   1.178 +			PrintToChatAll("[SM] %t", "Current Map", map);
   1.179 +		}
   1.180 +		else
   1.181 +		{
   1.182 +			PrintToChat(client,"[SM] %t", "Current Map", map);
   1.183 +		}
   1.184 +	}	
   1.185 +	
   1.186 +	return Plugin_Continue;
   1.187 +}
   1.188 +
   1.189 +public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
   1.190 +{
   1.191 +	new reason = GetEventInt(event, "reason");
   1.192 +	if(reason == 16)
   1.193 +	{
   1.194 +		g_fStartTime = GetEngineTime();		
   1.195 +	}	
   1.196 +}
   1.197 +
   1.198 +public OnMapStart()
   1.199 +{
   1.200 +	g_fStartTime = GetEngineTime();
   1.201 +}
   1.202 +
   1.203 +Float:GetTimeLeft()
   1.204 +{
   1.205 +	new Float:fLimit = GetConVarFloat(g_Cvar_Timelimit);
   1.206 +	new Float:fElapsed = GetEngineTime() - g_fStartTime;
   1.207 +	
   1.208 +	return (fLimit*60.0) - fElapsed;
   1.209 +}