Skip to content

Repository files navigation

🎮 Capture the Flag

A fast-paced C# game mode for open.mp — featuring two teams, two flags, and pure competitive chaos.

SA-MP logo

Capture the Flag is a game mode for open.mp (Open Multiplayer, a multiplayer mod for GTA San Andreas) built with C# and the SampSharp framework.

There are 2 flags on the map, one for each team. Players need to capture the enemy's flag and bring it back to their own base.

Index

Features

  • Capture the Flag gameplay.
  • Configurable Weapon Packs.
  • Multiple weapon catalogs.
  • In-game coin economy.
  • Redeemable combat combos.
  • Optional GunGame mode.
  • Multiple GunGame weapon progressions.
  • Performance-based team balancing.
  • Automatic map rotation.
  • Support for creating custom maps.
  • Player ranks and statistics.
  • SQLite and MariaDB support.
  • Docker support.

Gameplay

The Beta team plays against the Alpha team. The goal is to steal the enemy team’s flag and bring it back to the spawn of your own flag.

To score, your own flag must be at its base, so teams must attack and defend at the same time. Team coordination and tactical play are essential to win.

The match lasts 15 minutes. The team with the most captures when time runs out wins.
If both teams have the same number of captures, the match ends in a draw.

Beware! Enemies can see flag carriers on their radar.

In this video, you can watch a gameplay demo: https://youtu.be/rsWCZaT4aBE
You can also check the full playlist: https://www.youtube.com/playlist?list=PLBM-9TMXSAJjsWn4zmg1ua7eof9Aj83fS

Gameplay Rules

Game Objective

  • Steal the enemy team’s flag and bring it back to your base to score a capture.
  • The match does not end when a team reaches a specific number of captures.
  • The match only ends when the timer runs out.

Flag Rules

Stealing the enemy flag

  • A player can steal the enemy flag by picking up the flag pickup at the enemy base, marked by a square icon on the map.
  • A player can carry only one flag at a time.

Capturing (scoring a capture)

  • To score a capture, all of the following conditions must be met:
    • The player is carrying the enemy flag
    • The player reaches their own base or capture zone
    • The player’s team flag is at its base position
  • If the team’s flag has been stolen or is dropped somewhere on the map, a capture cannot be scored.

Flag carrier death

  • If a player dies while carrying the enemy flag:
    • The flag is dropped on the ground at the player’s current position
    • The player stops being the flag carrier

Flag carrier disconnection

  • If a player disconnects while carrying the enemy flag:
    • The flag is dropped on the ground at the player’s last known position
    • The player is removed from the match

Flag carrier inactivity (pause)

  • If a flag carrier remains paused or inactive for 30 seconds:
    • the enemy flag is automatically returned to its base
    • the player stops being the flag carrier

Flag auto-return

  • If a flag remains dropped on the map and is not recovered:
    • It automatically returns to its base after 120 seconds

Death and respawn

  • When a player dies:
    • Players respawn at their team’s base
    • A random spawn position is selected for the player (spawn location is not fixed)
    • No additional spawn protection is applied
    • If they were carrying a flag, the flag drop rule applies

Match end conditions

  • The match ends only when the timer reaches zero.
  • The team with the highest number of captures wins.
  • If both teams have the same number of captures:
    • The match ends in a draw
    • There is no sudden death

Round Transition Rules

  • Every 15 minutes, the current map ends and a new map is loaded.
  • During map rotation:
    • All connected players are frozen
    • Players are switched to spectator mode
  • A 10-second "loading map" countdown is displayed before the new round starts.
  • Teams are rebalanced based on player performance from the previous round:
    • Players are reassigned to teams according to their scores
    • Team balance is calculated automatically by the system
  • Players are not sent to the class selection screen:
    • Respawn is automatic
    • The system decides the spawn and team assignment

Additional Game Modes

GunGame

Besides the default Capture the Flag gameplay, the server includes an optional GunGame mode that can be enabled by administrators at runtime.

Unlike traditional GunGame servers, this mode does not replace Capture the Flag. Both game modes run simultaneously on the current map, allowing players to continue capturing flags while progressing through weapon levels.

Commands

Command Description
/gungameon <kills-per-level> Enables GunGame.
/gungameoff Disables GunGame.

Rules

  • Players start with the first weapon in the selected progression.
  • Every configured number of kills advances the player to the next weapon.
  • Knife kills steal one weapon level from the victim.
  • The first player to complete the progression wins the GunGame match.
  • Capture the Flag objectives remain active while GunGame is enabled.
  • Completing GunGame does not end the Capture the Flag match. Instead, the event concludes, the winner receives a special reward, their teammates receive a smaller bonus, and normal Capture the Flag gameplay continues.

