Get Agent of the first and second team for Color changing device

I want to add a timed feature for color-changing devices that set the team back and forth using the SetTeam function. I got the player’s agent using the below code, but I want to get the other team’s Agent to switch dynamically. Any idea on how to implement this?

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }

using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
ReactiveColorFloor_device := class(creative_device):
    @editable var ColorFloorTiles : []color_changing_tiles_device = array{}
    # Runs when the device is started in a running game
    var Team : []team = array{}
    var Alternate : logic = false
    OnBegin<override>()<suspends>:void=
       # TODO: Replace this with your code
        for (Row := 0..ColorFloorTiles.Length - 1):
            if (Tile := ColorFloorTiles[Row]):
                if:
                    FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
                    MyAgent := FirstPlayer.GetFortCharacter[].GetAgent[]

                then:
                    Tile.SetTeam(MyAgent)
                    

you can store the last agent in a variable itself, you would most likely have to store it in an optional variable like this:

var MaybeLastAgent: ?agent = false

and then set it like this set MaybeLastAgent = option{Agent} each time it gets switched over.

You can access an optional variable like this if (LastAgent := MaybeLastAgent?): and then do stuff with LastAgent.

1 Like

Hi Thomas,
Thanks for your reply. This takes care of setting the agent, but how would I get the second team’s agent?
For example, this code gets the Agent of the first player. Similarly I need to get the Agent of Team 2,3,etc…

 if:
                    FirstPlayer := Self.GetPlayspace().GetPlayers()[0]
                    MyAgent := FirstPlayer.GetFortCharacter[].GetAgent[]

                then:
                    Tile.SetTeam(MyAgent)

I guess I’m sort of confused by the actual progression of this game mechanic, but basically you’re able to store any amount of agents you want that way, and if you need you could do it in an array where it keeps track of them in a specific order, etc.

Hi @Twin01,
Thanks for your reply. What I’m trying to achieve here is portrayed in the following image

Using color-changing devices, I want the platforms to change Or SetTeam() to their respective team color so only they can activate it and get points.

The problem here is really how do I get both the Blue and Red Team’s Agent via verse code? If you guide me to a proper syntax it would be helpful.

Hey, sounds like GetAgents function on fort_team_collection interface might be what you want.

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