Join in progress issue

I have a elimination gun game that gives each player a gun on the start of the game, I have tried the join in progress spawn but they do not get a weapon, I tried the team index but it puts everyone on the same team. How do you set the game for players joining after the game starts and set them with a weapon thanks in advance

You listen to the PlayerAddedEvent function and use “Grant” from the item_granter_device for the player that joined.

1 Like

Sorry i am still learning verse I have 2 sets of code I have used the first one is
below it works but without the join in progress.

the 2nd code I will add under this code which i found from the forums, my question is how do I add this 2nd code to the first or just create a new verse file and compile and if that is the case just set my join in progress to spawn and let the code work.

publishing my Island everytime I try something is driving me crazy but doing what I have to do Thank you again

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }

elimination_game_device := class(creative_device):

@editable
EndGameDevice : end_game_device = end_game_device{}

# Array of item granters used to grant the weapons
@editable
var WeaponItemGranters : []item_granter_device = array{}

# This is set later, this will be equal to the the number of weapon item_granters in the island
var NumberOfEliminationsToWin : int = 0
# Map container to track players progress. This is how to determine which weapon to award to the player
var AgentMap : [agent]int = map{}

OnBegin<override>()<suspends>:void=
    Sleep(0.0)
    # Can use this variable to scale the number of eliminations needed based on how many item granters there are in the experience
    set NumberOfEliminationsToWin = WeaponItemGranters.Length
    Print("Number of Weapon Item Granters: {WeaponItemGranters.Length}")
    
    # Randomize the order in which the weapons are granted
    

    # Get all the players in the experience
    AllPlayers := GetPlayspace().GetPlayers()
    for (EliminationGamePlayer : AllPlayers):
        if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
            FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) # subscribe to eliminated event
        
        # Add Players to a Map to track progress
        if (set AgentMap[EliminationGamePlayer] = 1) {} 
        
        # Grant the first weapon to each player
        if (FirstItemGranter := WeaponItemGranters[0]):
            FirstItemGranter.GrantItem(EliminationGamePlayer) 

             # Event that handles when a player is eliminated
OnPlayerEliminated(Result:elimination_result):void=
    Print("Player Eliminated")
    EliminatingCharacter := Result.EliminatingCharacter
    if (FortCharacter := EliminatingCharacter?):
        if (EliminatingAgent := FortCharacter.GetAgent[]):
            GrantNextWeapon(EliminatingAgent)

GrantNextWeapon(Agent:agent):void=
                if (var CurrentItemNumber:int = AgentMap[Agent]):
                    if (IsVictoryConditionMet(CurrentItemNumber) = true):
                        EndGame(Agent) # Game has been won
                    else: # Game is not over yet
                        set CurrentItemNumber = CurrentItemNumber + 1
                        if (ItemGranter := WeaponItemGranters[CurrentItemNumber - 1]):
                            ItemGranter.GrantItem(Agent)
                        
                        if (set AgentMap[Agent] = CurrentItemNumber) {}  

                        # Check if the victory condition has been met and return the the result
IsVictoryConditionMet(EliminationNumber:int)<transacts>:logic=
    if(EliminationNumber = NumberOfEliminationsToWin):
        return true
    else:
        return false

EndGame(Agent:agent):void=
            EndGameDevice.Activate(Agent)

2nd code

using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }

player_map := [player]int # This is a type alias!

team_elimination_game := class(creative_device):

@editable
EndGameDevice : end_game_device = end_game_device{}

@editable
var WeaponGranters : []item_granter_device = array{}

@editable
var PlayerSpawners : []player_spawner_device = array{}

@editable
var Sentries : []sentry_device = array{}

var EliminationsToEndGame : int = 0

var Teams : []team = array{}

# Map of Team Maps, where the key is the team and the value is a map of
# player->int key-value pairs
var TeamMap : [team]player_map = map{}  

OnBegin<override>()<suspends> : void =
    set Teams = GetPlayspace().GetTeamCollection().GetTeams()
    set EliminationsToEndGame = WeaponGranters.Length
    Print("Beginning to assign players")

    PopulateTeamsAndPlayers()   

    for (Spawner : PlayerSpawners):
        Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn) # Subscribe to each player spawn pad

    for (Sentry : Sentries):
        Sentry.EliminatedEvent.Subscribe(TestPlayerEliminated) # Subscribe to each Sentry

    # Subscribe to new players joining the game

    GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)

