• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[OLD] Detecting teams

Level 12
Joined
Apr 15, 2008
Messages
1,063
Update: Patch 1.1.0
As of Patch 1.1.0, there is a function called "Players on team", which returns player group with players that were in given team in lobby. Following tutorial describes situation before patch, so it should not be used anymore.

Starcraft's player numbering comes with an very annoying issue, that you can hardly detect which players are on which team. If your teams are equivalent, that is not an issue, you can use alliance setting to find out, but what if your teams have different roles in the game?

1. What should (and maybe someday will) work

Using the GUI function "Attribute Player Value" - it can return any player attribute, even team ID. Problem is that GUI has no way of using the actual result of this function - return type is "Attribute Value" (it is actually a string, but blizzard decided to make it more complicated). Now you could compare the returned value to preset values:
  • General - If (Conditions) then do (Actions) else do (Actions)
    • If
      • (Team [2 Teams] value for player 1) == Team 1 [1]
    • Then
      • General - Custom Script: // something
    • Else
  • General - If (Conditions) then do (Actions) else do (Actions)
    • If
      • (Team [2 Teams] value for player 1) == Team 2 [1]
    • Then
      • General - Custom Script: // something else
    • Else
  • General - If (Conditions) then do (Actions) else do (Actions)
    • If
      • (Team [2 Teams] value for player 1) == Team 3 [1]
    • Then
      • General - Custom Script: // something else
    • Else
Galaxy transcription:
JASS:
if ((GameAttributePlayerValue("[bnet:Teams 04 (Mod)/0.0/999]2011", 1) == "2155")) {
        // something
    }
if ((GameAttributePlayerValue("[bnet:Teams 04 (Mod)/0.0/999]2011", 1) == "2155")) {
        // something else
    }
if ((GameAttributePlayerValue("[bnet:Teams 04 (Mod)/0.0/999]2011", 1) == "2155")) {
        // something else
    }

You can see that the editor transcribed all three possible values (Team 1[1], Team 2[1] and Team 3 [1]) to "2155". Not only all team settings have same value, but this value has no meaning at all.

2. What you actually have to do

The actual values returned by "Attribute Player Value" are strings, containing "Tx", where x is team ID (e.g. T1, T2, T3...), so you can easily get the team ID with a substring. Not a problem if you are using Galaxy. Impossible for GUI users, though, since there is no way to convert Attribute value to string (although it is actually string, you can't use it as a string).

So, just create a following function:
  • Get Player Team Id
    • Options: Function
    • Return Type: Integer
    • Parameters
      • param_player = 0 <Integer>
    • Grammar Text: Get Player Team Id(param_player)
    • Hint Text: (None)
    • Custom Script Code
    • Local Variables
      • attribute = (Team [2 Teams] value for player param_player) <Attribute Value>
    • Actions
      • General - Custom Script: return StringToInt( StringSub( lv_attribute,2...
The custom script:
JASS:
return StringToInt( StringSub( lv_attribute,2,3 )  );
What attribute you use doesn't matter, as long as it is one of the team ones. ("Team [2 Teams]", "Team [3 Teams]", "Team [FFA]"... no matter what you choose, it will still return the same values)

Note that if you want to create the whole thing in Galaxy, you'll still need to get the attribute ID("[bnet:Teams 04 (Mod)/0.0/999]2011"). The ID depends on player count ("Teams 04" for 4 player, "Teams 08" for 8 players.....), also the number at the end can change, it's 2011 for "Team [2 Teams]" attribute, 2012 for "Team [3 Teams]", but as I already said above, this setting doesn't matter (it was tested in patch 1.02 I think)
 
Last edited:
Top