General Game Mode Setup – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<syntaxhighlight lang="c#">" to "<enforce>")
m (Text replacement - "</syntaxhighlight>" to "</enforce>")
Line 154: Line 154:
BaseGameMode baseGameMode = GetGame().GetGameMode();
BaseGameMode baseGameMode = GetGame().GetGameMode();
SCR_GameModeBase gameMode = SCR_GameModeBase.Cast( baseGameMode );
SCR_GameModeBase gameMode = SCR_GameModeBase.Cast( baseGameMode );
</syntaxhighlight>
</enforce>
'''SCR_FactionManager''': single instance in the world - mandatory.
'''SCR_FactionManager''': single instance in the world - mandatory.


Line 161: Line 161:
FactionManager baseFactionManager = GetGame().GetFactionManager();
FactionManager baseFactionManager = GetGame().GetFactionManager();
SCR_FactionManager factionManager = SCR_FactionManager.Cast( baseFactionManager );
SCR_FactionManager factionManager = SCR_FactionManager.Cast( baseFactionManager );
</syntaxhighlight>
</enforce>
'''SCR_LoadoutManager''' : single instance in the world - mandatory.
'''SCR_LoadoutManager''' : single instance in the world - mandatory.


Line 167: Line 167:
<enforce>
<enforce>
SCR_LoadoutManager loadoutManager = GetGame().GetLoadoutManager();
SCR_LoadoutManager loadoutManager = GetGame().GetLoadoutManager();
</syntaxhighlight>
</enforce>
'''SCR_RespawnSystemComponent:''' single instance in the world, attached to game mode. Mandatory.
'''SCR_RespawnSystemComponent:''' single instance in the world, attached to game mode. Mandatory.


Line 174: Line 174:
SCR_GameModeBase gameMode; /* = yourInstance; */
SCR_GameModeBase gameMode; /* = yourInstance; */
SCR_RespawnSystemComponent respawnSystemComponent = gameMode.GetRespawnSystemComponent();
SCR_RespawnSystemComponent respawnSystemComponent = gameMode.GetRespawnSystemComponent();
</syntaxhighlight>
</enforce>
'''SCR_RespawnComponent:''' Not to confuse with '''SCR_RespawnSystemComponent'''!
'''SCR_RespawnComponent:''' Not to confuse with '''SCR_RespawnSystemComponent'''!


Line 185: Line 185:
// Client: if myId is local playerId, respawn component is returned. Null otherwise. (Owned PlayerController component only)
// Client: if myId is local playerId, respawn component is returned. Null otherwise. (Owned PlayerController component only)
// Authority: if myId is valid playerId, respawn component is returned. Null otherwise. (Any PlayerController component)
// Authority: if myId is valid playerId, respawn component is returned. Null otherwise. (Any PlayerController component)
</syntaxhighlight>
</enforce>





Revision as of 19:18, 30 July 2022

The SCR_BaseGameMode entity is the lowest usable game mode implementation that allows you to set up a custom game mode.

The core idea behind SCR_BaseGameMode is the expansion via specialized components of SCR_BaseGameModeComponent type.

These provide the user with API that allows hooking onto certain game events as necessary. Many provided components can work standalone and can be mixed and matched.


Example Scenarios

To easily get familiar with how game modes can be set up now, please see the following scenarios:

Mode Link Description
Plain enfusion://ResourceManager/~ArmaReforger:worlds/MP/MpTest.ent
  • Simplest scenario
  • Automatic respawn
  • Free for all
Deathmatch enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/Deathmatch/TestGameMode_Deathmatch_Auto.ent
  • Scoring
  • Automatic respawn
  • Free for all
Deathmatch enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/Deathmatch/TestGameMode_Deathmatch_Selection.ent
  • Scoring
  • Menu respawn
  • Free for all
Team Deathmatch enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/TeamDeathmatch/TestGameMode_TeamDeathmatch_Auto.ent
  • Scoring
  • Automatic respawn
  • Team based
Team Deathmatch enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/TeamDeathmatch/TestGameMode_TeamDeathmatch_Selection.ent
  • Scoring
  • Menu respawn
  • Team based
Capture Point enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/CapturePoint/TestGameMode_CapturePoint.ent
  • CP Scoring
  • Menu respawn
  • Free for all
Capture & Hold enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/CaptureAndHold/TestGameMode_CaptureAndHold.ent
  • C&H Scoring
  • Menu respawn (wave)
  • Team based
Game Master enfusion://ResourceManager/~ArmaReforger:worlds/FeatureTests/GameModes/GameMaster/TestGameMode_GameMaster.ent
  • Game master logic

Basic Setup

To setup the most basic scenario the user must add the following. For the simplest set-up add all items from the "Pre-made" column.

Free for All