PopulateTeamsAndPlayers() : void =
    Print("Beginning to populate players")
    for (Team : Teams, TeamPlayers := GetPlayspace().GetTeamCollection().GetAgents[Team]):
        var PlayerMap : player_map = map {}
        for (Agent : TeamPlayers, TeamPlayer := player[Agent], FortCharacter := Agent.GetFortCharacter[]): 
            if(set PlayerMap[TeamPlayer] = 0, WeaponTier := PlayerMap[TeamPlayer]): 
                Print("Assigned Player to PlayerMap with Tier {WeaponTier}")
            FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) 
        if(set TeamMap[Team] = PlayerMap):
            Print("Successfully set this team in the TeamMap")

# Handles a new player joining the game
OnPlayerAdded(InPlayer : player) : void =
    Print("A New Player Joined!")
    if:
        FortCharacter := InPlayer.GetFortCharacter[]
    then:
        FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)

# Grants players weapons based on their WeaponTier when they spawn    
OnPlayerSpawn(Agent : agent) : void =
    Print("A player just spawned!")
    if(PlayerTeam := GetPlayspace().GetTeamCollection().GetTeam[Agent]):
        if(TeamPlayer := player[Agent]):
            var WeaponTier : int = 0
            if(TeamMap[PlayerTeam][TeamPlayer]):
                if(set WeaponTier = TeamMap[PlayerTeam][TeamPlayer]):
                    GrantWeapon(option{Agent}, WeaponTier)
            else:
                if (var PlayerMap : player_map = TeamMap[PlayerTeam]):
                    if(set PlayerMap[TeamPlayer] = 0):
                        if(set TeamMap[PlayerTeam] = PlayerMap):
                            GrantWeapon(option{Agent}, WeaponTier)

OnPlayerEliminated(Result : elimination_result) : void =
    Print("A Player was eliminated!")
    Eliminator := Result.EliminatingCharacter
    if (FortCharacter := Eliminator?, EliminatorAgent := FortCharacter.GetAgent[]):
        GiveNextWeapon(EliminatorAgent)

# Allows testing of GiveNextWeapon by spoofing Sentries as Players

TestPlayerEliminated(Agent: ?agent) : void =
    Print("Sentry Down!")
    if(TeamPlayer := Agent?):
        GiveNextWeapon(TeamPlayer)

GiveNextWeapon(EliminatingPlayer : agent) : void =
    Print("Finding a player to promote")
    var WeaponTier : int = 0
    var MaybePlayerToGrant : ?agent = option{EliminatingPlayer} # The player to grant a gun to
    var MaybePlayerTeam : ?team = option{GetPlayspace().GetTeamCollection().GetTeam[EliminatingPlayer]} # The team this player is on

    if(PlayerTeam := MaybePlayerTeam?, set WeaponTier = TeamMap[PlayerTeam][EliminatingPlayer]):
        for(Teammate -> TeammateTier : TeamMap[PlayerTeam], TeammateTier < WeaponTier):
            Print("Found a Teammate with a lower Tier at Tier {TeammateTier}")
            if(set WeaponTier = TeamMap[PlayerTeam][Teammate]):
                set MaybePlayerToGrant = option{Teammate}

    set WeaponTier = WeaponTier + 1
    if(PlayerTeam := MaybePlayerTeam?, PlayerToGrant := player[MaybePlayerToGrant?], set TeamMap[PlayerTeam][PlayerToGrant] = WeaponTier):
        Print("Eliminating Player Tier is now {WeaponTier}")

    if(WeaponTier >= EliminationsToEndGame):
        EndGame(EliminatingPlayer)

    GrantWeapon(MaybePlayerToGrant, WeaponTier)
    
GrantWeapon(InPlayer : ?agent, WeaponTier : int) : void =
    Print("Promoting Player to Tier {WeaponTier}")
    if(ItemGranter := WeaponGranters[WeaponTier], GrantedPlayer := InPlayer?):
        ItemGranter.GrantItem(GrantedPlayer)

EndGame(InPlayer : agent) : void =
    Print("Player reached final Weapon Tier, activating EndGameDevice")
    EndGameDevice.Activate(InPlayer)