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 { / }
using { / }
using { / }
using { / }
using { / }
using { / }
using { / }

elimination_game_device := class(creative_device):

EndGameDevice : end_game_device = end_game_device{}

# Array of item granters used to grant the weapons
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{}

    # 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]):

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

                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]):
                        if (set AgentMap[Agent] = CurrentItemNumber) {}  

                        # Check if the victory condition has been met and return the the result
    if(EliminationNumber = NumberOfEliminationsToWin):
        return true
        return false


2nd code

using { / }
using { / }
using { / }
using { / }
using { / }

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

team_elimination_game := class(creative_device):

EndGameDevice : end_game_device = end_game_device{}

var WeaponGranters : []item_granter_device = array{}

var PlayerSpawners : []player_spawner_device = array{}

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")


    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


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}")
        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!")
        FortCharacter := InPlayer.GetFortCharacter[]

# 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(set WeaponTier = TeamMap[PlayerTeam][TeamPlayer]):
                    GrantWeapon(option{Agent}, WeaponTier)
                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[]):

# Allows testing of GiveNextWeapon by spoofing Sentries as Players

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

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):

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

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