Junior Member
|
05-06-2023
, 10:55
Modify "Spectator Bots" Plugin
|
#1
|
Hello,I have a spectator bot plugin which adds 2 bots on the spectator team to advertise the ip and forum,the plugin works perfectly but on gametracker the bots appear like real players,it is possible to modify the code for gametracker to detect the bots as "Bots" instead of "Players"? ,thank you
Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#define PLUGIN "Spectator Bots"
#define VERSION "1.0"
#define AUTHOR "hackera457"
const MAX_PATH_LENGTH = 64
const ADMIN_ACCESS = ADMIN_LEVEL_B
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("spectator_bots", 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("specbot_minimum_players", "0")
g_pCvarMaxPlayers = register_cvar("specbot_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), "")
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)
}
}
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)
cs_set_user_team(id, CS_TEAM_SPECTATOR);
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
}
|
|