Dadido3 / D3bot

A very primitive AI for GMod bots designed to work with Jetboom's Zombie Survival gamemode.
40 stars 28 forks source link

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

Open LuckyLuke9542 opened 10 months ago

LuckyLuke9542 commented 10 months ago

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 commented 10 months ago

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:

https://github.com/Dadido3/D3bot/blob/9c87dd47bad03b0b800de4a68528002bd36c6fc4/lua/d3bot/sv_zs_bot_handler/supervisor.lua#L4-L21

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:

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.