scripting/dm_bot_quotas.sp
author Ruben Gonzalez <drifter01620@gmail.com>
Fri Mar 22 14:59:00 2013 -0400 (2013-03-22)
changeset 139 df5cbb604269
parent 43 6793d77652a4
permissions -rw-r--r--
Update code to use SourceHooks function.
     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 = "AlliedModders LLC",
    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 	if (!quota)
    66 	{
    67 		return;
    68 	}
    69 	
    70 	new maxClients = GetMaxClients()
    71 	new humans, bots
    72 	
    73 	/* Get the number of valid humans and bots */
    74 	for (new i=1; i<=maxClients; i++)
    75 	{
    76 		if (!IsClientInGame(i))
    77 		{
    78 			continue
    79 		}
    80 		if (!IsFakeClient(i))
    81 		{
    82 			humans++
    83 		} else {
    84 			bots++
    85 		}
    86 	}
    87 	
    88 	/* Get the number of bots needed to fill quota */
    89 	if (quota < humans)
    90 	{
    91 		quota = 0
    92 	} else {
    93 		quota -= humans
    94 	}
    95 	
    96 	/* Now, set the new value */
    97 	SetConVarInt(BotQuota, quota)
    98 }
    99 
   100 public OnClientPutInServer(client)
   101 {
   102 	BalanceBots(GetConVarInt(BalanceAmt))
   103 }
   104 
   105 public OnClientDisconnect_Post(client)
   106 {
   107 	BalanceBots(GetConVarInt(BalanceAmt))
   108 }