SC2Mapster Forums

Development > Triggers

Identifying players as variable arrays

  • 8 posts
    #1 Nov 15, 2012 at 04:34 UTC - 0 likes

    So I have a variable called: Players[]
    With 12 players, it has 12 arrays.

    Heres my code, but not matter which slot I put myself into in the lobby, Im player 1.

            General - Repeat (Actions) 12 times
                Actions
                    Variable - Set PlayerNumber = (PlayerNumber + 1)
                    Variable - Set Players[PlayerNumber] = (Player group(PlayerNumber))
                    UI - Display ("You are player: " + (Text(PlayerNumber))) for Players[PlayerNumber] to Subtitle area
    

    The UI is just for testing purposes. How doesnt this work?
    I just want it so...
    Player[1] = Player 1
    Player[2] = Player 2
    Etc.

    Thanks!

    #2 Nov 15, 2012 at 06:40 UTC - 0 likes

    I'm new at this too, but I think I have the code you want.

    What you do is make a variable ("Selected player = 1 <interger[16]>") Make it an array, 1 dimensions, with a size of 16 and an initial value of 1.

    If you want to pick each player in order, (so they can by text-activated-trigger or button select each other) "Variable - modify selected player [(Owner of (Triggering Unit))]: + 1 will select each player next in order.

    (From Anteep's Empire Builder map)

    Last edited Nov 15, 2012 by KenjI03

    MLP: Spike http://imgur.com/a/hKHq7#10

    #3 Nov 15, 2012 at 07:38 UTC - 0 likes

    @xHydrAx74: Go

    players are 0-15 and are treated as integers

    by default player 0 is neutral and 15 is hostile. These are computer players that can be refereed to as player 0 and player 15 in the game.

    When I make a player variable I make it 0-15. even if all of them are not used. This will make your coding simpler since you avoid most errors when looping through all the players.

    As players enter the lobby they are assigned to open player slots.

    Skype
    KageNinpo = SN

    My Libraries
    DialogLeaderboard & TeamSort

    My Projects
    SPACEWAR Tribute
    Infinite TD

    #4 Nov 15, 2012 at 17:42 UTC - 0 likes

    So is it always based on when the player enters the lobby?

    I have 3 teams of 4, and each team is already set into a variable. Can I use this player group variable to determine specific players?

    Something like...
    Set Player[1] = Player group (player 1 from group 1)
    Set Player[2] = Player group (player 2 from group 1)
    Set Player[3] = Player group (player 3 from group 1)
    Set Player[4] = Player group (player 4 from group 1)

    Set Player[5] = Player group (player 1 from group 2)
    Set Player[6] = Player group (player 2 from group 2)
    etc.

    #5 Nov 15, 2012 at 18:04 UTC - 0 likes

    @xHydrAx74: Go

    Yes that is correct, the first player in the lobby is player 1. You can then run a switch,loop,etc and compare with team the player is on and then add that player accordingly to the playergroup. While your repeat system works i think you may need to learn to use an interger loop properly so that you are not using set each player.

    Last edited Nov 15, 2012 by hobbidude

    When I want your opinion...I'll give it to you!

    http://www.sc2pod.com/achievement.php?id=13361

    #6 Nov 15, 2012 at 23:37 UTC - 0 likes

    I still have yet to figure this out.

    Say the first player who joins the lobby wants to be on team 3, why is he still player 1?

    I want slot 1 = player 1 from group 1
    Slot 2 = player 2 from group 1
    etc.

    #7 Nov 16, 2012 at 00:17 UTC - 0 likes

    My last idea didnt work either (post #4)

    So I tried these, and still no luck.
    I put myself on team 2 or team 3 and start the game. Im still player 1?

            General - Repeat (Actions) 12 times
                Actions
                    Variable - Set PlayerNumber = (PlayerNumber + 1)
                    Player Group - Add player PlayerNumber to Players[PlayerNumber]
                    UI - Display ("You are player: " + (Text(PlayerNumber))) for Players[PlayerNumber] to Subtitle area
    


    And this..

    General - For each integer PlayerNumber from 1 to 12 with increment 1, do (Actions)
    Actions
    Player Group - Add player PlayerNumber to Players[PlayerNumber]

    Last edited Nov 16, 2012 by xHydrAx74
    #8 Nov 16, 2012 at 04:25 UTC - 0 likes

    Judging from what you have written, you will need to do something along the lines of:

    First you need to identify the players.

    Second you need to assign them to an array.

    Third you need to verify the teams.

    Fourth you need to assign them to a team array.

    Each line above can basically be it's own function - may I suggest that you do the following:

    Records are basically like folders, so instead of having 10 variables arrays relating to the player, you can have 1 record (an array) and inside it ten normal variables and it works the same way. It keeps it extremely organised and all it does is move the [Array] number from like Playernumber[15] to Player[15].Number,

    It is better to rewrite your code now than later to include Records - trust me on this.

    Create a Record called "Player Data", then create a Variable Type of Record [Array 15] and call it "Player" and point it to Player Data.

    Inside that record you can create everything relating to the player. So create three integers, one called "position_number" the others called "team_number" and "team_position_number".

    Next create a Record like we did before, this time calling it "Global Data" and a variable [No Array] pointing to it called "Global".

    Create an integer array called "position" [Array 15], create another integer [No Array] call it "amountofplayers".

    Create an integer [No Array] call it "amountofteams". Create an integer [No Array] call it "maxplayers" and set this to (15).

    Next create another Record call it "Team Data and a variable [Array 4] called "Team"

    Create an integer array called "position" [Array 15], create another integer [No Array] call it "amountofplayers".

    Create a text variable and call it "name" (just so we can see the team's name).

    Alrighty here we go ...

    Foreword: Most of this (Like the general idea of how it works) is based off how Tofu does it, however, I use quite a few more records and set quite a more more variables, so I have kept it as simple as possible for OP to learn from.

    First thing you are going to need is to Identify the teams, IE - Setup Teams.

    Create an Action Definition, call it Setup Teams - Add this to Map Intialization (create new action definition, search for setup teams).

    Setup Teams
        Options: Action
        Return Type: (None)
        Parameters
        Grammar Text: Setup Teams()
        Hint Text: (None)
        Custom Script Code
        Local Variables
        Actions
            Variable - Modify Global.amountsofteams: + 1
            Variable - Set Team[Global.amountsofteams].name = "Team Pika"
            Variable - Modify Global.amountsofteams: + 1
            Variable - Set Team[Global.amountsofteams].name = "Team Bulba"
            Variable - Modify Global.amountsofteams: + 1
            Variable - Set Team[Global.amountsofteams].name = "Team Charmander"
            Variable - Modify Global.amountsofteams: + 1
            Variable - Set Team[Global.amountsofteams].name = "Team Squirtle"
    

    Secondly, you are going to need is to check players.

    Create an Action Definition, call it Check Players. - Add this to Map Intialization or Game Start Trigger (anytime after Setup Teams).

    Check Players
        Options: Action
        Return Type: (None)
        Parameters
        Grammar Text: Check Players()
        Hint Text: (None)
        Custom Script Code
        Local Variables
            x = 0 <Integer>
            player = 1 <Integer>
        Actions
                    General - While (Conditions) are true, do (Actions)
                        Conditions
                            player <= Global.maxplayers
                        Actions
                            General - If (Conditions) then do (Actions) else do (Actions)
                                If
                                    (Status of player player) == Playing
                                    (Controller of player player) == User
                                Then
                                    Variable - Modify x: + 1
                                    Variable - Set Global.position[x] = player
                                    Variable - Set Player[player].position_number = x
                                Else
                            Variable - Modify player: + 1
                    Variable - Set Global.amountofplayers = x
    

    So this has basically just identified our players as HUMAN, and assigned them to an array, skipping over any computers it may find. The array is "Global.Position" and the length of the array is "Global.Amountofplayers".

    Next we want to set the teams - there are many different ways to do this and I would suggest making each way it's own Action Definition so that you can switch them later if you add in game mode options. Alternatively you may see a similarity between this and the check players function, this is because they are basically doing a different thing in the same way. You could add this to that function but you wouldn't be able to add in more game modes (like Random Teams) later on.

    Add this after the Check Players function.

    Default Teams
        Options: Action
        Return Type: (None)
        Parameters
        Grammar Text: Default Teams()
        Hint Text: (None)
        Custom Script Code
        Local Variables
            team = 1 <Integer>
        Actions
            General - While (Conditions) are true, do (Actions)
                Conditions
                    team <= Global.amountsofteams
                Actions
                    General - If (Conditions) then do (Actions) else do (Actions)
                        If
                            (Number of players in (Players on team team)) >= 1
                        Then
                            Player Group - Pick each player in (Players on team team) and do (Actions)
                                Actions
                                    General - If (Conditions) then do (Actions) else do (Actions)
                                        If
                                            (Controller of player (Picked player)) == User
                                            (Status of player (Picked player)) == Playing
                                        Then
                                            Variable - Modify Team[team].amountsofplayers: + 1
                                            Variable - Set Team[team].position[Team[team].amountsofplayers] = (Picked player)
                                            Variable - Set Player[(Picked player)].team_number = team
                                            Variable - Set Player[(Picked player)].team_position_number = Team[team].amountsofplayers
                                        Else
                        Else
                    Variable - Modify team: + 1
    

    This would create an array of players for each team. If you wanted to create a Player Group then you would create one inside the Team Data record, and then EMPTY it as the first thing inside the Team Loop and then add each the player to it where it sets all the player's data.

    You would call this through a LOOP.

    Like:

    Set loop_team = 1
          While loop <= Global.Amountofteams
                Set loop_player = 1
                    While loop <= Team[loop_team].amountofplayers
                        Then create unit for Team[loop_team].position[loop_player] at Center of Map
                    Modify loop_player + 1
                Modify loop_team + 1
    

    If you wanted to create units at the center of a team's base you would create a variable inside the team data record of type region, set the region in Setup Team thing (under the name), and then you could do Create Unit for Team[loop_team].position[loop_player] at center of region Team[loop_team].region

    Once set up like this, and you understand how it works, your possibilities are endless.

    Last edited Nov 16, 2012 by DogmaiSEA
  • 8 posts

You must login to post a comment. Don't have an account? Register to get one!