How to do different logic based on a player's team

I’m trying to get my head around what to do if I want to vary what happens based on what team a player is on. The example I’m working with right now is:

  1. Player Captures a Capture Area
  2. If Player was on Team 1 do THIS, if Player was on Team 2 do THIS
1 Like

Add variable of the players current team and just change behavior based on that variable. Simple as that.

Your question is a bit unclear, and therefore better help cannot be provided. Be more specific on what do you want to change.

1 Like

What I was trying to do was take a variable and increment it whenever the corresponding team captured a zone. I ended up arriving at this with some help from the FNC discord:

DoThisFunction(Player:agent, AreaCaptured:int):void=
    if:
        Teams := GetPlayspace().GetTeamCollection()
        Team := Teams.GetTeam[Player]
        TeamIndex := Teams.GetTeams().Find[Team]
        TeamIndex = 0
    then:
        set TeamAOwned += 1

This looks for Team 1 and increments that variable accordingly. Appreciate the point in the right direction earlier as well!

You first need logic to have some zone captured. And when zone is captured, do it in a tick fucntion

create field variable capturedZoneBonus

void Tick() {
   if (captured_some_zone) { capturedZoneBonus++ }
}
2 Likes

I’m interested in the results from this post.
@Twin01 did @Bojann 's solution help you resolve the issue?

Curious minds want to know :slight_smile:

The last post I had made was actually the solution! I have it saved with some comments so I’ll repost it here, but this totally works:

DoThisFunction(Player:agent):void=
        if:
            Teams := GetPlayspace().GetTeamCollection() #creates a collection of teams in the game currently.
            Team := Teams.GetTeam[Player] #Gets the current team number of the instigating player.
            TeamIndex := Teams.GetTeams().Find[Team] #Converts that number to an int.
            TeamIndex = 0 #Compares the player's team number to the one you are looking for (0 is Team 1 in this case)
        then:
            #Do Stuff based on Team 1

Let me know if you have questions (and this could also not be the best way to do it so feedback welcome)

1 Like

That’s awesome! Thanks so much for reposting!

1 Like

If this creates collection, make sure you don’t do it in Tick(). Optimize it a bit in order to create this collection on event based actions.

1 Like