• 🏆 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!

need trigger to find WHO IS WINNER and Ranking

Status
Not open for further replies.
Level 7
Joined
Sep 19, 2020
Messages
190
Hi, I'm working on my map and it is done now I need a trigger to find who is the winner

My Map Detail
12 Player, 4 Team, each team have 3 player
10 Round game
I use multiboard
KillDieFlag
Human teamvar Kill(0)var Die(0)var Flag(0)
orc teamvar Kill(1)var Die(1)var Flag(1)
undead teamvar Kill(2)var Die(2)var Flag(2)
night elf teamvar Kill(3)var Die(3)var Flag(3)
and another variable I called Win(4)(for each win round score)
now after 10 round playing I need to find who is...
Rank 1: (winner)
Rank 2
Rank 3
Rank 4
by using this formula --> (Win*100) + (Flag*10) + (Kill) - (Die*3) = Team score


NOW NEED TRIGGER TO FIND WHO IS WINNER????

TNX FOR HELP...
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
This is assuming that you already have all of the wins, kills, deaths, and flags tracked for each team.

First, create a new Integer array called TeamScore and use your formula to calculate and track each team's total score:
TeamScore[0] = Human's total score, TeamScore[1] = Orc's total score, etc.

Then you compare these TeamScore variables to one another and set the Ranks using a Sorting algorithm.
This one is GUI friendly and has a simple to follow example: Merge Sort [GUI Friendly] v1.01

Merge Sort will take your TeamScore values and sort them in a variable array called MSort_Indices.
So MSort_Indices[1] = Rank 1 (Winner), MSort_Indices[2] = Rank 2, etc.
 
Level 7
Joined
Sep 19, 2020
Messages
190
This is assuming that you already have all of the wins, kills, deaths, and flags tracked for each team.

First, create a new Integer array called TeamScore and use your formula to calculate and track each team's total score:
TeamScore[0] = Human's total score, TeamScore[1] = Orc's total score, etc.

Then you compare these TeamScore variables to one another and set the Ranks using a Sorting algorithm.
This one is GUI friendly and has a simple to follow example: Merge Sort [GUI Friendly] v1.01

Merge Sort will take your TeamScore values and sort them in a variable array called MSort_Indices.
So MSort_Indices[1] = Rank 1 (Winner), MSort_Indices[2] = Rank 2, etc.
so if I use merge sort, when 2 teams score as same what's happening?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
It should still index the tied values in the array. I don't know how it handles that exactly but the result should be a filled out array with higher values always coming before lower values (if using Descending order). Whether a case of a tie means that let's say Orcs are the first in the array before Humans despite having the same score would depend on how the code works, but that's not really important in this case.

It's up to you to check for ties after the sorting is complete. To do so you could do something like this:

Create a boolean array called Tied and an Integer called TieCount.

Then Loop over MSort_Indicies.

For Integer A from 2 to 4 -> If MSort_Indicies[1] Equal to MSort_Indicies[A] then Set Tied[A] = True and Set TieCount = TieCount + 1.

After that you can check for ties.

If TieCount > 0 then do:
For Integer A from 2 to 4 -> check if Tied[A] is Equal to True -> If it is then do whatever you need to do (change text, multiboard, rank position, etc).

I suppose you really only need the first Loop and could get rid of TieCount/Tied. But maybe you want to store the ties for some later use or something.

In your case you could change the Rank text if ties are detected. For example, if Human/Orc/Undead all tied for first you could display it like this:
Rank 1: Human (Tied)
Rank 1: Orc (Tied)
Rank 1: Undead (Tied)
Rank 2: Night Elf

Edit: On second thought, Player Groups would be more useful for storing the Ranks, especially in the case of Ties. With a Player Group you can easily Add players to their proper Rank, so using my above example Human would be added to RankGroup[1], Orc to RankGroup[1], Undead to RankGroup[1], and Night Elf to RankGroup[2]. Then you can take advantage of Pick Every Player and do something like give Victory to each player in RankGroup[1] and Defeat to each player in RankGroup[2-4].
 
