plugins/mapmanager/events.sp
author Michael McKoy <ferret99gt@gmail.com>
Wed Dec 19 22:19:34 2007 +0000 (2007-12-19)
branchsourcemod-1.1.0
changeset 1807 a0de5251fb1a
child 1947 e73a1e51833b
permissions -rw-r--r--
Don't even bother trying to compile these, it's not finished. Just committing for archiving purposes, this is not intended for 1.0 release.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Map Manager Plugin
     5  * Contains event callbacks
     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 public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
    35 {
    36 	if (g_IntermissionCalled)
    37 	{
    38 		return Plugin_Handled;
    39 	}
    40 	
    41 	decl String:type[15];
    42 
    43 	/* If we don't get a valid string, bail out. */
    44 	if (BfReadString(bf, type, sizeof(type)) < 0)
    45 	{
    46 		return Plugin_Handled;
    47 	}
    48  
    49 	if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
    50 	{
    51 		g_IntermissionCalled = true;
    52 		
    53 		decl String:map[32];
    54 		new Float:fChatTime = GetConVarFloat(g_Cvar_Chattime);
    55 		
    56 		if (fChatTime < 2.0)
    57 		{
    58 			SetConVarFloat(g_Cvar_Chattime, 2.0);
    59 		}
    60 		
    61 		LogMessage("[MapManager] Changing map to '%s' due to map ending.", g_NextMap);
    62 		
    63 		g_MapChanged = true;
    64 		CreateTimer(fChatTime - 1.0, Timer_ChangeMap);		
    65 	}
    66 	
    67 	return Plugin_Handled;
    68 }
    69 
    70 public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
    71 {
    72 	if (g_MapChanged)
    73 	{
    74 		return;
    75 	}
    76 	
    77 	if (g_MapChangeSet && g_MapChangeWhen == 'r')
    78 	{
    79 		LogMessage("[MapManager] Changing map to '%s' due to round ending.", g_NextMap);
    80 		
    81 		g_MapChanged = true;
    82 		CreateTimer(1.0, Timer_ChangeMap);
    83 		
    84 		return;
    85 	}
    86 	
    87 	if (g_HasVoteStarted)
    88 	{
    89 		return;
    90 	}
    91 
    92 	new winner = GetEventInt(event, "winner");
    93 	
    94 	if (winner == 0 || winner == 1)
    95 	{
    96 		return;
    97 	}
    98 
    99 	g_TotalRounds++;
   100 	
   101 	new team[2], teamPos = -1;
   102 	for (new i; i < GetArraySize(g_TeamScores); i++)
   103 	{
   104 		GetArrayArray(g_TeamScores, i, team);
   105 		if (team[0] == winner)
   106 		{
   107 			teamPos = i;
   108 			break;
   109 		}		
   110 	}
   111 	
   112 	if (teamPos == -1)
   113 	{
   114 		team[0] = winner;
   115 		team[1] = 1;
   116 		PushArrayArray(g_TeamScores, team);
   117 	}
   118 	else
   119 	{
   120 		team[1]++;
   121 		SetArrayArray(g_TeamScores, teamPos, team);
   122 	}	
   123 	
   124 	if (g_Cvar_Winlimit != INVALID_HANDLE)
   125 	{
   126 		new winlimit = GetConVarInt(g_Cvar_Winlimit);
   127 		if (winlimit)
   128 		{
   129 			if (team[1] >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
   130 			{
   131 				InitiateVote();
   132 			}
   133 		}
   134 	}
   135 	
   136 	if (g_Cvar_Maxrounds != INVALID_HANDLE)
   137 	{
   138 		new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
   139 		if (maxrounds)
   140 		{
   141 			if (g_TotalRounds >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
   142 			{
   143 				InitiateVote();
   144 			}			
   145 		}
   146 	}
   147 }
   148 
   149 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   150 {
   151 	if (g_MapChanged || g_HasVoteStarted || g_Cvar_Fraglimit == INVALID_HANDLE)
   152 	{
   153 		return;
   154 	}
   155 	
   156 	if (!GetConVarInt(g_Cvar_Fraglimit))
   157 	{
   158 		return;
   159 	}
   160 
   161 	new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
   162 	if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
   163 	{
   164 		InitiateVote();
   165 	}
   166 }