Gun Game Script

FYI for all new UEFN Beta members, this is very outdated and I am working on uploading a gun game device full of features soon!

I wanted to share this here instead of inside the Creations area since it’s not actually feasible yet without access to player info.

This script would rely on checking the number of eliminations a player has without needing to add in countless Tracker Devices. (Currently storing a DEBUG variable as my elims)

The Setup:

  • Custom UEFN Device
    • Elimination Manager
    • End Game Device
    • Array of Item Granters

With the granters stored in an array, the number of guns/eliminations needed to win is flexible since it’s based on the length of the array. (attach 5 item granters, the kills to win = 6. Attach 20 and the kills to win = 21, etc)

Very much looking forward to the day where we’ll gain more access to simple things like elimination count! But for now feel free to check out the script in it’s current state, I’ll update it once the API is out :slight_smile:

using { /Verse.org/Native }
using { /Verse.org/Verse }
using { /Verse.org/Simulation }
using { /Fortnite.com/Devices}
using { /EpicGames.com/Temporary/Diagnostics }

log_gun_game_device:=class(log_channel){}

# This is a Verse-authored creative device that can be placed in a level
# 
# Getting started:
#   https://www.epicgames.com/fortnite/en-US/creative/docs/uefn/programming-with-verse-in-unreal-editor-for-fortnite
#
gun_game_device := class<concrete>(creative_device):
    Logger:log := log{Channel:=log_gun_game_device}

    # This will be set on gamestart based on the number of item granters added to the array
    var EliminationsToWin : int := 0

    # Future API should be able to grab player's current elim upon each elim
    # For now I'm just setting this as a variable for testing purposes
    var DEBUG_elims : int := 0

    @editable
    DEBUG_BUTTON : button_device := button_device{}

    # Devices To Be Added

    #Used to end the round when a player has gotten a elim with the last gun in the item granter array
    @editable
    EndGameDevice :  end_game_device := end_game_device{}

    #Used to track each time that a player gets an elimination
    @editable
    EliminationManager :  elimination_manager_device := elimination_manager_device{} 

    #Used to add as many weapons you want players to cycle through in the gun game
    @editable
    WeaponGranters : []item_granter_device := array{}

    
    

    # Runs when this creative_device is started in a running game
    OnBegin<override>()<suspends>:void=
        # Replace this with your code
        Logger.Print("Verse device started!", ?Level := log_level.Warning)

        #set num of elims to win = to the number of granters in the array.
        set EliminationsToWin = WeaponGranters.Length
        Logger.Print("ELIMS: {DEBUG_elims}", ?Level := log_level.Warning)
        Logger.Print("ELIMS-TO-WIN: {EliminationsToWin}", ?Level := log_level.Warning)
        

        DEBUG_BUTTON.InteractedWithEvent.Subscribe(FakeElim)

        # EliminationManager.EliminationEvent.Subscribe(HandleElim)
        EliminationManager.EliminationEvent.Subscribe(FakeElim)

    FakeElim(Player:player):void =
        Logger.Print("ELIMS: {DEBUG_elims}", ?Level := log_level.Warning)
        set DEBUG_elims += 1 #add one fake kill
        Logger.Print("ELIMS: {DEBUG_elims}", ?Level := log_level.Warning)

        #pretend elim manager event happened
        if (DEBUG_elims > EliminationsToWin):
            Logger.Print("WINNER!", ?Level := log_level.Warning)
            EndGameDevice.Activate(Player)
        else:
            if (GranterExists := WeaponGranters[DEBUG_elims - 1]):
                GranterExists.GrantItem(Player)
            else:
                Logger.Print("Cannot find granter = elims", ?Level := log_level.Warning)


# Currently unused, but after API release this is how this might work.
   # HandleElim(Player:player):void = 
        # Logger.Print("Elimination", ?Level := log_level.Warning)

        # Future API hopefully will work... -1 for use in array 
        # var elimCount : int := Player.getEliminations() - 1

        # if (elimCount >= EliminationsToWin):
        #     EndGameDevice.Activate(Player)

       # if (DEBUG_elims > EliminationsToWin ):
            # Logger.Print("WINNER!", ?Level := log_level.Warning)
            # EndGameDevice.Activate(Player)
       # else:
           # if (GranterExists := WeaponGranters[DEBUG_elims - 1]):
              # GranterExists.GrantItem(Player)
           # else:
               # Logger.Print("Cannot find granter = elims", ?Level := log_level.Warning)
          
        

    <#
    # Runs when this creative_device is stopped or the game ends
    OnEnd<override>():void=
        # Uncomment this function, then replace this with your code
        Logger.Print("Verse device stopped!")
    #>
7 Likes

Fantastic work!

Thank you for sharing this, it has really helped with the Verse learning process.

I can’t tell but did Epic put the API in or not?