Last edited:
Level 7
Joined
Sep 19, 2020
Messages
190
Hi again I make a trigger and it is work but how to make the win and lose I use Player - Victory but it is not work
  • Team Score And Ranking
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 0 to 3, do (Actions)
        • Loop - Actions
          • Set TeamScore[(Integer A)] = ((((Win[(Integer A)] x 100) + (Flag[(Integer A)] x 10)) + Kill[(Integer A)]) - (Die[(Integer A)] x 3))
          • Set TeamRank[(Integer A)] = (Integer A)
      • For each (Integer A) from 0 to 3, do (Actions)
        • Loop - Actions
          • For each (Integer B) from ((Integer A) + 1) to 3, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TeamScore[(Integer A)] Less than TeamScore[(Integer B)]
                • Then - Actions
                  • Set TempScore = TeamScore[(Integer A)]
                  • Set TeamScore[(Integer A)] = TeamScore[(Integer B)]
                  • Set TeamScore[(Integer B)] = TempScore
                  • Set TempRank = TeamRank[(Integer A)]
                  • Set TeamRank[(Integer A)] = TeamRank[(Integer B)]
                  • Set TeamRank[(Integer B)] = TempRank
                • Else - Actions
      • Game - Display to (All players) the text: |cffffff00Rank:|r
      • Game - Display to (All players) the text: (|cffffff00# 1: + (TeamName[TeamRank[0]] + |r))
      • Game - Display to (All players) the text: (|cffffff00# 2: + (TeamName[TeamRank[1]] + |r))
      • Game - Display to (All players) the text: (|cffffff00# 3: + (TeamName[TeamRank[2]] + |r))
      • Game - Display to (All players) the text: (|cffffff00# 4: + (TeamName[TeamRank[3]] + |r))
      • Player Group - Pick every player in Team[TeamRank[0]] and do (Actions)
        • Loop - Actions
          • Game - Victory (Picked player) (Show dialogs, Show scores)
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in Team[TeamRank[(Integer A)]] and do (Actions)
            • Loop - Actions
              • Game - Defeat (Picked player) with the message: Defeat!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
1) Group arrays need to be initialized. You MUST do this inside of the variable editor. So set the Array size to 4 in this case.

2) For ties (when 2+ teams have the same score) you can use that Boolean method I described.

So if Teams[1-3] are Tied with Team[0] then Set their Tied[Team Number] to True.

Then you can check this Tied boolean when Picking Every Player:
If Tied[TeamRank[Integer A]] Equal to True then Victory (Picked player) else Defeat (Picked player).

Alternatively, you could just Add the Tied players to Team[0] (Winning Team) instead of using the Boolean. In the case of your trigger you wouldn't even have to Remove them from their previous Team because they'd be given Victory before Defeat.
 
Last edited:
Level 7
Joined
Sep 19, 2020
Messages
190
1) Group arrays need to be initialized. You MUST do this inside of the variable editor. So set the Array size to 4 in this case.
it is 4, now fix it, the problem is another think
It should still index the tied values in the array. I don't know how it handles that exactly but the result should be a filled out array with higher values always coming before lower values (if using Descending order). Whether a case of a tie means that let's say Orcs are the first in the array before Humans despite having the same score would depend on how the code works, but that's not really important in this case.

It's up to you to check for ties after the sorting is complete. To do so you could do something like this:

Create a boolean array called Tied and an Integer called TieCount.

Then Loop over MSort_Indicies.

For Integer A from 2 to 4 -> If MSort_Indicies[1] Equal to MSort_Indicies[A] then Set Tied[A] = True and Set TieCount = TieCount + 1.

After that you can check for ties.

If TieCount > 0 then do:
For Integer A from 2 to 4 -> check if Tied[A] is Equal to True -> If it is then do whatever you need to do (change text, multiboard, rank position, etc).

I suppose you really only need the first Loop and could get rid of TieCount/Tied. But maybe you want to store the ties for some later use or something.

In your case you could change the Rank text if ties are detected. For example, if Human/Orc/Undead all tied for first you could display it like this:
Rank 1: Human (Tied)
Rank 1: Orc (Tied)
Rank 1: Undead (Tied)
Rank 2: Night Elf

Edit: On second thought, Player Groups would be more useful for storing the Ranks, especially in the case of Ties. With a Player Group you can easily Add players to their proper Rank, so using my above example Human would be added to RankGroup[1], Orc to RankGroup[1], Undead to RankGroup[1], and Night Elf to RankGroup[2]. Then you can take advantage of Pick Every Player and do something like give Victory to each player in RankGroup[1] and Defeat to each player in RankGroup[2-4].
can u explain by my trigger it is for Merge sort (I'm confused):peasant-confused:
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Here's what I came up with using Merge Sort. Note that some of these Variables like the Users, Team, and TeamNumber should be set beforehand like during Map Initialization or after teams are decided if you do that ingame. These variables are meant to keep track of the players as a whole and their individual Teams (human, orc, undead, night elf).
  • Demo
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Keep track of each team: --------
      • Player Group - Add Player 1 (Red) to Team[1]
      • Player Group - Add Player 2 (Blue) to Team[2]
      • Player Group - Add Player 3 (Teal) to Team[3]
      • Player Group - Add Player 4 (Purple) to Team[4]
      • -------- Keep track of all players that are part of a team: --------
      • Player Group - Add Player 1 (Red) to Users
      • Player Group - Add Player 2 (Blue) to Users
      • Player Group - Add Player 3 (Teal) to Users
      • Player Group - Add Player 4 (Purple) to Users
      • -------- Keep track of each player's Team Number. Index = Player Number and Value = Team Number. So TeamNumber[2] means Blue is an Orc (1 = Human, 2 = Orc, 3 = Undead, 4 = Night Elf) --------
      • Set VariableSet TeamNumber[1] = 1
      • Set VariableSet TeamNumber[2] = 2
      • Set VariableSet TeamNumber[3] = 3
      • Set VariableSet TeamNumber[4] = 4
      • -------- Keep track of each team's total score ( you would use your formula here for kills/deaths/flags ) --------
      • Set VariableSet TeamScore[1] = 5
      • Set VariableSet TeamScore[2] = 15
      • Set VariableSet TeamScore[3] = 20
      • Set VariableSet TeamScore[4] = 10
      • -------- The Merge Sort system needs to know these Team Scores. It uses a Real variable so in this case let's convert that to an Integer: --------
      • Set VariableSet MSort_Values[1] = (Real(TeamScore[1]))
      • Set VariableSet MSort_Values[2] = (Real(TeamScore[2]))
      • Set VariableSet MSort_Values[3] = (Real(TeamScore[3]))
      • Set VariableSet MSort_Values[4] = (Real(TeamScore[4]))
      • -------- Ascending = Lowest value is first. Descending = Highest value is first. --------
      • Set VariableSet MSort_Ascending = False
      • Set VariableSet MSort_StartIndex = 1
      • Set VariableSet MSort_EndIndex = 4
      • Trigger - Run Merge Sort <gen> (checking conditions)
      • -------- --------
      • -------- Display the sorted values AND add players to their Team Sorted player groups: --------
      • For each (Integer i) from MSort_StartIndex to MSort_EndIndex, do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in Users and do (Actions)
            • Loop - Actions
              • Set VariableSet pn = (Player number of (Picked player))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TeamScore[TeamNumber[pn]] Equal to (Integer(MSort_Values[i]))
                  • HasBeenSorted[pn] Equal to False
                • Then - Actions
                  • Player Group - Add (Picked player) to TeamSorted[i]
                  • Set VariableSet HasBeenSorted[pn] = True
                • Else - Actions
      • -------- --------
      • -------- The players have all been put into the TeamSorted player groups. TeamSorted[1] = 1st place, [2] = second place, [3] = third place, [4] = fourth place --------
      • -------- Example of winning the game for 1st place and losing for everyone else: --------
      • Player Group - Pick every player in Users and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) is in TeamSorted[1].) Equal to True
            • Then - Actions
              • Game - Victory (Picked player) (Show dialogs, Show scores)
            • Else - Actions
              • Game - Defeat (Picked player) with the message: Defeat!
