scripting/dm_bot_quotas.sp
changeset 13 3f35cdcf6955
child 19 4a79c2770e9e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripting/dm_bot_quotas.sp	Tue Jun 26 00:03:54 2007 +0000
     1.3 @@ -0,0 +1,97 @@
     1.4 +/**
     1.5 + * dm_bot_quotas.sp
     1.6 + * Adds bot quota correction to CS:S DM.
     1.7 + * This file is part of CS:S DM, Copyright (C) 2005-2007 AlliedModders LLC
     1.8 + * by David "BAILOPAN" Anderson, http://www.bailopan.net/cssdm/
     1.9 + *
    1.10 + * This program is free software; you can redistribute it and/or
    1.11 + * modify it under the terms of the GNU General Public License
    1.12 + * as published by the Free Software Foundation; either version 2
    1.13 + * of the License, or (at your option) any later version.
    1.14 + *
    1.15 + * This program is distributed in the hope that it will be useful,
    1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 + * GNU General Public License for more details.
    1.19 + * 
    1.20 + * You should have received a copy of the GNU General Public License
    1.21 + * along with this program; if not, write to the Free Software
    1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.23 + *
    1.24 + * Version: $Id$
    1.25 + */
    1.26 +
    1.27 +
    1.28 +#include <sourcemod>
    1.29 +
    1.30 +public Plugin:myinfo = 
    1.31 +{
    1.32 +	name = "CS:S DM Bot Quotas",
    1.33 +	author = "BAILOPAN",
    1.34 +	description = "Bot Quota Correction for CS:S DM",
    1.35 +	version = "2.0.0.0",
    1.36 +	url = "http://www.bailopan.net/cssdm/"
    1.37 +}
    1.38 +
    1.39 +/* CS:S ConVars */
    1.40 +new Handle:BotQuota = INVALID_HANDLE
    1.41 +
    1.42 +/* Our ConVars */
    1.43 +new Handle:BalanceAmt = INVALID_HANDLE
    1.44 +
    1.45 +public OnPluginStart()
    1.46 +{
    1.47 +	/* Find CS:S ConVars */
    1.48 +	BotQuota = FindConVar("bot_quota")
    1.49 +	
    1.50 +	/* Create our ConVars */
    1.51 +	BalanceAmt = CreateConVar("cssdm_bots_balance", "0", "Minimum number of players (bot_quota)")
    1.52 +	HookConVarChange(BalanceAmt, OnBalanceChange)
    1.53 +}
    1.54 +
    1.55 +public OnBalanceChange(Handle:convar, const String:oldval[], const String:newval[])
    1.56 +{
    1.57 +	BalanceBots(StringToInt(newval))
    1.58 +}
    1.59 +
    1.60 +BalanceBots(quota)
    1.61 +{
    1.62 +	new maxClients = GetMaxClients()
    1.63 +	new humans, bots
    1.64 +	
    1.65 +	/* Get the number of valid humans and bots */
    1.66 +	for (new i=1; i<=maxClients; i++)
    1.67 +	{
    1.68 +		if (!IsPlayerInGame(i))
    1.69 +		{
    1.70 +			continue
    1.71 +		}
    1.72 +		if (!IsFakeClient(i))
    1.73 +		{
    1.74 +			humans++
    1.75 +		} else {
    1.76 +			bots++
    1.77 +		}
    1.78 +	}
    1.79 +	
    1.80 +	/* Get the number of bots needed to fill quota */
    1.81 +	if (quota < humans)
    1.82 +	{
    1.83 +		quota = 0
    1.84 +	} else {
    1.85 +		quota -= humans
    1.86 +	}
    1.87 +	
    1.88 +	/* Now, set the new value */
    1.89 +	SetConVarInt(BotQuota, quota)
    1.90 +}
    1.91 +
    1.92 +public OnClientPutInServer(client)
    1.93 +{
    1.94 +	BalanceBots(GetConVarInt(BalanceAmt))
    1.95 +}
    1.96 +
    1.97 +public OnClientDisconnect_Post(client)
    1.98 +{
    1.99 +	BalanceBots(GetConVarInt(BalanceAmt))
   1.100 +}