Where should i handle gameplay rules and code?

Hello, I’m trying to improve the functioning of my code so i made a diagram of where i think code should be, based on the doc. I’m not sure this is a correct way to do this things so please correct me if I’m wrong. I planned 2 GameMode, DeathMatch and Domination.

  • When Engine Start, use a Default GameMode.
    When a Type of Game is choose, Switch to the map (Map default will switch GameMode to Gamemode_Deathmatch or Gamemode_ Domination)

  • Player State :

  • Contain Function : GetKilled (e.g.Call by another Player)

RELATIVE TO DEATHMATCH MODE :

  • Gamemode_DeathMatch :

  • On Init : Show HUD_DeathMatch

  • On Init : Bind Event from PlayerState GetKilled, when called, call AddScore on GameState

  • GameState_DeathMatch :

  • Contain Varr : int Score

  • Contain Function : AddScore (+1 to Score)

  • HUD_DeathMatch :

  • On Init : Create all required widgets for this gamemode

RELATIVE TO DOMINATION MODE :

  • Gamemode_Domination :

  • On Init : Show HUD_Domination

  • Bind Event from AreaBlueprint::OnBeginOverlap, when called, call CalculateScore within a Timer

  • Contain Function : int CalculateScore(int Equip1PlayersInArea, int Equip2PlayersInArea) { “Calculate how many points to add”} “then call AddScore on GameState”

  • GameState_Domination :

  • Contain Varr : int Score

  • Contain Function : AddScore (+X to Score) //e.g. X Negative for Equip1 and X Positive for Equip2

  • HUD_Domination :

  • On Init : Create all required widgets for this gamemode

Is this correct or is there a more efficient way to do this? I’m planning to start a big project so i want everything to be clean :smiley:

The first thing I would recommend is to create a base class for all your game modes related things so that you can share functionality between game modes

Gamemode_Base
GameState_Base
HUD_Base

And the specific game modes inherit from that.

Second I would recommend putting the death onto the player pawn and the death counter on the player state.

Health, Damage, Speed should be on the pawn, things that are independent on which character you are controlling at the moment on the state.

But the second part is my opinion, the first part I strongly recommend

as Lardo Deepdelver said you need to use class inherence, but i would handle it different way, i would go in way UT is handle it.

Think about dominance, in it you cna kill people same as DeathMatch and you got teams same as team deathmatch, thats why i think you should go by creating GameMode for deathmatch which implements kill scoring, then based of deathwatch, team deathwatch which introduce teams to entire concept and then form team deathmatch the domination which changes the goals of team deathmatch. Thats how UT is doing, in this way. UT4 has little different approach, by having base game mode and then team base game mode and out of those create specific modes.

This way if you change something in more base concept that effect all modes you or something in team play don’t need to change it in every game mode, they will just inherent that.

With HUD i would do the same, make base HUD for all modes, then create widget specially for specific mode and put it on top of base HUD.

About the state, you should not have anything that is authoritative to game state like AddScore, clients should not have access to that. Point of Game State is to expose variables from gamemode to the clients that don’t have access to gamemode, it should be like a display board.

I was confused with GameState/Mode but now it seems more intuitive. Gonna do all the logic related to Game in GameMode (now including the score value) and then send this variable to GameState as you said. Thanks for your answer :slight_smile:

Thanks for your answer. I’ll consider do both parts :stuck_out_tongue: