Assistance with Respawn Logic Based on Capture Areas and Zones & Getting Teams

Hello,

I am working on a respawn system where the ability to respawn is determined by the capture areas or zone points (A, B, C). The respawn status is based on whether a point is captured or not, and I need help with integrating this logic into my existing code. Additionally, I am encountering an issue with obtaining the teams, and I am not sure how to fix this error.

Here is the script I am working with:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/Characters }
using { /Fortnite.com/FortPlayerUtilities }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Teams }

respawn_manager := class(creative_device):
    var CaptureWeightOfThisPointA:int = 0
    var PlayerWeightOfThisPointA:float = 0.0
    var WeightOfPoint:float = 0.0
    WeightForEachPlayer:float = 0.5
    TeamCollectionRef:fort_team_collection

    @editable SpawnPoint1I : player_spawner_device = player_spawner_device{}
    @editable SpawnPoint1 : player_spawner_device = player_spawner_device{}
    @editable ButtonTeam1I : button_device = button_device{}
    @editable ButtonTeam1A : button_device = button_device{}
    @editable CapturePointA : capture_area_device = capture_area_device{}
    @editable LargeZoneA : player_counter_device = player_counter_device{}

    GetTeamDirectionOfAgent<private>(MyAgent:agent)<transacts>:int=
        if (FirstTeam := TeamCollectionRef.GetTeams()[0]):
            if (TeamCollectionRef.IsOnTeam[MyAgent, FirstTeam]):
                return 1
        return -1

    CaptureA(MyAgent:agent):void=
        set CaptureWeightOfThisPointA = GetTeamDirectionOfAgent(MyAgent)

    CountedZoneA(MyAgent:agent):void=
        set PlayerWeightOfThisPointA = PlayerWeightOfThisPointA + (GetTeamDirectionOfAgent(MyAgent) * WeightForEachPlayer)
    RemovedZoneA(MyAgent:agent):void=
        set PlayerWeightOfThisPointA = PlayerWeightOfThisPointA - (GetTeamDirectionOfAgent(MyAgent) * WeightForEachPlayer)

    OnBegin<override>()<suspends>:void=
        BeginPlayEventSubscriptions()

        ButtonTeam1I.InteractedWithEvent.Subscribe(ButtonInteractedHandler)
        ButtonTeam1A.InteractedWithEvent.Subscribe(ButtonSpawn1A)

        CapturePointA.ControlChangeEvent.Subscribe(CaptureA)
        LargeZoneA.CountedEvent.Subscribe(CountedZoneA)
        LargeZoneA.RemovedEvent.Subscribe(RemovedZoneA)

    BeginPlayEventSubscriptions<private>():void=
        {
        TeamCollectionRef := Self.GetPlayspace().GetTeamCollection()
        }

    ButtonInteractedHandler(MyAgent:agent):void=
        if(FortCharacter := Agent.GetFortCharacter[]):
            FortCharacter.Damage(150.0)
            Agent.Respawn(vector3{X := 2570.0, Y := -6180.0, Z := 2690.0}, IdentityRotation())

    ButtonSpawn1A(MyAgent:agent):void=
        set WeightOfPoint = PlayerWeightOfThisPointA + PlayerWeightOfThisPointA
        if(WeightOfPoint >= 0):
            if(FortCharacter := Agent.GetFortCharacter[]):
                FortCharacter.Damage(150.0)
                Agent.Respawn(vector3{X := 2079.0, Y := 980.0, Z := 2680.0}, IdentityRotation())

The goal is that players will respawn only in certain zones based on whether the corresponding capture area or point (A, B, or C) is owned by the team. However, I’m unsure about how to implement the condition for respawning based on these capture areas. Additionally, I am encountering an error when trying to get the teams using the line:

TeamCollectionRef := Self.GetPlayspace().GetTeamCollection()
TeamCollectionRef:fort_team_collection
	# If Team 1, we return 1.  If Team 2, we return -1.
GetTeamDirectionOfAgent<private>(MyAgent:agent)<transacts>:int=
      if (FirstTeam := TeamCollectionRef.GetTeams()[0]):
          if (TeamCollectionRef.IsOnTeam[MyAgent, FirstTeam]):
              return 1
      return -1

I am not sure how to properly get the teams, and the error message suggests there is an issue with this approach.

Could you please guide me on how to fix these issues and implement the respawn logic based on the capture areas and teams?

Thank you for your help!

Best regards,

Sorry I cant help with the verse part, but I would use each capture zones event to both enable the correct spawns and disable all the other spawns (even if they’re already disabled).

