scripting/dm_bot_quotas.sp
author David Anderson <dvander@alliedmods.net>
Wed Jul 25 04:15:38 2007 +0000 (2007-07-25)
changeset 26 18856020dff3
parent 19 4a79c2770e9e
child 36 369d95743d20
permissions -rw-r--r--
fixed a bug where you could get infinite ammo when dm was disabled
     1 /**
     2  * dm_bot_quotas.sp
     3  * Adds bot quota correction to CS:S DM.
     4  * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
     5  * by David "BAILOPAN" Anderson, http://www.bailopan.net/cssdm/
     6  *
     7  * This program is free software; you can redistribute it and/or
     8  * modify it under the terms of the GNU General Public License
     9  * as published by the Free Software Foundation; either version 2
    10  * of the License, or (at your option) any later version.
    11  *
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  * 
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program; if not, write to the Free Software
    19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20  *
    21  * Version: $Id$
    22  */
    23 
    24 
    25 #include <sourcemod>
    26 #include <cssdm>
    27 
    28 public Plugin:myinfo = 
    29 {
    30 	name = "CS:S DM Bot Quotas",
    31 	author = "BAILOPAN",
    32 	description = "Bot Quota Correction for CS:S DM",
    33 	version = CSSDM_VERSION,
    34 	url = "http://www.bailopan.net/cssdm/"
    35 }
    36 
    37 /* CS:S ConVars */
    38 new Handle:BotQuota = INVALID_HANDLE
    39 
    40 /* Our ConVars */
    41 new Handle:BalanceAmt = INVALID_HANDLE
    42 
    43 public OnPluginStart()
    44 {
    45 	/* Find CS:S ConVars */
    46 	BotQuota = FindConVar("bot_quota")
    47 	
    48 	/* Create our ConVars */
    49 	BalanceAmt = CreateConVar("cssdm_bots_balance", "0", "Minimum number of players (bot_quota)")
    50 	HookConVarChange(BalanceAmt, OnBalanceChange)
    51 }
    52 
    53 public OnMapStart()
    54 {
    55 	BalanceBots(GetConVarInt(BalanceAmt));
    56 }
    57 
    58 public OnBalanceChange(Handle:convar, const String:oldval[], const String:newval[])
    59 {
    60 	BalanceBots(StringToInt(newval))
    61 }
    62 
    63 BalanceBots(quota)
    64 {
    65 	new maxClients = GetMaxClients()
    66 	new humans, bots
    67 	
    68 	/* Get the number of valid humans and bots */
    69 	for (new i=1; i<=maxClients; i++)
    70 	{
    71 		if (!IsPlayerInGame(i))
    72 		{
    73 			continue
    74 		}
    75 		if (!IsFakeClient(i))
    76 		{
    77 			humans++
    78 		} else {
    79 			bots++
    80 		}
    81 	}
    82 	
    83 	/* Get the number of bots needed to fill quota */
    84 	if (quota < humans)
    85 	{
    86 		quota = 0
    87 	} else {
    88 		quota -= humans
    89 	}
    90 	
    91 	/* Now, set the new value */
    92 	SetConVarInt(BotQuota, quota)
    93 }
    94 
    95 public OnClientPutInServer(client)
    96 {
    97 	BalanceBots(GetConVarInt(BalanceAmt))
    98 }
    99 
   100 public OnClientDisconnect_Post(client)
   101 {
   102 	BalanceBots(GetConVarInt(BalanceAmt))
   103 }