View Single Post
Code of my plugin:
Old
  (#5)
GordonInc
Member
 
Status: Offline
Posts: 7
Join Date: Mar 2005
Default Code of my plugin: - 31-03-2005

#include <amxmod>

/* balance numbers */
new autoteamnum = 5
new arePeople = -1

/* balance adjust */
public balance_adjust() {
// if we don't want to check bots at all
if (!get_cvar_num ("boty")) return 0

new ctplayers[32], tplayers[32], realplayers[32], aliveplayers[32], spectators[32]
new ctnum, tnum, dnum, realnum, alivenum, alivepeoplenum, spectatorsnum, i
get_players(ctplayers,ctnum,"e","CT")
get_players(tplayers,tnum,"e","TERRORIST")
get_players(spectators, spectatorsnum, "e", "SPECTATOR")
get_players(aliveplayers, alivenum, "a")
get_players (realplayers, realnum, "c")
alivepeoplenum = alivenum
for (i = 0; i < alivenum; i++)
if (is_user_bot (aliveplayers [i])) alivepeoplenum--

server_print ("[AutoBotKiller] Number of players: %d", get_playersnum ())
server_print ("[AutoBotKiller] REAL PLAYERS: %d", realnum)
server_print ("[AutoBotKiller] SPECTATORS: %d", spectatorsnum)
server_print ("[AutoBotKiller] ALIVE PEOPLE: %d", alivepeoplenum)
server_print ("[AutoBotKiller] CT's: %d", ctnum)
server_print ("[AutoBotKiller] T's: %d", tnum)

// turn bots off if no people are on the server
if (realnum && (arePeople == -1)) arePeople = 0
if (!realnum && (arePeople == -1)) arePeople = 1
if (!realnum && arePeople) {
arePeople = 0
server_cmd ("bot_kick all")
return 0 // no other operations are required
}
if (realnum && !arePeople) arePeople = 1

/* killing bots, when all players are down */
if (get_cvar_num ("kill_bots") && (realnum - spectatorsnum > 0)
&& !alivepeoplenum) {
server_print ("[AutoBotKiller] Killing bots due to waiting players...")
server_cmd ("bot_kill all")
}

/* kicking bots... */
if (ctnum > autoteamnum) {
dnum = ctnum - autoteamnum
for(new a = 0; a < ctnum; a++) {
if (is_user_bot(ctplayers[a])) {
new id = get_user_userid(ctplayers[a])
new quota = get_cvar_num ("bot_quota")
set_cvar_num ("bot_quota", quota-1)
server_print("[AutoBotKiller] kick a CT bot user %d to balance", id)
server_cmd("kick #%d", id)
dnum--
}
if (dnum == 0) break
}
}

if (tnum > autoteamnum) {
dnum = tnum - autoteamnum
for(new a = 0; a < tnum; a++) {
if (is_user_bot(tplayers[a])) {
new id = get_user_userid(tplayers[a])
new quota = get_cvar_num ("bot_quota")
set_cvar_num ("bot_quota", quota-1)
server_print("[AutoBotKiller] kick a T bot user %d to balance", id)
server_cmd("kick #%d", id)
dnum--
}

if (dnum == 0) break
}
}

/* adding bots */
if (realnum && ((ctnum < autoteamnum) || (tnum < autoteamnum))) {
new howmuch = 2*autoteamnum - ctnum - tnum
server_print("[AutoBotKiller] adding %d bots to balance...", howmuch)
new switchvar
if (ctnum < tnum) switchvar = 0 // first add to CT
else switchvar = 1 // otherwise to T
for (new a = 0; a < howmuch; a++) {
if (switchvar) {
server_print ("[AutoBotKiller] add a T bot to balance")
server_cmd ("bot_add_t")
}
else {
server_print ("[AutoBotKiller] add a CT bot to balance")
server_cmd ("bot_add_ct")
}
switchvar = 1 - switchvar
}
}

return PLUGIN_HANDLED
}

public plugin_init() {
register_plugin("AutoBotsBalance","0.0.1","default ")
register_cvar ("kill_bots", "1", FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_UNLOGGED | FCVAR_SPONLY)
register_cvar ("boty", "1", FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_UNLOGGED | FCVAR_SPONLY)

set_task(10.0, "balance_adjust", 0, "", 0, "b")

return PLUGIN_CONTINUE
}