Added amb1665 and amb1381 - Added other map limits to 'timeleft' and handling of timeleft/nextmap console commands.
authorMatt Woodrow <pred@alliedmods.net>
Mon May 26 01:09:10 2008 +0000 (2008-05-26)
changeset 20833dcbef056e44
parent 2082 89c0bd044fbe
child 2084 b8292af05705
Added amb1665 and amb1381 - Added other map limits to 'timeleft' and handling of timeleft/nextmap console commands.
plugins/basetriggers.sp
plugins/nextmap.sp
translations/basetriggers.phrases.txt
     1.1 --- a/plugins/basetriggers.sp	Sun May 25 20:50:11 2008 +0000
     1.2 +++ b/plugins/basetriggers.sp	Mon May 26 01:09:10 2008 +0000
     1.3 @@ -50,6 +50,10 @@
     1.4  
     1.5  new Handle:g_Timer_TimeShow = INVALID_HANDLE;
     1.6  
     1.7 +new Handle:g_Cvar_WinLimit = INVALID_HANDLE;
     1.8 +new Handle:g_Cvar_FragLimit = INVALID_HANDLE;
     1.9 +new Handle:g_Cvar_MaxRounds = INVALID_HANDLE;
    1.10 +
    1.11  public OnPluginStart()
    1.12  {
    1.13  	LoadTranslations("common.phrases");
    1.14 @@ -62,7 +66,14 @@
    1.15  	RegConsoleCmd("say", Command_Say);
    1.16  	RegConsoleCmd("say_team", Command_Say);
    1.17  	
    1.18 +	RegConsoleCmd("timeleft", Command_Timeleft);
    1.19 +	
    1.20  	HookConVarChange(g_Cvar_TimeleftInterval, ConVarChange_TimeleftInterval);
    1.21 +	
    1.22 +	
    1.23 +	g_Cvar_WinLimit = FindConVar("mp_winlimit");
    1.24 +	g_Cvar_FragLimit = FindConVar("mp_fraglimit");
    1.25 +	g_Cvar_MaxRounds = FindConVar("mp_maxrounds");
    1.26  }
    1.27  
    1.28  public ConVarChange_TimeleftInterval(Handle:convar, const String:oldValue[], const String:newValue[])
    1.29 @@ -90,19 +101,14 @@
    1.30  
    1.31  public Action:Timer_DisplayTimeleft(Handle:timer)
    1.32  {
    1.33 -	new timeleft;
    1.34 -	if (GetMapTimeLeft(timeleft))
    1.35 -	{
    1.36 -		new mins, secs;
    1.37 -		
    1.38 -		if (timeleft > 0)
    1.39 -		{
    1.40 -			mins = timeleft / 60;
    1.41 -			secs = timeleft % 60;		
    1.42 -		}
    1.43 -		
    1.44 -		PrintToChatAll("[SM] %T %d:%02d", "Timeleft", LANG_SERVER, mins, secs);
    1.45 -	}
    1.46 +	ShowTimeLeft(0, true);	
    1.47 +}
    1.48 +
    1.49 +public Action:Command_Timeleft(client, args)
    1.50 +{
    1.51 +	ShowTimeLeft(client);
    1.52 +	
    1.53 +	return Plugin_Handled;
    1.54  }
    1.55  
    1.56  public Action:Command_Say(client, args)
    1.57 @@ -125,27 +131,7 @@
    1.58  
    1.59  	if (strcmp(text[startidx], "timeleft", false) == 0)
    1.60  	{
    1.61 -		new timeleft;
    1.62 -		if (GetMapTimeLeft(timeleft))
    1.63 -		{
    1.64 -			new mins, secs;
    1.65 -			
    1.66 -			if (timeleft > 0)
    1.67 -			{
    1.68 -				mins = timeleft / 60;
    1.69 -				secs = timeleft % 60;		
    1.70 -			}
    1.71 -			
    1.72 -			if(GetConVarInt(g_Cvar_TriggerShow))
    1.73 -			{
    1.74 -				PrintToChatAll("[SM] %t %d:%02d", "Timeleft", mins, secs);
    1.75 -			}
    1.76 -			else
    1.77 -			{
    1.78 -				PrintToChat(client,"[SM] %t %d:%02d", "Timeleft", mins, secs);
    1.79 -			}
    1.80 -		}
    1.81 -		
    1.82 +		ShowTimeLeft(client);
    1.83  	}
    1.84  	else if (strcmp(text[startidx], "thetime", false) == 0)
    1.85  	{
    1.86 @@ -201,4 +187,135 @@
    1.87  	}	
    1.88  	
    1.89  	return Plugin_Continue;
    1.90 +}
    1.91 +
    1.92 +ShowTimeLeft(client, bool:all=false)
    1.93 +{
    1.94 +	new bool:lastround = false;
    1.95 +	new bool:written = false;
    1.96 +	new bool:notimelimit = false;
    1.97 +	
    1.98 +	decl String:finalOutput[1024];
    1.99 +	finalOutput[0] = 0;
   1.100 +	
   1.101 +	if(GetConVarInt(g_Cvar_TriggerShow) || all)
   1.102 +	{
   1.103 +		client = 0;	
   1.104 +	}
   1.105 +	
   1.106 +	new timeleft;
   1.107 +	if (GetMapTimeLeft(timeleft))
   1.108 +	{
   1.109 +		new mins, secs;
   1.110 +		new timelimit;
   1.111 +		
   1.112 +		if (timeleft > 0)
   1.113 +		{
   1.114 +			mins = timeleft / 60;
   1.115 +			secs = timeleft % 60;
   1.116 +			written = true;
   1.117 +			FormatEx(finalOutput, sizeof(finalOutput), "%T %d:%02d", "Timeleft", client, mins, secs);
   1.118 +		}
   1.119 +		else if (GetMapTimeLimit(timelimit) && timelimit == 0)
   1.120 +		{
   1.121 +			notimelimit = true;
   1.122 +		}
   1.123 +		else
   1.124 +		{
   1.125 +			/* 0 timeleft so this must be the last round */
   1.126 +			lastround=true;
   1.127 +		}
   1.128 +	}
   1.129 +	
   1.130 +	if (!lastround)
   1.131 +	{
   1.132 +		if (g_Cvar_WinLimit != INVALID_HANDLE)
   1.133 +		{
   1.134 +			new winlimit = GetConVarInt(g_Cvar_WinLimit);
   1.135 +			
   1.136 +			if (winlimit > 0)
   1.137 +			{
   1.138 +				if (written)
   1.139 +				{
   1.140 +					new len = strlen(finalOutput);
   1.141 +					if (len < sizeof(finalOutput))
   1.142 +					{
   1.143 +						FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "WinLimitAppend" ,client, winlimit, (winlimit == 1)? "":"s");
   1.144 +					}
   1.145 +				}
   1.146 +				else
   1.147 +				{
   1.148 +					FormatEx(finalOutput, sizeof(finalOutput), "%T", "WinLimit", client, winlimit, (winlimit == 1)? "":"s");
   1.149 +					written = true;
   1.150 +				}
   1.151 +			}
   1.152 +		}
   1.153 +		
   1.154 +		if (g_Cvar_FragLimit != INVALID_HANDLE)
   1.155 +		{
   1.156 +			new fraglimit = GetConVarInt(g_Cvar_FragLimit);
   1.157 +			
   1.158 +			if (fraglimit > 0)
   1.159 +			{
   1.160 +				if (written)
   1.161 +				{
   1.162 +					new len = strlen(finalOutput);
   1.163 +					if (len < sizeof(finalOutput))
   1.164 +					{
   1.165 +						FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "FragLimitAppend", client, fraglimit, (fraglimit == 1)? "":"s");
   1.166 +					}	
   1.167 +				}
   1.168 +				else
   1.169 +				{
   1.170 +					FormatEx(finalOutput, sizeof(finalOutput), "%T", "FragLimit", client, fraglimit, (fraglimit == 1)? "":"s");
   1.171 +					written = true;
   1.172 +				}			
   1.173 +			}
   1.174 +		}
   1.175 +		
   1.176 +		if (g_Cvar_MaxRounds != INVALID_HANDLE)
   1.177 +		{
   1.178 +			new maxrounds = GetConVarInt(g_Cvar_MaxRounds);
   1.179 +			
   1.180 +			if (maxrounds > 0)
   1.181 +			{
   1.182 +				if (written)
   1.183 +				{
   1.184 +					new len = strlen(finalOutput);
   1.185 +					if (len < sizeof(finalOutput))
   1.186 +					{
   1.187 +						FormatEx(finalOutput[len], sizeof(finalOutput)-len, "%T", "MaxRoundsAppend", client, maxrounds, (maxrounds == 1)? "":"s");
   1.188 +					}
   1.189 +				}
   1.190 +				else
   1.191 +				{
   1.192 +					FormatEx(finalOutput, sizeof(finalOutput), "%T", "MaxRounds", client, maxrounds, (maxrounds == 1)? "":"s");
   1.193 +					written = true;
   1.194 +				}			
   1.195 +			}		
   1.196 +		}
   1.197 +	}
   1.198 +	
   1.199 +	if (lastround)
   1.200 +	{
   1.201 +		FormatEx(finalOutput, sizeof(finalOutput), "%T", "LastRound", client);
   1.202 +	}
   1.203 +	else if (notimelimit && !written)
   1.204 +	{
   1.205 +		FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
   1.206 +	}
   1.207 +
   1.208 +	if(GetConVarInt(g_Cvar_TriggerShow) || all)
   1.209 +	{
   1.210 +		PrintToChatAll("[SM] %s", finalOutput);
   1.211 +	}
   1.212 +	else if (client != 0)
   1.213 +	{
   1.214 +		PrintToChat(client, "[SM] %s", finalOutput);
   1.215 +	}
   1.216 +	
   1.217 +	if (client == 0)
   1.218 +	{
   1.219 +		PrintToServer("[SM] %s", finalOutput);
   1.220 +	}
   1.221  }
   1.222 \ No newline at end of file
     2.1 --- a/plugins/nextmap.sp	Sun May 25 20:50:11 2008 +0000
     2.2 +++ b/plugins/nextmap.sp	Mon May 26 01:09:10 2008 +0000
     2.3 @@ -61,10 +61,7 @@
     2.4  	RegConsoleCmd("say", Command_Say);
     2.5  	RegConsoleCmd("say_team", Command_Say);
     2.6  	
     2.7 -	if (GetCommandFlags("nextmap") == INVALID_FCVAR_FLAGS)
     2.8 -	{
     2.9 -		RegServerCmd("nextmap", Command_Nextmap);
    2.10 -	}
    2.11 +	RegConsoleCmd("nextmap", Command_Nextmap);
    2.12  
    2.13  	RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
    2.14  	RegConsoleCmd("listmaps", Command_List);
    2.15 @@ -113,7 +110,7 @@
    2.16  		decl String:map[32];
    2.17  		GetNextMap(map, sizeof(map));
    2.18  		
    2.19 -		PrintToChat(client, "%t", "Next Map", map);
    2.20 +		PrintToChat(client, "[SM] %t", "Next Map", map);
    2.21  	}
    2.22  	
    2.23  	return Plugin_Continue;	
    2.24 @@ -159,13 +156,13 @@
    2.25  	return Plugin_Handled;
    2.26  }
    2.27   
    2.28 -public Action:Command_Nextmap(args)
    2.29 +public Action:Command_Nextmap(client, args)
    2.30  {
    2.31  	decl String:map[64];
    2.32  	
    2.33  	GetNextMap(map, sizeof(map));
    2.34  	
    2.35 -	ReplyToCommand(0, "%t", "Next Map", map);
    2.36 +	ReplyToCommand(client, "[SM] %t", "Next Map", map);
    2.37  	
    2.38  	return Plugin_Handled;
    2.39  }
     3.1 --- a/translations/basetriggers.phrases.txt	Sun May 25 20:50:11 2008 +0000
     3.2 +++ b/translations/basetriggers.phrases.txt	Mon May 26 01:09:10 2008 +0000
     3.3 @@ -26,4 +26,49 @@
     3.4  		"#format"	"{1:s}"
     3.5  		"en"		"The current map is {1}."
     3.6  	}
     3.7 +
     3.8 +	"WinLimitAppend"
     3.9 +	{
    3.10 +		"#format"	"{1:i},{2:s}"
    3.11 +		"en"		", or change map after a team wins {1} round{2}"
    3.12 +	}
    3.13 +
    3.14 +	"WinLimit"
    3.15 +	{
    3.16 +		"#format"	"{1:i},{2:s}"
    3.17 +		"en"		"Map will change after a team wins {1} round{2}"
    3.18 +	}
    3.19 +
    3.20 +	"MaxRoundsAppend"
    3.21 +	{
    3.22 +		"#format"	"{1:i},{2:s}"
    3.23 +		"en"		", or change map after {1} round{2}"
    3.24 +	}
    3.25 +
    3.26 +	"MaxRounds"
    3.27 +	{
    3.28 +		"#format"	"{1:i},{2:s}"
    3.29 +		"en"		"Map will change after {1} round{2}"
    3.30 +	}
    3.31 +
    3.32 +	"FragLimitAppend"
    3.33 +	{
    3.34 +		"#format"	"{1:i},{2:s}"
    3.35 +		"en"		", or change map after player reaches {1} frag{2}"
    3.36 +	}
    3.37 +	"FragLimit"
    3.38 +	{
    3.39 +		"#format"	"{1:i},{2:s}"
    3.40 +		"en"		"Map will change after a player reaches {1} frag{2}"
    3.41 +	}
    3.42 +
    3.43 +	"LastRound"
    3.44 +	{
    3.45 +		"en"		"This is the last round!!"
    3.46 +	}
    3.47 +
    3.48 +	"NoTimelimit"
    3.49 +	{
    3.50 +		"en"		"No timelimit for map"
    3.51 +	}
    3.52  }