plugins/mapmanager/events.sp
changeset 1952 b7aa2b626807
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/mapmanager/events.sp	Sun Mar 30 07:00:22 2008 +0000
     1.3 @@ -0,0 +1,166 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Map Manager Plugin
     1.8 + * Contains event callbacks
     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 +public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
    1.38 +{
    1.39 +	if (g_IntermissionCalled)
    1.40 +	{
    1.41 +		return Plugin_Handled;
    1.42 +	}
    1.43 +	
    1.44 +	decl String:type[15];
    1.45 +
    1.46 +	/* If we don't get a valid string, bail out. */
    1.47 +	if (BfReadString(bf, type, sizeof(type)) < 0)
    1.48 +	{
    1.49 +		return Plugin_Handled;
    1.50 +	}
    1.51 + 
    1.52 +	if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
    1.53 +	{
    1.54 +		g_IntermissionCalled = true;
    1.55 +		
    1.56 +		decl String:map[32];
    1.57 +		new Float:fChatTime = GetConVarFloat(g_Cvar_Chattime);
    1.58 +		
    1.59 +		if (fChatTime < 2.0)
    1.60 +		{
    1.61 +			SetConVarFloat(g_Cvar_Chattime, 2.0);
    1.62 +		}
    1.63 +		
    1.64 +		LogMessage("[MapManager] Changing map to '%s' due to map ending.", g_NextMap);
    1.65 +		
    1.66 +		g_MapChanged = true;
    1.67 +		CreateTimer(fChatTime - 1.0, Timer_ChangeMap);		
    1.68 +	}
    1.69 +	
    1.70 +	return Plugin_Handled;
    1.71 +}
    1.72 +
    1.73 +public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
    1.74 +{
    1.75 +	if (g_MapChanged)
    1.76 +	{
    1.77 +		return;
    1.78 +	}
    1.79 +	
    1.80 +	if (g_MapChangeSet && g_MapChangeWhen == 'r')
    1.81 +	{
    1.82 +		LogMessage("[MapManager] Changing map to '%s' due to round ending.", g_NextMap);
    1.83 +		
    1.84 +		g_MapChanged = true;
    1.85 +		CreateTimer(1.0, Timer_ChangeMap);
    1.86 +		
    1.87 +		return;
    1.88 +	}
    1.89 +	
    1.90 +	if (g_HasVoteStarted)
    1.91 +	{
    1.92 +		return;
    1.93 +	}
    1.94 +
    1.95 +	new winner = GetEventInt(event, "winner");
    1.96 +	
    1.97 +	if (winner == 0 || winner == 1)
    1.98 +	{
    1.99 +		return;
   1.100 +	}
   1.101 +
   1.102 +	g_TotalRounds++;
   1.103 +	
   1.104 +	new team[2], teamPos = -1;
   1.105 +	for (new i; i < GetArraySize(g_TeamScores); i++)
   1.106 +	{
   1.107 +		GetArrayArray(g_TeamScores, i, team);
   1.108 +		if (team[0] == winner)
   1.109 +		{
   1.110 +			teamPos = i;
   1.111 +			break;
   1.112 +		}		
   1.113 +	}
   1.114 +	
   1.115 +	if (teamPos == -1)
   1.116 +	{
   1.117 +		team[0] = winner;
   1.118 +		team[1] = 1;
   1.119 +		PushArrayArray(g_TeamScores, team);
   1.120 +	}
   1.121 +	else
   1.122 +	{
   1.123 +		team[1]++;
   1.124 +		SetArrayArray(g_TeamScores, teamPos, team);
   1.125 +	}	
   1.126 +	
   1.127 +	if (g_Cvar_Winlimit != INVALID_HANDLE)
   1.128 +	{
   1.129 +		new winlimit = GetConVarInt(g_Cvar_Winlimit);
   1.130 +		if (winlimit)
   1.131 +		{
   1.132 +			if (team[1] >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
   1.133 +			{
   1.134 +				InitiateVote();
   1.135 +			}
   1.136 +		}
   1.137 +	}
   1.138 +	
   1.139 +	if (g_Cvar_Maxrounds != INVALID_HANDLE)
   1.140 +	{
   1.141 +		new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
   1.142 +		if (maxrounds)
   1.143 +		{
   1.144 +			if (g_TotalRounds >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
   1.145 +			{
   1.146 +				InitiateVote();
   1.147 +			}			
   1.148 +		}
   1.149 +	}
   1.150 +}
   1.151 +
   1.152 +public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   1.153 +{
   1.154 +	if (g_MapChanged || g_HasVoteStarted || g_Cvar_Fraglimit == INVALID_HANDLE)
   1.155 +	{
   1.156 +		return;
   1.157 +	}
   1.158 +	
   1.159 +	if (!GetConVarInt(g_Cvar_Fraglimit))
   1.160 +	{
   1.161 +		return;
   1.162 +	}
   1.163 +
   1.164 +	new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
   1.165 +	if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
   1.166 +	{
   1.167 +		InitiateVote();
   1.168 +	}
   1.169 +}
   1.170 \ No newline at end of file