Skip to content
Pablo Rodriguez

Flag System

Create comprehensive flag system for competitive gameplay:

  • Arrow Component: Root for positioning control
  • Static Mesh Component: Flag visual representation
  • Box Collision: Pickup detection (custom collision, overlap pawn only)
  • Team System Integration: Team enumeration for flag ownership
// Flag State Variables
Team: E_Team; // Flag ownership (Player/Enemy)
Flag_Home: Actor; // Reference to home base
Spawn_Transform: Transform; // Original flag position
Attached_Actor: Character; // Current flag bearer
// Flag Bearer Detection
OnFlagPickup(Character) {
if (Character.GetTeam() != Flag_Team) {
// Enemy picked up flag
AttachFlagToCharacter(Character);
DisableFlagCollision();
StartDeathCheckTimer();
} else {
// Ally touched flag - return to base if dropped
ResetFlagToSpawn();
}
}

Implement flag carrying mechanics:

Create flag-carrying socket on character skeleton:

  • Socket Name: S_Flag on first spine bone
  • Position: X=4, Y=31, Z=-51 (adjust for character model)
  • Rotation: X=-13°, Y=80°, Z=90° for natural flag position
  • Scale: 0.5 uniform scaling for appropriate size
// Flag Attachment Implementation
AttachFlagToCharacter(Character) {
character_mesh = Character.Interface_Get_Mesh();
AttachActorToComponent(character_mesh, 'S_Flag', SnapToTarget);
Attached_Actor = Character;
// Start monitoring flag bearer health
Timer_Check_For_Dead = CreateTimer(0.25, true);
}

Handle flag bearer death and flag recovery:

// Flag Bearer Death Monitoring
CE_Check_For_Dead() {
if (Attached_Actor.Interface_Get_Dead_State()) {
// Flag bearer died - drop flag
DetachFromActor(KeepWorld, KeepWorld, KeepWorld);
// Find ground position for dropped flag
LineTraceForObjects(CurrentLocation + 500Z, CurrentLocation - 500Z);
SetActorTransform(GroundLocation, SpawnRotation, SpawnScale);
EnableFlagCollision();
StopDeathCheckTimer();
}
}

Create flag capture zones:

  • Arrow Component: Root component
  • Box Collision: Large capture zone above base
  • Static Mesh: Visual base representation (spawn pad, altar, etc.)
  • Team Assignment: Match with corresponding flag team
// Flag Capture Logic
OnHomeCaptureZoneOverlap(OtherActor) {
if (OtherActor != Flag && OtherActor.IsA(Actor_Flag)) {
captured_flag = Cast(Actor_Flag, OtherActor);
if (captured_flag.Team != Team) {
// Enemy flag captured!
CaptureFlag(captured_flag);
}
}
}
CaptureFlag(EnemyFlag) {
EnemyFlag.DetachFromActor();
EnemyFlag.CE_Reset_Transform(); // Return to enemy base
AwardPointToTeam(Team);
}

Create simple score tracking interface:

  • Size: 200x50 for compact display
  • Team Colors: Red and blue sections (100px each)
  • Score Text: Current score display for each team
  • Positioning: Top middle of screen, hidden by default
// Score Tracking System
CE_Score_Red() {
Score_Red++;
UpdateScoreDisplay();
CheckGameEnd();
}
CE_Score_Blue() {
Score_Blue++;
UpdateScoreDisplay();
CheckGameEnd();
}
CheckGameEnd() {
if (Score_Red >= WinningScore || Score_Blue >= WinningScore) {
// Game Over - restart level
ExecuteConsoleCommand('RestartLevel');
}
}

Connect flag captures to scoreboard:

// Flag Home Score Integration
OnFlagCaptured(CapturingTeam) {
scoreboard = GetWidgetOfClass(W_Scoreboard);
if (CapturingTeam == Player) {
scoreboard.CE_Score_Blue();
} else {
scoreboard.CE_Score_Red();
}
// Show scoreboard when point scored
scoreboard.SetVisibility(NotHitTestable_SelfOnly);
}

Create balanced competitive environment:

  • Two Identical Bases: Ensure perfect symmetry for fair competition
  • Flag Rooms: Secure locations for flag placement
  • Multiple Routes: Various paths to flag rooms with different difficulty levels
  1. Create Single Base: Design one complete base structure
  2. Copy and Mirror: Duplicate base for perfect symmetry
  3. Team Assignment: Set appropriate team values for flags and homes
  4. Eyedropper Tool: Link flags to corresponding homes and vice versa

Enhance flag system with clear feedback:

  • Team Colors: Blue flags for player team, red flags for enemy team
  • Construction Script: Automatically set flag mesh based on team
  • Status Indicators: Visual cues for flag states (home, carried, dropped)
  • Capture Requirements: Ensure your flag must be home to score
  • Flag Reset: Dropped flags return home after timeout or ally touch
  • Movement Penalties: Optional movement speed reduction for flag bearers
  • Flag Bearer Tracking: Boolean variable to identify flag carriers
  • Game Mode Integration: Flags can be disabled for non-CTF game modes
  • Team System: Leverages existing team framework for consistent behavior

The flag system creates engaging competitive gameplay with clear objectives, balanced mechanics, and immediate visual feedback for all player actions and game state changes.