#define MIN_PLAYERS_NUM 0
#define MAX_PLAYERS_NUM 31 // also try with 30 same... they not go out...
Код за потвърждение: Избери целия код
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define PLUGIN "Spectator Bots"
#define VERSION "1.0"
#define AUTHOR "hackera457"
// Edited by Huehue @ AMXX-BG.INFO
const MAX_PATH_LENGTH = 64
const ADMIN_ACCESS = ADMIN_BAN
new const g_szFolder[] = "SpectatorBots"
new const g_szFile[] = "Spectator_Bots.ini"
new g_iPlayers, g_iBots, g_iTotalBotNames
new g_pCvarMinPlayers, g_pCvarMaxPlayers
new g_pMinPlayers, g_pMaxPlayers
new Array:g_aBotData
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("hackera457_spectatorbots", VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
register_clcmd("amx_reload_specbots", "Command_ReloadSpecBotsFile", ADMIN_ACCESS, "* Reloads the file with the spec bots")
g_pCvarMinPlayers = register_cvar("sb_minimum_players", "0")
g_pCvarMaxPlayers = register_cvar("sb_maximum_players", "30")
hook_cvar_change(g_pCvarMinPlayers, "OnCvarChanged")
hook_cvar_change(g_pCvarMaxPlayers, "OnCvarChanged")
set_task(2.0, "Check_Bots")
}
public plugin_cfg()
{
g_aBotData = ArrayCreate(MAX_PLAYERS, 1)
new szDir[MAX_PATH_LENGTH], szFmtDir[MAX_PATH_LENGTH]
get_localinfo("amxx_configsdir", szDir, charsmax(szDir))
formatex(szFmtDir, charsmax(szFmtDir), "addons/amxmodx/configs/%s", g_szFolder)
if (!dir_exists(szFmtDir))
mkdir(szFmtDir)
ReadFile()
g_pMinPlayers = get_pcvar_num(g_pCvarMinPlayers)
g_pMaxPlayers = get_pcvar_num(g_pCvarMaxPlayers)
}
public ReadFile()
{
static szConfigsDir[MAX_PATH_LENGTH], iFile, szSpectatorBots[MAX_PATH_LENGTH]
get_configsdir(szConfigsDir, charsmax(szConfigsDir))
formatex(szSpectatorBots, charsmax(szSpectatorBots), "/%s/%s", g_szFolder, g_szFile)
add(szConfigsDir, charsmax(szConfigsDir), szSpectatorBots)
iFile = fopen(szConfigsDir, "rt")
if(!file_exists(szConfigsDir))
{
server_print("File (%s) not found, creating new one..", g_szFile)
new iFile = fopen(szConfigsDir, "wt")
if (iFile)
{
new szNewFile[512]
formatex(szNewFile, charsmax(szNewFile), "; Copyright AMXX-BG.INFO | Author: hackera457 | Major Edit by Huehue^nServer IP: xx.xxx.xx.xx:27015^nWebsite: http://www.amxx-bg.info/forum")
fputs(iFile, szNewFile)
}
fclose(iFile)
ReadFile()
return
}
new iLine
if (iFile)
{
static szSpecBotName[MAX_NAME_LENGTH]
while (!feof(iFile))
{
fgets(iFile, szSpecBotName, charsmax(szSpecBotName))
trim(szSpecBotName)
if (szSpecBotName[0] == EOS || szSpecBotName[0] == ';' || (szSpecBotName[0] == '/' && szSpecBotName[1] == '/'))
continue
ArrayPushString(g_aBotData, szSpecBotName)
iLine++
}
fclose(iFile)
}
g_iTotalBotNames = iLine
server_print("__________________________________________________^n");
server_print("> Loaded %i spectator bot names from file (%s)", g_iTotalBotNames, g_szFile)
server_print("__________________________________________________^n")
}
public Command_ReloadSpecBotsFile(id, level, cid)
{
if(!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
ArrayClear(g_aBotData)
RemoveBots()
set_task(1.0, "Check_Bots")
ReadFile()
return PLUGIN_HANDLED
}
public client_connect(id)
{
if(!is_user_bot(id))
g_iPlayers++
set_task(2.0, "Check_Bots")
}
public client_disconnected(id)
{
if(!is_user_bot(id))
g_iPlayers--
set_task(2.0, "Check_Bots")
}
public OnCvarChanged(pcvar, szOldValue[], szNewValue[])
{
if (pcvar == g_pCvarMinPlayers)
{
if (str_to_num(szOldValue) != str_to_num(szNewValue))
{
g_pMinPlayers = str_to_num(szNewValue)
}
}
else if (pcvar == g_pCvarMaxPlayers)
{
if (str_to_num(szOldValue) != str_to_num(szNewValue))
{
g_pMaxPlayers = str_to_num(szNewValue)
}
}
set_task(2.0, "Check_Bots")
}
public Check_Bots()
{
static i, szBotNames[MAX_NAME_LENGTH]
if (g_iPlayers >= g_pMaxPlayers)
{
RemoveBots()
return PLUGIN_CONTINUE
}
if (g_pMinPlayers <= g_iPlayers <= g_pMaxPlayers)
{
for (i = 0; i < g_iTotalBotNames; i++)
{
if (g_iBots == g_iTotalBotNames)
break
ArrayGetString(g_aBotData, i, szBotNames, charsmax(szBotNames))
CreateBots(szBotNames)
}
}
return PLUGIN_HANDLED
}
CreateBots(const szName[])
{
static szReason[128], id
id = engfunc(EngFunc_CreateFakeClient, szName)
engfunc(EngFunc_FreeEntPrivateData, id)
set_pev(id, pev_flags, pev(id, pev_flags) | FL_FAKECLIENT)
dllfunc(DLLFunc_ClientConnect, id, szName, "127.0.0.1", szReason)
dllfunc(DLLFunc_ClientPutInServer, id)
g_iBots++
}
RemoveBots()
{
static iPlayers[MAX_PLAYERS], iNum
get_players_ex(iPlayers, iNum, GetPlayers_ExcludeHuman)
for(--iNum; iNum >= 0; iNum--)
server_cmd("kick #%i", get_user_userid(iPlayers[iNum]))
g_iBots = 0
}
Потребители разглеждащи този форум: Bing [Bot], Semrush [Bot] и 13 госта