So this has a problem that might not matter to you. The way it adds players to TeamSorted can be incorrect for teams beyond the 1st.
For example:
  • Actions
    • -------- Keep track of each team's total score ( you would use your formula here for kills/deaths/flags ) --------
    • Set VariableSet TeamScore[1] = 20
    • Set VariableSet TeamScore[2] = 10
    • Set VariableSet TeamScore[3] = 20
    • Set VariableSet TeamScore[4] = 10
Player 1 = 20 (tied with p3)
Player 2 = 10 (tied with p4)
Player 3 = 20 (tied with p1)
Player 4 = 10 (tied with p2)

My trigger adds Player 1/3 to TeamSorted[1] which works. But it adds Player 2/4 to TeamSorted[3] instead of TeamSorted[2].

This isn't an issue if you're simply Defeating anyone that's not in TeamSorted[1], but it could be if you wanted to do something different for Teams 2/3/4 like giving the 2nd place team a better reward than the 3rd place team. I'll try and fix this issue and post it here if I can think of a good solution.
 
Last edited:
Level 7
Joined
Sep 19, 2020
Messages
190
empty.gif
joinbottomminus.gif
playergroup.gif
Player Group - Pick every player in Users and do (Actions)
  • empty.gif
    empty.gif
    joinbottomminus.gif
    actions.gif
    Loop - Actions
    • empty.gif
      empty.gif
      empty.gif
      joinbottomminus.gif
      if.gif
      If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • empty.gif
        empty.gif
        empty.gif
        empty.gif
        joinminus.gif
        cond.gif
        If - Conditions
        • empty.gif
          empty.gif
          empty.gif
          empty.gif
          line.gif
          joinbottom.gif
          if.gif
          ((Picked player) is in TeamSorted[1].) Equal to True
      • empty.gif
        empty.gif
        empty.gif
        empty.gif
        joinminus.gif
        actions.gif
        Then - Actions
        • empty.gif
          empty.gif
          empty.gif
          empty.gif
          line.gif
          joinbottom.gif
          game.gif
          Game - Victory (Picked player) (Show dialogs, Show scores)
      • empty.gif
        empty.gif
        empty.gif
        empty.gif
        joinbottomminus.gif
        actions.gif
        Else - Actions
        • empty.gif
          empty.gif
          empty.gif
          empty.gif
          empty.gif
          joinbottom.gif
          game.gif
          Game - Defeat (Picked player) with the message: Defeat!
I changed to it
  • Player Group - Pick every player in Team[TeamRank[(Integer A)]] and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TeamScore[(Integer A)] Equal to TeamScore[0]
        • Then - Actions
          • Game - Victory (Picked player) (Show dialogs, Show scores)
        • Else - Actions
          • Game - Defeat (Picked player) with the message: Defeat!
it is ok?
I think it is work
team 1 score = 1000
team 2 score = 1000
team 3 score = 1000
team 4 score = 100
now return
Rank 1: team 1 (victory)
Rank 2: team 2 (victory)
Rank 3: team 3 (victory)
Rank 4: team 4 (Defeat)
 
Status
Not open for further replies.
Top