// 1. Define the Game Class // This is the "Brain" of our island. It holds all the logic. team_elimination_game := class(creative_game): // We need to track players. A "Map" is like a scoreboard list. // Key = Player ID, Value = The Player Entity Players: Map = Map{} // List of weapons to grant. Order matters! Weapons: []string = ["Pistol", "SMG", "Shotgun", "AR", "Sniper"] // Track current weapon tier for each team TeamRedTier: int = 0 TeamBlueTier: int = 0 // 2. The Setup Function // This runs once when the game starts. Like the pre-game lobby. setup() -> void: Print("Game Started! Fight!") // Subscribe to the "Player Joined" event. // This means: "Hey Verse, call me whenever someone spawns." PlayerJoinedEvent.Subscribe(OnPlayerJoined) // Subscribe to the "Player Eliminated" event. // This means: "Hey Verse, call me whenever someone dies." PlayerEliminatedEvent.Subscribe(OnPlayerEliminated) // 3. Handle a New Player Joining OnPlayerJoined(InPlayer: player) -> void: Print(&"{InPlayer.GetPlayerName()} joined the fight!") // Add this player to our tracking map Players.Add(InPlayer, InPlayer.GetPlayerEntity()) // Give them their first weapon (Pistol) GrantWeapon(InPlayer, 0) // 4. Handle an Elimination OnPlayerEliminated(InEliminated: player, InKiller: player) -> void: // InKiller is the person who got the kill. // InEliminated is the person who died. // Check if the killer is valid (sometimes a player can die without a killer, like fall damage) if InKiller != void: // Determine which team the killer is on KillerTeam := InKiller.GetTeam() // Get the killer's current tier CurrentTier := if KillerTeam == TeamRed, TeamRedTier, TeamBlueTier // Increment the tier (next weapon) NewTier := CurrentTier + 1 // Update the global tier for that team if KillerTeam == TeamRed: TeamRedTier = NewTier else: TeamBlueTier = NewTier // Grant the next weapon GrantWeapon(InKiller, NewTier) // Check for Win Condition CheckWinCondition(InKiller.GetTeam()) // 5. Grant Weapon Helper Function // Think of this as a mini-recipe for giving items GrantWeapon(InPlayer: player, Tier: int) -> void: // Make sure the tier isn't higher than our weapon list if Tier >= len(Weapons): Tier = len(Weapons) - 1 // Cap at the last weapon WeaponName := Weapons[Tier] // Find the Item Granter that corresponds to this weapon // In a real build, you'd link this to specific device IDs, // but for simplicity, we'll assume a generic grant logic here. // Note: In actual UEFN, you'd use Device methods. // For this tutorial, we simulate the logic concept. Print(&"{InPlayer.GetPlayerName()} got {WeaponName}!") // Real Verse code would look like: // ItemGranterDevice.GrantItem(InPlayer, WeaponName) // 6. Check Who Won CheckWinCondition(WinningTeam: team) -> void: // Get the number of players alive on the losing team LosingTeam := if WinningTeam == TeamRed, TeamBlue, TeamRed PlayersAlive := 0 // Loop through all players in our map for EachPlayer: player <- Players: if EachPlayer.GetTeam() == LosingTeam: // If the player is alive, count them // (In real code, we'd check health > 0) PlayersAlive++ if PlayersAlive == 0: Print(&"Team {WinningTeam} Wins!") EndGame(WinningTeam)