Available Weapon Progressions

  • Classic
  • Reverse Classic
  • Pistols Only
  • SMGs Only
  • Shotguns Only
  • Rifles Only
  • Powerful Weapons

Account System

The game mode includes a built-in account system that requires players to authenticate when they join the server.

Authentication

Authentication is based on the player's nickname:

  • If the nickname has never been registered before, the player is prompted to create a password (signup).
  • If the nickname already exists, the player is prompted to enter their password (login).

Passwords are securely hashed before being stored in the database.

Authentication Flow

  1. A player connects to the server.
  2. The system searches for an existing account using the player's nickname.
  3. If no account exists:
    • The player is asked to create a password.
    • A new account is created.
    • The player is authenticated automatically.
  4. If the account already exists:
    • The player is asked to enter their password.
    • If the password is correct, the player is authenticated.
    • Otherwise, the player is prompted to try again.
  5. After multiple consecutive failed login attempts, the player is automatically kicked from the server.

The entire authentication process is handled automatically, allowing new players to register and existing players to log in without requiring any commands (such as /register or /login).

Authorization

Player accounts can be assigned one of the following roles:

  • Basic
  • VIP
  • Moderator
  • Admin

Privileged commands declare the minimum required role. Before a command is executed, the system verifies whether the player's account has the required role.

Weapon System

When players spawn, they are presented with a weapon selection menu containing the weapons available in the currently active weapon catalog.

Selected weapons are automatically saved to the player's Weapon Pack, allowing them to reuse the same weapons across future spawns without having to select their weapons again.

Weapon Catalogs

Administrators can change the active weapon catalog at runtime.

Available catalogs include:

  • Walking Weapons
  • Run Weapons
  • Run & Walk Weapons
  • Rifles Only
  • War Weapons
  • Heavy Weapons
  • Melee Weapons

Player Commands

Command Description
/weapons Opens the list of available weapons from the current catalog.
/weaponpack Displays the player's saved Weapon Pack. Weapons can be removed individually from this menu.

Admin Commands

Command Description
/weaponcatalog Changes the active weapon catalog at runtime.

GunGame Integration

When GunGame is enabled:

  • /weapons is disabled.
  • /weaponpack is disabled.
  • /weaponcatalog is disabled.

This prevents conflicts with the GunGame weapon progression, where players are restricted to a single assigned weapon.

Combo System

Coins

Players earn Coins by participating in the match.

Coins are awarded for actions such as:

  • Achieving kill streaks.
  • Eliminating the enemy flag carrier.
  • Capturing the enemy flag.
  • Returning the friendly flag.
  • Scoring a point for the team.
  • Ranking up.

Once a player reaches 100 Coins, they can use the /combos command to exchange all their coins for a temporary combat package.

Redeeming a combo resets the player's coin balance back to 0.

Available Combos

  • +100 Health, +100 Armour and Flamethrower
  • +100 Health, +100 Armour and Grenades
  • +100 Health, +100 Armour and Molotov Cocktails
  • +100 Health and Rocket Launcher (RPG) (disabled by default; admins can enable it with /rpgon)
  • +100 Health, +100 Armour and Satchel Charges
  • +100 Health, +100 Armour and Tear Gas

GunGame Integration

The /combos command is disabled while GunGame is active.

Additionally, Coins are no longer awarded for achieving kill streaks or ranking up during GunGame. This prevents players from accumulating enough Coins to redeem a combo immediately after the event ends. Rewards related to the core Capture the Flag gameplay, such as eliminating the enemy flag carrier, capturing the enemy flag, returning the friendly flag, and scoring points for the team, remain unchanged.

This prevents players from obtaining weapons outside the GunGame progression. Instead, the winner is rewarded with 100 Coins, fully restored Health and Armour, and a special weapon after completing the entire weapon progression. Since GunGame is integrated into the ongoing Capture the Flag match, the winner's teammates also receive a smaller bonus consisting of additional Health, Armour, and Coins.

Creating a custom map

Adding a new map requires three steps.

Create the map definition

Create a new class under:

src/Host/CustomMapObjects/

that inherits from MapDefinition.

Example:

public class AimHeadshotV3 : MapDefinition
{
    public override string Name => "AimHeadshotV3";