I think that would mean either making a heap of @editable spawn point entries or bypass that by using a turn on trigger and a turn off trigger per set of spawns, which would probably be better if you have something like 16 players per team.
2 triggers x 2 teams x 3 capture zones = 12 editables by trigger
vs
3 captures zones x 2 teams x 16 players = 96 editables by player spawner

there is probably a better way to achieve this though… and I’m a verse noob

1 Like

This script a bit is too much to take all in at once, but for starters You should remove whatever this function is, it just retrieves the teamcollection and then does nothing,doesn’t save it anywhere or nothing

Also you can’t just make values without setting them. Since you can’t define fort_team_collection, you can just paste TeamCollectionRef:=GetPlayspace().GetTeamCollection() at the start of every function that uses it

2 Likes

Thank you for your reply.
I have rewritten the code, but have encountered the following error:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation/Tags }
using { /Fortnite.com/Characters}
using { /Fortnite.com/FortPlayerUtilities }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Teams }

respawn_manager := class(creative_device):
    var CaptureWeightOfThisPointA:int = 0
    var PlayerWeightOfThisPointA:float = 0.0
    var WeightOfPoint:float = 0.0
    WeightForEachPlayer:float = 0.5
    TeamCollectionRef:=GetPlayspace().GetTeamCollection()
    



    @editable SpawnPoint1I : player_spawner_device = player_spawner_device{}
    @editable SpawnPoint1 : player_spawner_device = player_spawner_device{}

    @editable ButtonTeam1I : button_device = button_device{}
    @editable ButtonTeam1A : button_device = button_device{}

    @editable CapturePointA : capture_area_device = capture_area_device{}

    @editable LargeZoneA : player_counter_device =player_counter_device{}

	# If Team 1, we return 1.  If Team 2, we return -1.
    GetTeamDirectionOfAgent<private>(MyAgent:agent)<transacts>:int=
        if (FirstTeam := TeamCollectionRef.GetTeams()[0]):
            if (TeamCollectionRef.IsOnTeam[MyAgent, FirstTeam]):
                return 1
        return -1
                
    
    CaptureA(MyAgent:agent):void=
        set CaptureWeightOfThisPointA = GetTeamDirectionOfAgent(MyAgent)
        
    # Shift player weighting of point as players enter or leave
    CountedZoneA(MyAgent:agent):void=
        set PlayerWeightOfThisPointA = PlayerWeightOfThisPointA + (GetTeamDirectionOfAgent(MyAgent) * WeightForEachPlayer)
    RemovedZoneA(MyAgent:agent):void=
        set PlayerWeightOfThisPointA = PlayerWeightOfThisPointA - (GetTeamDirectionOfAgent(MyAgent) * WeightForEachPlayer)

    OnBegin<override>()<suspends>:void=
        ButtonTeam1I.InteractedWithEvent.Subscribe(ButtonInteractedHandler)
        ButtonTeam1A.InteractedWithEvent.Subscribe(ButtonSpawn1A)

        CapturePointA.ControlChangeEvent.Subscribe(CaptureA)
        LargeZoneA.CountedEvent.Subscribe(CountedZoneA)
        LargeZoneA.RemovedEvent.Subscribe(RemovedZoneA)

    ButtonInteractedHandler(Agent:agent): void=
        if(FortCharacter := Agent.GetFortCharacter[]):
            FortCharacter.Damage(150.0) 
            Agent.Respawn(vector3{X := 2570.0, Y := -6180.0, Z := 2690.0},IdentityRotation())
    ButtonSpawn1A(Agent:agent): void=
        set WeightOfPoint = PlayerWeightOfThisPointA + PlayerWeightOfThisPointA
        if(WeightOfPoint => 0):
            if(FortCharacter := Agent.GetFortCharacter[]):
                FortCharacter.Damage(150.0) 
                Agent.Respawn(vector3{X := 2079.0, Y := 980.0, Z := 2680.0},IdentityRotation())
Script error 3547: Data definition TeamCollectionRef at class scope must specify a value domain.
Script error 3582: Divergent calls (calls that might not complete) cannot be used to define data-members.
Script error 3502: Function literals are not yet implemented.

TeamCollectionRef:=GetPlayspace().GetTeamCollection()

Is it an error that the domain is added to the individual parts?
Please let me know.

Thanks for your replies.
I’ll try it if it’s difficult.

1 Like

TeamCollectionRef:=GetPlayspace().GetTeamCollection() Needs to be at the start of every function that uses the team collection, you can’t just have it as on the class unless you use optionals Option | Unreal Editor for Fortnite Documentation | Epic Developer Community

1 Like

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