scripting/dm_bot_quotas.sp
author David Anderson <dvander@alliedmods.net>
Tue Jun 26 19:48:41 2007 +0000 (2007-06-26)
changeset 16 70bb5195e8f2
parent 13 3f35cdcf6955
child 19 4a79c2770e9e
permissions -rw-r--r--
bumped versions
     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 
    27 public Plugin:myinfo = 
    28 {
    29 	name = "CS:S DM Bot Quotas",
    30 	author = "BAILOPAN",
    31 	description = "Bot Quota Correction for CS:S DM",
    32 	version = "2.0.0.0",
    33 	url = "http://www.bailopan.net/cssdm/"
    34 }
    35 
    36 /* CS:S ConVars */
    37 new Handle:BotQuota = INVALID_HANDLE
    38 
    39 /* Our ConVars */
    40 new Handle:BalanceAmt = INVALID_HANDLE
    41 
    42 public OnPluginStart()
    43 {
    44 	/* Find CS:S ConVars */
    45 	BotQuota = FindConVar("bot_quota")
    46 	
    47 	/* Create our ConVars */
    48 	BalanceAmt = CreateConVar("cssdm_bots_balance", "0", "Minimum number of players (bot_quota)")
    49 	HookConVarChange(BalanceAmt, OnBalanceChange)
    50 }
    51 
    52 public OnBalanceChange(Handle:convar, const String:oldval[], const String:newval[])
    53 {
    54 	BalanceBots(StringToInt(newval))
    55 }
    56 
    57 BalanceBots(quota)
    58 {
    59 	new maxClients = GetMaxClients()
    60 	new humans, bots
    61 	
    62 	/* Get the number of valid humans and bots */
    63 	for (new i=1; i<=maxClients; i++)
    64 	{
    65 		if (!IsPlayerInGame(i))
    66 		{
    67 			continue
    68 		}
    69 		if (!IsFakeClient(i))
    70 		{
    71 			humans++
    72 		} else {
    73 			bots++
    74 		}
    75 	}
    76 	
    77 	/* Get the number of bots needed to fill quota */
    78 	if (quota < humans)
    79 	{
    80 		quota = 0
    81 	} else {
    82 		quota -= humans
    83 	}
    84 	
    85 	/* Now, set the new value */
    86 	SetConVarInt(BotQuota, quota)
    87 }
    88 
    89 public OnClientPutInServer(client)
    90 {
    91 	BalanceBots(GetConVarInt(BalanceAmt))
    92 }
    93 
    94 public OnClientDisconnect_Post(client)
    95 {
    96 	BalanceBots(GetConVarInt(BalanceAmt))
    97 }