No weapon being granted - Team Elimination Game tutorial

Hello everyone. I have very little experience programming and I’m having a hard time figuring out what’s going wrong.

I’m stuck at this step of the Team Elimination Game - to be more precise, I finished all the steps from ’ 4. Tracking Players Using Maps’ and stopped before starting ’ Mapping Teams of Players’.

The issue is that no weapon is being granted on respawn.

I already erased my code and started it over from scratch three times, but I can’t figure out what I’m doing wrong.

On the previous step/page (this one) everything worked pretty well.

The last message that shows up on the console is “A Player just spawned!” but that doesnt mean much since it can be pretty much anything besides the first lines.

Here’s the code:

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

team_elimination_game := class(creative_device):
    var PlayerMap : [player]int = map{} # This stores a reference to each player and their weapon tier

    @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{}

    OnPlayerSpawn(InPlayer : agent) : void = 
        Print("A Player just spawned!")
        if(WeaponTier := PlayerMap[InPlayer]):
            GrantWeapon(option{InPlayer}, WeaponTier)
            Print("Spawned Player was granted a gun of tier {WeaponTier}")

    GrantWeapon(InPlayer : ?agent, WeaponTier : int) : void=
        Print("Granting Player a weapon of Tier {WeaponTier}")
        if(ItemGranter := WeaponGranters[WeaponTier], GrantedPlayer := InPlayer?):
            ItemGranter.GrantItem(GrantedPlayer)

    PopulateTeamsAndPlayers() : void=
        Print("Beginning to populate players")
        AllPlayers := GetPlayspace().GetPlayers()
        for (Agent : AllPlayers, TeamPlayer := player[Agent], FortCharacter := TeamPlayer.GetFortCharacter[]):
            if(set PlayerMap[TeamPlayer] = 0, WeaponTier := PlayerMap[TeamPlayer]):
               Print("Assigned Player to PlayerMap with Tier {WeaponTier}")
               FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated) 

    OnPlayerEliminated(Result : elimination_result) : void=
        Print("A Player was eliminated!")

    OnBegin<override>()<suspends> : void =
        # Get all the players
        set Teams = GetPlayspace().GetTeamCollection().GetTeams()
        set EliminationsToEndGame = WeaponGranters.Length
        Print("Number of eliminations to end game is {EliminationsToEndGame}")
        for (Spawner : PlayerSpawners):
            Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn)   # Subscribe to each player spawn pad

I have only just started looking at verse so I have no idea, I have only just read the beginning docs, it says the OnBegin<> part should be put above the code that is meant to run during gameplay. Maybe it should be above the OnPlayerSpawn bit.

Hey! Thank you for the reply.

In this case, the code that’s outside OnBegin() are mainly functions. I even tried your suggestion to see how it goes, but it create scope issues (things that can’t be acessed/placed on certain parts of the code) and the whole script doesn’t even compile

Inside OnBegin() we have OnPlayerSpawn(). This function is called and then it should start triggering the other ones, but this is not happening and I have no idea why XD

so the players weapons disappear when they respawn?
try setting islandsettings > user options-game settings > eliminated player’s items to “keep”.

Not really. Using the code as it’s, the first weapon is never granted - nor the Print(s) that should follow is sent. Just in case, it was granting the weapon as shown in the previous example/exercise.

It basically stops on the Print below - maybe because the next condition is not met? I’m really not sure yet:

    OnPlayerSpawn(InPlayer : agent) : void = 
        Print("A Player just spawned!")
        if(WeaponTier := PlayerMap[InPlayer]):
            GrantWeapon(option{InPlayer}, WeaponTier)

Hello everyone. I was able to solve the issue and it was really simple.

The documentation doesn’t really say this, but you need to call PopulateTeamsAndPlayers() on OnBegin(). This makes total sense since at the step I got stuck we remove the previous hardcoded WeaponTier and improve a function to do handle that by itself.

What helped me to understand this was this dude’s video: Learn UEFN and Verse in Fortnite Beginner Course (Creative 2.0) - YouTube

He’s teaching basically the same thing/code, but does not include the “Team” part - and he’s very good at explaining things.

I still find the syntax of Verse very confusing on ifs since we jump into something with a lot of pre-made and complex code - I don’t know, it’s a weird feeling to have since it’s kinda aimed at noobies - but after a few days with it, it’s becoming a bit clearer.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.