Assign a random class/item granter to spawn pad

Hey!

I’m 3 weeks into learning UEFN and Verse - so far I’ve made a Gun Game mode and box fight mode.

I’m trying to make an Arena-based FFA game where 16 players are randomly assigned loadouts. I tried using the class device + item granter device in UEFN but faced issues (spawn pads set to random, but when playtesting with 1 other we always landed on pad 1 and 2; therefore only receiving the first 2 of 16 possible loadouts)

I’m trying to create this in Verse where the item granter index is shuffled and then re-assigned to the spawning player. At the moment, I’m consistently spawning in with item granter at first index

Here is my code:

game_manager := class(creative_device):
    
    var PlayerMap : [player]int = map {}

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

    
    OnBegin<override>()<suspends>:void=
        InitPlayers()        
        #Randomise order of weapon granters
        set WeaponGranters = Shuffle(WeaponGranters)

    InitPlayers() : void=
        AllPlayers := GetPlayspace().GetPlayers()
        for (Player : AllPlayers, FortCharacter := Player.GetFortCharacter[]):
            if (set PlayerMap[Player] = 0, WeaponTier := PlayerMap[Player]):
                GrantWeapon(Player, WeaponTier)
        
    GrantWeapon(Player : player, WeaponTier: int) : void=
        # Print("Attempting to grant weapon")
        if (ItemGranter := WeaponGranters[WeaponTier]):
            # Print("Granted item to player")
            ItemGranter.GrantItem(Player)

Please help! I’ve spent hours trying to fix this and will deeply appreciate any solutions

1 Like

i think what you are trying to accomplish according to your logic your code is just slightly out of order. currently you shuffle the weapon granters array once, after you already initialize all of the players and grant their weapons

Maybe try to adjust Init players and place your Shuffle here :

 InitPlayers() : void=
        AllPlayers := GetPlayspace().GetPlayers()
        for (Player : AllPlayers, FortCharacter := Player.GetFortCharacter[]):
--------set WeaponGranters = Shuffle(WeaponGranters)

            if (set PlayerMap[Player] = 0, WeaponTier := PlayerMap[Player]):
                GrantWeapon(Player, WeaponTier)

gotta sleep now, sorry if it doesnt work, good luck with your project

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