Welcome!
This directory contains the source code and resources for implementing a CTF game mode in your game project.
Whether you're building a multiplayer game, experimenting with game mechanics, or enhancing an existing project, this CTF game mode provides a starting point to get you started.
- ctf_client.lua: Handles flag logic and team selection.
- ctf_rendering.lua: Handles drawing on the client.
- ctf_server.lua: Handles most of the CTF logic (this involves capturing, dropping and taking the flag).
- ctf_shared.lua: Has some structs (and lua tables) and a single function that is shared by the server and the client. Documentation about the
shared_scriptdirective can be found here.
For the server logic, team and flag objects 'classes' are used, Lua supports such in the form of metatables under chapter 16.1.
Classes used in this game-mode are detailed down below:
- CTFGame: The main class that simply holds a
CTFGame:Updatemethod, itsconstructor(to initialize flags and teams) and aCTFGame:shutDownmethod that is used to 'dispose' of any flag or team instances onceonResourceStopgets called. - Flag: Used for each
Flaginstance, eachFlagcan have different states and they're tied to a team. - Team: An instance of
Teamstores the base position and each team color, teams (referred byCTFGameasself.teams) are Blue, Red and Spectator (where Spectator is simply a placeholder at the moment).
This game mode utilizes the following FiveM features:
- State Bags: To keep track of any entity states between client and server.
- Put the bases farther away from each other, mainly close for testing.