samp.directory
← Scripts y librerías

DevD4v3/Capture-The-Flag

A complete and extensible game mode for open.mp (Open Multiplayer, a multiplayer mod for GTA San Andreas), built with C# and SampSharp

Herramienta★ 33actualizado ago 2026AGPL-3.0C#
Abrir en GitHub

README.md

Capture the Flag is a complete and extensible 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.

History

SampSharp v0.x (Legacy)

The v9.x versions of Capture the Flag were built with SampSharp v0.x (Legacy), the original implementation targeting SA-MP servers. While it continues to receive maintenance and bug fixes, it is no longer the primary development focus and has inherent architectural limitations.

SampSharp v1.x

Starting with v10.x of Capture the Flag, the project was migrated to SampSharp v1.x, the modern rewrite built from the ground up for the open.mp server.

It embraces current .NET technologies, requires 64-bit architecture, and introduces the ECS (Entity Component System) framework.

For more information about the differences between SampSharp versions and their platform support, see the SampSharp Platform & Version Support documentation.

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
CommandDescription
/gungameon <kills-per-level>Enables GunGame.
/gungameoffDisables 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

CommandDescription
/weaponsOpens the list of available weapons from the current catalog.
/weaponpackDisplays the player's saved Weapon Pack. Weapons can be removed individually from this menu.

Admin Commands

CommandDescription
/weaponcatalogChanges 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
SectionDescription
AlphaTeamLocationsAlpha team spawn locations
BetaTeamLocationsBeta team spawn locations
RedFlagLocationRed flag position
BlueFlagLocationBlue 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

Technologies used

Leer el resto en GitHub

capture-the-flagcapturetheflagcsharpctfdotnetecsgrandgrand-theft-autogtagtasahexagonal-architectureompoopoop-principlesopenmpopenmultiplayersa-mpsampsampsharpsan-andreas-multiplayer

Esta página se genera con lo que GitHub publica sobre el repositorio. samp.directory no aloja el código. Informar de un problema con esta ficha

DevD4v3/Capture-The-Flag: Herramienta de SA-MP | samp.directory