    protected override void OnLoad()
    {
        CreateObject(
            modelId: 6989,
            position: new Vector3(-166.94000f, 138.17999f, -79.50000f),
            rotation: new Vector3(0.00000f, 0.00000f, -17.46000f)
        );

        GlobalObject object0 = CreateObject(
            modelId: 3885,
            position: new Vector3(-152.15030f, 52.53920f, 2.75850f),
            rotation: new Vector3(0.00000f, 0.00000f, 146.00000f)
        );

        object0.SetMaterial(
            materialIndex: 0,
            modelId: 10357,
            txdName: "tvtower_sfs",
            textureName: "ws_transmit_red",
            materialColor: Color.FromInteger(0xFFFFFFFF, ColorFormat.ARGB)
        );
    }
}

Map objects are loaded through SampSharp.MapObjects.

Material colors

When using SetMaterial, always create material colors using the ARGB format:

Color.FromInteger(0xFFFFFFFF, ColorFormat.ARGB)

The SetMaterial method expects colors in ARGB format. Creating a Color instance directly, for example:

new Color(0xFFFFFFFF)

uses RGBA by default.

Although values such as 0xFFFFFFFF and 0x00000000 produce the same result, other colors may be interpreted incorrectly, resulting in materials with incorrect colors or invisible textures.

Register the map

Register the map definition in src/Host/Startup.cs:

public void ConfigureServices(IServiceCollection services, IConfiguration _)
{
    // ...

    services.AddMapDefinition<AimHeadshotV3>();

    // ...
}

Create the gameplay configuration

Create an INI file under:

src/Application/Maps/Files/

The file name must match the value returned by MapDefinition.Name, as it is used as the unique identifier of the map.

For example:

public override string Name => "AimHeadshotV3";

must correspond to:

AimHeadshotV3.ini

This file contains gameplay-specific configuration for the map.

Supported sections

Section Description
AlphaTeamLocations Alpha team spawn locations
BetaTeamLocations Beta team spawn locations
RedFlagLocation Red flag position
BlueFlagLocation Blue flag position
Interior (optional) Interior ID
Weather (optional) Weather ID (0-20)
WorldTime (optional) World Time (0-23)

Example

# Format: X,Y,Z,Angle
[AlphaTeamLocations]
-669.9301,2567.7261,233.1899,4.0968
-662.3662,2568.0757,233.1899,4.4101

[BetaTeamLocations]
-656.4174,2739.6848,219.2168,177.9750
-650.9906,2739.0764,219.2168,177.9750

# Format: X,Y,Z
[RedFlagLocation]
-729.1639,2635.3447,223.3559

[BlueFlagLocation]
-576.2537,2731.9312,233.3905

# See https://open.mp/docs/scripting/resources/interiorids
[Interior]
10

# Valid values: 0-20
# See https://open.mp/docs/scripting/resources/weatherid
[Weather]
1

# Valid values: 0-23
# See https://open.mp/docs/scripting/functions/SetWorldTime
[WorldTime]
12

Note

A class that inherits from MapDefinition defines the map objects loaded through SampSharp.MapObjects, while the INI file contains gameplay-specific settings such as team spawn locations, flag locations, interior, weather, and world time.

Screenshots

sa-mp-000

sa-mp-000

sa-mp-001

sa-mp-001

sa-mp-002

sa-mp-002

sa-mp-003

sa-mp-003

sa-mp-004

sa-mp-004

sa-mp-005

sa-mp-005

sa-mp-006

sa-mp-006

sa-mp-007

sa-mp-007

sa-mp-008

sa-mp-008

sa-mp-009

sa-mp-009

sa-mp-010

sa-mp-010

Technologies used

Software

DevD4v3 libraries

Third-party frameworks and libraries

Testing

Software Engineering

These concepts have been applied to this project:

Programming Paradigms

Software Patterns

Design Principles

Requirements to play

Deployment without Docker

  • Download the appropriate release package for your operating system:
  • Extract the package to a directory of your choice.
  • Modify the .env file according to your needs.
  • Start the Open Multiplayer server:
    • Windows: omp-server.exe
    • Linux: ./omp-server

Deployment with Docker

  • Clone the repository:
git clone --recursive https://github.com/DevD4v3/Capture-The-Flag.git
  • Change directory:
cd Capture-The-Flag
  • Copy the contents of .env.example to .env:
cp .env.example .env
  • Build the image and initiate services:
docker compose up --build -d
  • Check the server logs to see if everything is working properly:
docker compose exec -it app cat log.txt
localhost:7777

Credentials

The following table shows the default credentials for authentication from the game mode.

PlayerName Password
Admin_Player 123456
Moderator_Player 123456
VIP_Player 123456
Basic_Player 123456

