plugins/mapmanager/events.sp
author David Anderson <dvander@alliedmods.net>
Sat May 17 05:12:52 2008 +0000 (2008-05-17)
changeset 2056 f1fcde46ac7c
parent 1952 b7aa2b626807
permissions -rw-r--r--
added amb1119 - sm_revote command
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Map Manager Plugin
ds@1952
     5
 * Contains event callbacks
ds@1952
     6
 *
ds@1952
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     8
 * =============================================================================
ds@1952
     9
 *
ds@1952
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    12
 * Free Software Foundation.
ds@1952
    13
 * 
ds@1952
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    17
 * details.
ds@1952
    18
 *
ds@1952
    19
 * You should have received a copy of the GNU General Public License along with
ds@1952
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    21
 *
ds@1952
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    29
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    30
 *
ds@1952
    31
 * Version: $Id$
ds@1952
    32
 */
ds@1952
    33
ds@1952
    34
public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
ds@1952
    35
{
ds@1952
    36
	if (g_IntermissionCalled)
ds@1952
    37
	{
ds@1952
    38
		return Plugin_Handled;
ds@1952
    39
	}
ds@1952
    40
	
ds@1952
    41
	decl String:type[15];
ds@1952
    42
ds@1952
    43
	/* If we don't get a valid string, bail out. */
ds@1952
    44
	if (BfReadString(bf, type, sizeof(type)) < 0)
ds@1952
    45
	{
ds@1952
    46
		return Plugin_Handled;
ds@1952
    47
	}
ds@1952
    48
 
ds@1952
    49
	if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
ds@1952
    50
	{
ds@1952
    51
		g_IntermissionCalled = true;
ds@1952
    52
		
ds@1952
    53
		decl String:map[32];
ds@1952
    54
		new Float:fChatTime = GetConVarFloat(g_Cvar_Chattime);
ds@1952
    55
		
ds@1952
    56
		if (fChatTime < 2.0)
ds@1952
    57
		{
ds@1952
    58
			SetConVarFloat(g_Cvar_Chattime, 2.0);
ds@1952
    59
		}
ds@1952
    60
		
ds@1952
    61
		LogMessage("[MapManager] Changing map to '%s' due to map ending.", g_NextMap);
ds@1952
    62
		
ds@1952
    63
		g_MapChanged = true;
ds@1952
    64
		CreateTimer(fChatTime - 1.0, Timer_ChangeMap);		
ds@1952
    65
	}
ds@1952
    66
	
ds@1952
    67
	return Plugin_Handled;
ds@1952
    68
}
ds@1952
    69
ds@1952
    70
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
    71
{
ds@1952
    72
	if (g_MapChanged)
ds@1952
    73
	{
ds@1952
    74
		return;
ds@1952
    75
	}
ds@1952
    76
	
ds@1952
    77
	if (g_MapChangeSet && g_MapChangeWhen == 'r')
ds@1952
    78
	{
ds@1952
    79
		LogMessage("[MapManager] Changing map to '%s' due to round ending.", g_NextMap);
ds@1952
    80
		
ds@1952
    81
		g_MapChanged = true;
ds@1952
    82
		CreateTimer(1.0, Timer_ChangeMap);
ds@1952
    83
		
ds@1952
    84
		return;
ds@1952
    85
	}
ds@1952
    86
	
ds@1952
    87
	if (g_HasVoteStarted)
ds@1952
    88
	{
ds@1952
    89
		return;
ds@1952
    90
	}
ds@1952
    91
ds@1952
    92
	new winner = GetEventInt(event, "winner");
ds@1952
    93
	
ds@1952
    94
	if (winner == 0 || winner == 1)
ds@1952
    95
	{
ds@1952
    96
		return;
ds@1952
    97
	}
ds@1952
    98
ds@1952
    99
	g_TotalRounds++;
ds@1952
   100
	
ds@1952
   101
	new team[2], teamPos = -1;
ds@1952
   102
	for (new i; i < GetArraySize(g_TeamScores); i++)
ds@1952
   103
	{
ds@1952
   104
		GetArrayArray(g_TeamScores, i, team);
ds@1952
   105
		if (team[0] == winner)
ds@1952
   106
		{
ds@1952
   107
			teamPos = i;
ds@1952
   108
			break;
ds@1952
   109
		}		
ds@1952
   110
	}
ds@1952
   111
	
ds@1952
   112
	if (teamPos == -1)
ds@1952
   113
	{
ds@1952
   114
		team[0] = winner;
ds@1952
   115
		team[1] = 1;
ds@1952
   116
		PushArrayArray(g_TeamScores, team);
ds@1952
   117
	}
ds@1952
   118
	else
ds@1952
   119
	{
ds@1952
   120
		team[1]++;
ds@1952
   121
		SetArrayArray(g_TeamScores, teamPos, team);
ds@1952
   122
	}	
ds@1952
   123
	
ds@1952
   124
	if (g_Cvar_Winlimit != INVALID_HANDLE)
ds@1952
   125
	{
ds@1952
   126
		new winlimit = GetConVarInt(g_Cvar_Winlimit);
ds@1952
   127
		if (winlimit)
ds@1952
   128
		{
ds@1952
   129
			if (team[1] >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   130
			{
ds@1952
   131
				InitiateVote();
ds@1952
   132
			}
ds@1952
   133
		}
ds@1952
   134
	}
ds@1952
   135
	
ds@1952
   136
	if (g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   137
	{
ds@1952
   138
		new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
ds@1952
   139
		if (maxrounds)
ds@1952
   140
		{
ds@1952
   141
			if (g_TotalRounds >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   142
			{
ds@1952
   143
				InitiateVote();
ds@1952
   144
			}			
ds@1952
   145
		}
ds@1952
   146
	}
ds@1952
   147
}
ds@1952
   148
ds@1952
   149
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   150
{
ds@1952
   151
	if (g_MapChanged || g_HasVoteStarted || g_Cvar_Fraglimit == INVALID_HANDLE)
ds@1952
   152
	{
ds@1952
   153
		return;
ds@1952
   154
	}
ds@1952
   155
	
ds@1952
   156
	if (!GetConVarInt(g_Cvar_Fraglimit))
ds@1952
   157
	{
ds@1952
   158
		return;
ds@1952
   159
	}
ds@1952
   160
ds@1952
   161
	new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
ds@1952
   162
	if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
ds@1952
   163
	{
ds@1952
   164
		InitiateVote();
ds@1952
   165
	}
ds@1952
   166
}