Type Pre-made Prefab Base Prefab Description
SCR_BaseGameMode enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Modes/Plain/GameMode_Plain.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Modes/GameMode_Base.et Specializes game mode by using components and their combinations. Must always have a SCR_RespawnSystemComponet and specialized SCR_RespawnHandlerComponent to allow proper spawning. See Requirements.
SCR_FactionManager enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Factions/FactionManager_FFA.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Factions/FactionManager_Base.et Provides list of available factions and their properties. For free for all modes, use the FFA faction.
SCR_LoadoutManager enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Loadouts/LoadoutManager_FFA.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Loadouts/LoadoutManager_Base.et Provides list of available loadouts and their properties. For free for all modes, use the FFA faction.
SCR_SpawnPoint enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Spawning/SpawnPoint_FFA.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Spawning/SpawnPoint_Base.et Provides information to the respawn system, marking a location available for spawning at. Set per faction. For free for all modes, use the FFA faction.

Faction Based

Type Pre-made Prefab Base Prefab Description
SCR_BaseGameMode enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Modes/Plain/GameMode_Plain.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Modes/GameMode_Base.et Specializes game mode by using components and their combinations. Must always have a SCR_RespawnSystemComponet and specialized SCR_RespawnHandlerComponent to allow proper spawning. See Requirements.
SCR_FactionManager enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Factions/FactionManager_USxUSSR.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Factions/FactionManager_Base.et Provides list of available factions and their properties.
SCR_LoadoutManager enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Loadouts/LoadoutManager_USxUSSR.et enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Managers/Loadouts/LoadoutManager_Base.et Provides list of available loadouts and their properties.
SCR_SpawnPoint enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Spawning/SpawnPoint_USSR.et (USSR)

enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Spawning/SpawnPoint_US.et (US)

enfusion://ResourceManager/~ArmaReforger:Prefabs/MP/Spawning/SpawnPoint_Base.et Provides information to the respawn system, marking a location available for spawning at. Set per faction.


Requirements

There are several components which are crucial to the functionality of any game mode:

The first and most important is the SCR_RespawnSystemComponent which handles spawning and assigning of requested player entities and via the usage of SCR_RespawnComponent allows handling requests and responses between the authority and the remote client.

It also allows and handles synchronization of player loadout, faction and spawn point selection. Due to that, there always must be an instance of the SCR_FactionManager and SCR_LoadoutManager entities present in the world.

Additionally required is a component of SCR_RespawnHandlerComponent type - a base for implementing custom ways of handling respawning itself. See SCR_AutomaticRespawnHandlerComponent and SCR_RespawnMenuHandlerComponent for examples. The former handles respawning purely on the authority side (automatically), where the latter allows communication and request/approval selection between the remote client and the authority.


Instances

SCR_BaseGameMode: single instance in the world - mandatory.

Ties game mode together, manages attached SCR_BaseGameModeComponent(s), calls necessary methods.

BaseGameMode baseGameMode = GetGame().GetGameMode(); SCR_GameModeBase gameMode = SCR_GameModeBase.Cast( baseGameMode );

SCR_FactionManager: single instance in the world - mandatory.

Provides available factions and API for retrieving and finding these by keys or indices.

FactionManager baseFactionManager = GetGame().GetFactionManager(); SCR_FactionManager factionManager = SCR_FactionManager.Cast( baseFactionManager );

SCR_LoadoutManager : single instance in the world - mandatory.

Provides available loadouts and API for retrieving and finding these by indices.

SCR_LoadoutManager loadoutManager = GetGame().GetLoadoutManager();

SCR_RespawnSystemComponent: single instance in the world, attached to game mode. Mandatory.

Provides means of setting and request/response player faction, loadout and spawn points.

SCR_GameModeBase gameMode; /* = yourInstance; */ SCR_RespawnSystemComponent respawnSystemComponent = gameMode.GetRespawnSystemComponent();

SCR_RespawnComponent: Not to confuse with SCR_RespawnSystemComponent!

This component is and should always be attached to a player controller. That means that remote client will always be able to retrieve their local SCR_RespawnComponent only! The authority will be able to retrieve and iterate over all SCR_RespawnComponent.

int myId; /* = my_local_id */ RespawnComponent baseRespawnComponent = GetGame().GetPlayerManager().GetPlayerRespawnComponent( myId ); SCR_RespawnComponent respawnComponent = SCR_RespawnComponent.Cast( baseRespawnComponent ); // Client: if myId is local playerId, respawn component is returned. Null otherwise. (Owned PlayerController component only) // Authority: if myId is valid playerId, respawn component is returned. Null otherwise. (Any PlayerController component)


Game State

The game has three pre-defined states that can be set by the server and are automatically replicated with appropriate callback to the clients. This can be omitted, leaving the game always in GAME state.

  • PREGAME (e.g. wait for n players?)
  • GAME (core game loop)
  • POSTGAME (e.g. show scoreboard, next scenario voting)

For particular implementation and details, see SCR_EGameModeState, SCR_GameModeEndData and SCR_BaseGameMode.OnGameStateChanged().

Gamemode End

The game mode transitions into POSTGAME state once the authority deems so by calling the EndGameMode() method.

This method accepts an instance of SCR_GameModeEndData, which is a small serializable structure that is replicated to all clients and contains somewhat arbitrary data. This can be used to synchronize the end state (winner player, winner faction, ...) to show e.g. the end-game screen.


Troubleshooting

My game mode is not working as it was before, errors are logged into the console regarding missing game mode, what do I do?

Navigate to the Basic Setup section.

Drag prefabs from the Faction Based table if you want to have US versus USSR game mode or Free for All table if FFA is what you are looking for.