Note that these credentials are only available if your database provider is in-memory. In your .env file you must indicate it as follows.

DatabaseProvider=InMemory

How to become an admin?

You must add your name and secret key from the .env file:

# Your nickname in the game.
ServerOwner__Name=MrDave
# Specify the secret key to give me admin.
ServerOwner__SecretKey=1234._%==?!

It is necessary to specify your secret key, which you will use when executing the command "/givemeadmin" in the game.

Supported RDBMS

SQLite

  • Create a file called .env in the root directory:
copy .env.example .env
  • You must specify the name of the database provider from the .env file:
DatabaseProvider=SQLite
  • You must specify the location of the database file:
SQLite__DataSource=C:\Users\mrdave\OneDrive\Desktop\gamemode.db
  • The database and its schema will be created automatically during server startup if they do not already exist.

MariaDB

  • Install MariaDb Server and set up your username and password.
  • Create a file called .env in the root directory:
copy .env.example .env
  • You must specify the name of the database provider from the .env file:
DatabaseProvider=MariaDB
  • You must specify the connection string in the .env file:
MariaDB__Server=localhost
MariaDB__Port=3306
MariaDB__Database=gamemode
MariaDB__UserName=root
MariaDB__Password=123456789
  • The database and its schema will be created automatically during server startup if they do not already exist.

Architectural overview

Show diagram

overview

Main components

  • Application Core. Contains all gameplay logic for the Capture the Flag game mode, including the rules and procedures that define how the game is played. It also defines the outbound ports required to interact with external systems.
  • Persistence Adapters. Provide concrete implementations of the outbound ports related to persistence. Each adapter encapsulates the data access logic for a specific storage technology, allowing the application core to remain independent of any specific persistence technology.
  • Host Application. Acts as the application's entry point and contains everything required to bootstrap the game mode.
    • Load application settings from .env file.
    • Select the database provider.
    • Register services in the DI container.
    • Register ECS systems.
    • Enable desired ECS system features.

Credits

This project would not have been possible without the following people and projects:

  • DevD4v3 — Creator of the original Capture the Flag game mode.
  • Parca_35 — Helped test the game mode.
  • ikkentim — Creator of the SampSharp framework.
  • Nickk888SAMP — Creator of NTD (TextDraw Editor).
  • samp-incognito — Creator of the Streamer Plugin.
  • Open Multiplayer — Creator of open.mp, a multiplayer modification for Grand Theft Auto: San Andreas that is fully compatible with San Andreas Multiplayer (SA-MP).
  • OpenSamp
    • Maintainer of omp-streamer-component, the x64 port of Incognito's Streamer Plugin for open.mp.
    • Creator of SampSharp.OpenMp.Streamer, providing managed (.NET) bindings for the Streamer Plugin on the SampSharp open.mp x64 host.

Mappers

  • Area66 by DragonZafiro.
  • d_dust5, SA_Hill, de_aztec and de_dust2_small by Elorreli.
  • Compound and cs_rockwar by Amirab.
  • DesertGlory, fy_iceworld2 and de_dust2x3 by TheYoungCapone.
  • EntryMap and TheConstruction by B4MB1[MC].
  • fy_snow by UnuAlex.
  • fy_snow2 by mihaibr.
  • de_dust2 by JamesT85.
  • Aim_Headshot by haubitze.
  • Aim_Headshot2 by Niktia_Ruchkov.
  • de_dust2x1 by SpikY_.
  • de_dust2x2 by Amads.
  • de_dust2x4 textured by excamunicado.
  • WarZone by Samarchai.
  • WarZone2 by iMaster.
  • cs_assault by Ghost-X.
  • GateToHell and TheWild by Zniper.
  • TheBunker by Dr.Pawno.
  • cs_deagle5 by SENiOR.
  • mp_jetdoor by saawan.
  • Simpson by Risq.
  • ZM_Italy - Unknown.
  • zone_paintball by Famous.
  • mp_island by Leo.
  • Baron's Playground (RC Battlefield V2) by Pyraeus.
  • cs_train, cs_opposition, fy_iceworld and de_dust2x5 by denis_32.

Contribution

Contributions of all kinds are welcome! You can help by improving the code, documentation, or tests.

To contribute:

  • Fork the repository.
  • Create a feature branch (git checkout -b my-new-change).
  • Commit your changes (git commit -am "Add some change").
  • Push to your branch (git push origin my-new-change).
  • Open a Pull Request.

License

This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.

Releases

Packages

Used by

Contributors

Languages