Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent bots from leaving game when killing a player? #122

Open
LuckyLuke9542 opened this issue Jan 5, 2024 · 1 comment
Open

Comments

@LuckyLuke9542
Copy link

Bots will leave when a human player dies. I'm wondering how to prevent that from happening.
Tried setting ZombiesPerPlayerMax to a higher value but no luck.

@Dadido3
Copy link
Owner

Dadido3 commented Jan 5, 2024

The addon tries to keep the number of bots in such a way that there is a desired number of players per team. And the desired count is defined by this function:

function D3bot.GetDesiredBotCount()
local wave = math.max(1, GAMEMODE:GetWave())
local minutes = (CurTime() - roundStartTime) / 60
local allowedTotal = game.MaxPlayers() - 2
local allowedBots = allowedTotal - #player.GetHumans()
local mapParams = D3bot.MapNavMesh.Params
local zombieFormula = ((mapParams.ZPP or D3bot.ZombiesPerPlayer) + (mapParams.ZPPW or D3bot.ZombiesPerPlayerWave) * wave) * #player.GetHumans() + (mapParams.ZPM or D3bot.ZombiesPerMinute) * minutes + (mapParams.ZPW or D3bot.ZombiesPerWave) * wave
local zombiesCount = math.Clamp(
math.ceil(math.min(zombieFormula, (mapParams.ZPPM or D3bot.ZombiesPerPlayerMax) * #player.GetHumans()) + D3bot.ZombiesCountAddition + (mapParams.BotMod or 0) + (D3bot.NodeZombiesCountAddition or 0)),
0,
allowedBots)
local survivorFormula = (mapParams.SPP or D3bot.SurvivorsPerPlayer) * #player.GetHumans()
local survivorsCount = math.Clamp(
math.ceil(survivorFormula + D3bot.SurvivorCountAddition + (mapParams.SCA or 0)),
0,
math.max(allowedBots - zombiesCount, 0))
return zombiesCount, (GAMEMODE.ZombieEscape or GAMEMODE.ObjectiveMap) and 0 or survivorsCount, allowedTotal
end

Any player that willingly or unwillingly joins the zombie team, will cause the addon to kick zombie bots until the desired number is reached again. Unfortunately there is no setting to prevent bots from leaving when they kill a player.

Probably the best way for now would be to modify that function. You can replace it with the following (untested) snippet, which will neither add/remove any zombie bots when the game is active:

function D3bot.GetDesiredBotCount()
	local wave = math.max(1, GAMEMODE:GetWave())
	local minutes = (CurTime() - roundStartTime) / 60
	local allowedTotal = game.MaxPlayers() - 2
	local allowedBots = allowedTotal - #player.GetHumans()
	local mapParams = D3bot.MapNavMesh.Params
	local zombieFormula = ((mapParams.ZPP or D3bot.ZombiesPerPlayer) + (mapParams.ZPPW or D3bot.ZombiesPerPlayerWave) * wave) * #player.GetHumans() + (mapParams.ZPM or D3bot.ZombiesPerMinute) * minutes + (mapParams.ZPW or D3bot.ZombiesPerWave) * wave
	local zombiesCount = math.Clamp(
		math.ceil(math.min(zombieFormula, (mapParams.ZPPM or D3bot.ZombiesPerPlayerMax) * #player.GetHumans()) + D3bot.ZombiesCountAddition + (mapParams.BotMod or 0) + (D3bot.NodeZombiesCountAddition or 0)),
		0,
		allowedBots)
	local survivorFormula = (mapParams.SPP or D3bot.SurvivorsPerPlayer) * #player.GetHumans()
	local survivorsCount = math.Clamp(
		math.ceil(survivorFormula + D3bot.SurvivorCountAddition + (mapParams.SCA or 0)),
		0,
		math.max(allowedBots - zombiesCount, 0))
	if GAMEMODE:GetWave() == 0 then zombiesCount = nil end
	return zombiesCount, (GAMEMODE.ZombieEscape or GAMEMODE.ObjectiveMap) and 0 or survivorsCount, allowedTotal
end

You can also replace that function all together with some more simple logic. All you need to return is:

  • Your desired number of zombies (including non bot zombies).
  • Your desired number of survivors (incudling non bots...), i would just leave that at 0 for now.
  • The total allowed number of players, above which bots will be kicked regardless of the team they are in. game.MaxPlayers() - 2 is probably fine for that.

Instead of that mess of parameters that we have now, i will most likely add a function to the config file so that server owners can easily define their own custom behavior. But that is for when i find some time to continue to work on the bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants