Download

AI bots on a dedicated server

Hello,

did anyone tried to run bots on the dedicated server?

I have a multiplayer game and I want to add bots to it. But not some AI mobs. I want a player bots. Copies of players, just not controlled by the player but by the server (so they still have all stats, kills, deaths, healths, weapons, ammo etc. like common player).

What I did now on the server:

  1. I created a player controller (good, player appeared in a player list)
  2. Spawned the bot with this player controller (good, bot was spawned in the world)

But this bot doing nothing. Is even not possible to use LaunchCharacter() on him - if I use it, nothing happens. If I use it on myself, I am launched successfully.
But something works - for example I can kill him.

I think that problem is somewhere on the dedicated server because the bot “player” running now on the server, but some code expecting that players runs only on the clients, not servers.

Is this that problem? Can it be solved something? How to solve launching the bot?

Bots on dedicated server works fine. You should create an AIController for the bot and let that possess your Character. Spawning from Gamemode can be done by first spawning the players and then spawning your bots. You probably want to setup the bots with specifc things like name and team.

But I need to have spawned the common player controller. The whole game will work with it. So I have to rewrite everything? For example list of connected players. Currently I will iterate over all player controllers and that is list of the connected players. But now I should do this to get players and also iterate over AI controllers to get bots and merge both lists to get final list of players?

If yes, then I have to double almost everything “if player then add score to the player… and if bot then add score to the bot…”. Not to mention that player controller have many essencial custom methods which ai controller will not have. It would be much easier to just spawn bot as a fake client.

The Controller should not have your player data(score, etc), you should put that in the PlayerState. What functions in the PlayerController do you need for bots?

**FrostyElkArne: **For example methods for writing to chat, building structures, changing team etc. If I will not use this controller then I cannot do almost nothing. And I will not be counted as a player because it is different controller and server counting only my controllers as players.