plugins/basetriggers.sp
author David Anderson <dvander@alliedmods.net>
Fri Nov 16 14:17:56 2007 +0000 (2007-11-16)
changeset 1684 c4e72bd36591
parent 1467 57e3f93188f1
child 1947 e73a1e51833b
permissions -rw-r--r--
fixed amb1161 - voteban didn't actually ban
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basic Info Triggers Plugin
     5  * Implements basic information chat triggers like ff and timeleft.
     6  *
     7  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    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.
    13  * 
    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
    17  * details.
    18  *
    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/>.
    21  *
    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>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 #pragma semicolon 1
    35 
    36 #include <sourcemod>
    37 
    38 public Plugin:myinfo = 
    39 {
    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/"
    45 };
    46 
    47 new Handle:g_Cvar_TriggerShow = INVALID_HANDLE;
    48 new Handle:g_Cvar_TimeleftInterval = INVALID_HANDLE;
    49 new Handle:g_Cvar_FriendlyFire = INVALID_HANDLE;
    50 
    51 new Handle:g_Timer_TimeShow = INVALID_HANDLE;
    52 
    53 public OnPluginStart()
    54 {
    55 	LoadTranslations("common.phrases");
    56 	LoadTranslations("basetriggers.phrases");
    57 	
    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");
    61 	
    62 	RegConsoleCmd("say", Command_Say);
    63 	RegConsoleCmd("say_team", Command_Say);
    64 	
    65 	HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
    66 }
    67 
    68 public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
    69 {
    70 	new Float:newval = StringToFloat(newValue);
    71 	
    72 	if (newval < 1.0)
    73 	{
    74 		if (g_Timer_TimeShow != INVALID_HANDLE)
    75 		{
    76 			KillTimer(g_Timer_TimeShow);		
    77 		}
    78 		
    79 		return;
    80 	}
    81 	
    82 	if (g_Timer_TimeShow != INVALID_HANDLE)
    83 	{
    84 		KillTimer(g_Timer_TimeShow);
    85 		g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
    86 	}
    87 	else
    88 		g_Timer_TimeShow = CreateTimer(newval, Timer_DisplayTimeleft, _, TIMER_REPEAT);
    89 }
    90 
    91 public Action:Timer_DisplayTimeleft(Handle:timer)
    92 {
    93 	new timeleft;
    94 	if (GetMapTimeLeft(timeleft))
    95 	{
    96 		new mins, secs;
    97 		
    98 		if (timeleft > 0)
    99 		{
   100 			mins = timeleft / 60;
   101 			secs = timeleft % 60;		
   102 		}
   103 		
   104 		PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
   105 	}
   106 }
   107 
   108 public Action:Command_Say(client, args)
   109 {
   110 	decl String:text[192], String:command[64];
   111 	new startidx = 0;
   112 	if (GetCmdArgString(text, sizeof(text)) < 1)
   113 	{
   114 		return Plugin_Continue;
   115 	}
   116 	
   117 	if (text[strlen(text)-1] == '"')
   118 	{
   119 		text[strlen(text)-1] = '\0';
   120 		startidx = 1;
   121 	}
   122 
   123 	if (strcmp(command, "say2", false) == 0)
   124 		startidx += 4;
   125 
   126 	if (strcmp(text[startidx], "timeleft", false) == 0)
   127 	{
   128 		new timeleft;
   129 		if (GetMapTimeLeft(timeleft))
   130 		{
   131 			new mins, secs;
   132 			
   133 			if (timeleft > 0)
   134 			{
   135 				mins = timeleft / 60;
   136 				secs = timeleft % 60;		
   137 			}
   138 			
   139 			if(GetConVarInt(g_Cvar_TriggerShow))
   140 			{
   141 				PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
   142 			}
   143 			else
   144 			{
   145 				PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
   146 			}
   147 		}
   148 		
   149 	}
   150 	else if (strcmp(text[startidx], "thetime", false) == 0)
   151 	{
   152 		decl String:ctime[64];
   153 		FormatTime(ctime, 64, NULL_STRING);
   154 		
   155 		if(GetConVarInt(g_Cvar_TriggerShow))
   156 		{
   157 			PrintToChatAll("[SM] %t", "Thetime", ctime);
   158 		}
   159 		else
   160 		{
   161 			PrintToChat(client,"[SM] %t", "Thetime", ctime);
   162 		}
   163 	}
   164 	else if (strcmp(text[startidx], "ff", false) == 0 || strcmp(text[startidx], "/ff", false) == 0)
   165 	{
   166 		if (g_Cvar_FriendlyFire != INVALID_HANDLE)
   167 		{
   168 			decl String:message[64];
   169 			if (GetConVarBool(g_Cvar_FriendlyFire))
   170 			{
   171 				Format(message, sizeof(message), "%T", "Friendly Fire On", client);
   172 			}
   173 			else
   174 			{
   175 				Format(message, sizeof(message), "%T", "Friendly Fire Off", client);
   176 			}
   177 		
   178 			if(GetConVarInt(g_Cvar_TriggerShow))
   179 			{
   180 				PrintToChatAll("[SM] %s", message);
   181 			}
   182 			else
   183 			{
   184 				PrintToChat(client,"[SM] %s", message);		
   185 			}
   186 		}
   187 	}
   188 	else if (strcmp(text[startidx], "currentmap", false) == 0)
   189 	{
   190 		decl String:map[64];
   191 		GetCurrentMap(map, sizeof(map));
   192 		
   193 		if(GetConVarInt(g_Cvar_TriggerShow))
   194 		{
   195 			PrintToChatAll("[SM] %t", "Current Map", map);
   196 		}
   197 		else
   198 		{
   199 			PrintToChat(client,"[SM] %t", "Current Map", map);
   200 		}
   201 	}	
   202 	
   203 	return Plugin_Continue;
   204 }