Fix Spectator bots

В този раздел можете да подавате всякакви заявки за намиране, изработка или преработка на плъгини/модове.
Аватар
Igivapto
Извън линия
Foreigner
Foreigner
Мнения: 36
Регистриран на: 08 Май 2020, 14:52
Се отблагодари: 13 пъти
Получена благодарност: 1 път

Fix Spectator bots

Мнение от Igivapto » 10 Юни 2021, 00:45

Huehue написа:
09 Юни 2021, 18:04
Igivapto написа:
09 Юни 2021, 13:15
@Huehue Am not using any bots simply server go 32/32 and bots not go out...
@m0ney, hes talking about bots from hackera that there is not cvar like it.
Can you make a snapshot from your console when the server is 31 or 32 with the command written in console status or ping and attach/upload it here. So I can see why the plugin doesn't work for you. Thanks in advance.
Изображение

#define MIN_PLAYERS_NUM 0
#define MAX_PLAYERS_NUM 31 // also try with 30 same... they not go out...

Аватар
Huehue
Извън линия
Модератор
Модератор
Мнения: 263
Регистриран на: 16 Яну 2017, 23:42
Местоположение: София
Се отблагодари: 7 пъти
Получена благодарност: 79 пъти
Обратна връзка:

Fix Spectator bots

Мнение от Huehue » 12 Юни 2021, 10:57

Try with this one..

Cvars to setup:
sb_minimum_players - 0 (Default)
sb_maximum_players - 30 (Default)

After First load of the plugin a folder will appear in your configs folder called SpectatorBots. Inside it there is a file named Spectator_Bots.ini you can add there the bots you want.

Additional:
amx_reload_specbots - Reloads the Spectator_Bots.ini file

To change when bots should leave the server, doesn't require server restart or map change. The action happens when cvar is changed.

Код за потвърждение: Избери целия код

#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
}
LOYAL TO THE OATH OF OMERTА̀

Зад монитора мъжкари, това не го разбирам..
На живо сте мишкари, това го гарантирам!
Седиш на 30 метра от мен като препариран!
Ако има нещо брат, номерът ми е блокиран..

Публикувай отговор
  • Подобни теми
    Отговори
    Преглеждания
     Последно мнение

Обратно към “Заявки за плъгини”

Кой е на линия

Потребители разглеждащи този форум: Bing [Bot] и 4 госта