• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Point System Trigger Question

Status
Not open for further replies.
Level 3
Joined
Aug 22, 2010
Messages
34
Hi, I'm trying to make a trigger to figure out how people stack up against each other at the end of a round. My trigger as now is when this is ran, if Shots = numshotstaken13(declared in another trigger, means everyone has shot), it says who the winner is and their total distance. This is no good as it only figures out who has the highest distance.

I have a global variable NumberPlayers_Int = 0 <Integer> to keep track of how many players there are (so you can't place 8th in a game with 7 players)

and a global integer array Gameplay_PlayerPoints_Integer = 0 <Integer[12]> (how many pts total they have)


I'm wondering if there's an easy way to figure out
1.) Who is first,second, third, ...# of playersth
2.) announce the guy who is in first (in this case biggest TotalDistance) and his distance
3.) Add to PlayerPoints for the players (so if there's 8 players in the game, first place gets 8, 2nd place gets 7, 3rd gets 6, so on)
4.) maybe handle ties(same distance) with them both getting the same points(IE tying 7/8 in an 8 player game would give you 1 pt)? Not that important.
5.) if LDSK_TotalDistance_Real[LoopA] (their distance) is 0.0, give them no points

I was never very good at doing this kind of stuff "elegantly" in my CS classes lol. (I could probably do all this with hundreds of lines of GUI...)

This is my trigger. Like I said it figures out who has the biggest distance, and announces it, and gives him #player pts.
  • General - If (Conditions) then do (Actions) else do (Actions)
    • If
      • LDSK_NumShotsTaken_Integer[13] == Shots
    • Then
      • Trigger - Turn (Current trigger) Off
      • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
        • Actions
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • LDSK_TotalDistance_Real[LoopA] > FurthestDistance
            • Then
              • Variable - Set FurthestDistance = LDSK_TotalDistance_Real[LoopA]
              • Variable - Set HighScorePlayer = LoopA
            • Else
  • Variable - Set Gameplay_PlayerPoints_Integer[HighScorePlayer] = (Gameplay_PlayerPoints_Integer[HighScorePlayer] + NumberPlayers_Int)
    • UI - Display (Combine ((Name of player HighScorePlayer), (Combine (" has won with total distance of ", (Combine ((Text(FurthestDistance) with Any Precision decimal places), " meters!")))))) for (All players) to Subtitle area
    • Else
Not sure if this is possible. If not, I'll probably just give them points based on their range and a bonus for having the highest.
Thanks in advance.
 
Level 11
Joined
Aug 1, 2009
Messages
963
Basically, the way you would do this is by having a loop within a loop.

Your first loop would loop for 1st place through the number of players.
Your second loop would be a "while" loop - while a local player group (which would be set to "Active Players" at the start of the trigger) does not have 0 players, execute actions.
Inside the second loop, it would set a local player variable to the first player of the playergroup. Then, it would compare each one to an integer variable to find which player has the highest score - if a player has a higher score than the integer variable, it would be set to another player variable. After this happened, it would remove the first player of the playergroup from the group.

Once the second loop finishes running, you can do whatever with the player who had the place equivalent to the loop integer for the first loop, give them points based on their score or something. It will repeat for each place.

Also checking if their distance = 0 would be easy with a simple if/then check. If they had a distance of 0, it would remove them from the player group before doing the loops.
 
Level 3
Joined
Aug 22, 2010
Messages
34
Basically, the way you would do this is by having a loop within a loop.

Your first loop would loop for 1st place through the number of players.
Your second loop would be a "while" loop - while a local player group (which would be set to "Active Players" at the start of the trigger) does not have 0 players, execute actions.
Inside the second loop, it would set a local player variable to the first player of the playergroup. Then, it would compare each one to an integer variable to find which player has the highest score - if a player has a higher score than the integer variable, it would be set to another player variable. After this happened, it would remove the first player of the playergroup from the group.

Once the second loop finishes running, you can do whatever with the player who had the place equivalent to the loop integer for the first loop, give them points based on their score or something. It will repeat for each place.

Also checking if their distance = 0 would be easy with a simple if/then check. If they had a distance of 0, it would remove them from the player group before doing the loops.

Oooh, I figured it would be loops inside of loops, but I didn't think of that. I'll give it a try in a bit, ty.
 
Level 3
Joined
Aug 22, 2010
Messages
34
It gets everything right up until...

I have player 3 / 5 / 7 / 12 set to have a score.

If I win, it goes you have won
player 3 has come in 2nd ...
player 7 has come in 3rd..
player 12 has come in 4th...
player 5 has come in 5th..
player 5 has come in 6th...
...
player 5 has come in 12th..

Can ya help me again? :)

IT NEVER GETS OUT OF THE WHILE LOOP

  • LDSK_Victory
    • Events
      • Timer - Every 1.0 seconds of Game Time
    • Local Variables
      • Shots = 0 <Integer>
      • LoopA = 0 <Integer>
      • FurthestDistance = 0.0 <Real>
      • HighScorePlayer = 0 <Integer>
      • Group = (Empty player group) <Player Group>
      • Position = 1 <Integer>
    • Conditions
    • Actions
      • ------- How many shots taken so far
      • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
        • Actions
          • Variable - Set Shots = (Shots + LDSK_NumShotsTaken_Integer[LoopA])
      • ------- Game over, man
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • LDSK_NumShotsTaken_Integer[13] == Shots
        • Then
          • ------- Everyone in same group
          • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
            • Actions
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • Gameplay_PlayerAlive_Boolean[LoopA] == true
                • Then
                  • Player Group - Add player LoopA to Group
                • Else
          • Trigger - Turn (Current trigger) Off
          • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
            • Actions
              • Camera - Set the camera bounds for (Player group(LoopA)) to (Entire map) (Do adjust the minimap)
              • Unit Group - Pick each unit in (Any units in LDSK_Visibility owned by player Any Player matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
                • Actions
                  • Unit - Remove (Picked unit) from the game
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • LDSK_TotalDistance_Real[LoopA] > FurthestDistance
                • Then
                  • ------- Figure out first place
                  • Variable - Set FurthestDistance = LDSK_TotalDistance_Real[LoopA]
                  • Variable - Set HighScorePlayer = LoopA
                • Else
          • ------- No one recieves points
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • FurthestDistance == 0.0
            • Then
              • UI - Display "Failures! Everyone in this room is..." for (All players) to Subtitle area
              • General - Skip remaining actions
            • Else
          • ------- Give points to first place, display text
          • Variable - Set Position = (Position + 1)
          • Variable - Set Gameplay_PlayerPoints_Integer[HighScorePlayer] = (Gameplay_PlayerPoints_Integer[HighScorePlayer] + LDSK_Score_Integer)
          • UI - Display (Combine ((Name of player HighScorePlayer), (Combine (" has won with total distance of ", (Combine ((Text(FurthestDistance) with Any Precision decimal places), (Combine (" meters and has recieved ", (Combine ((Text(LDSK_Score_Integer)), " points!")))))))) for (All players) to Subtitle area
          • Variable - Set LDSK_Score_Integer = (LDSK_Score_Integer - 1)
          • Player Group - Remove player HighScorePlayer from Group
          • Variable - Set FurthestDistance = 0.0
          • Trigger - Run Setup_UpdateLeaderboard (Ignore Conditions, Don't Wait until it finishes)
          • ------- Figure out places 2nd through #th players playing
          • General - While (Conditions) are true, do (Actions)
            • Conditions
              • (Number of players in Group) > 0
            • Actions
              • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
                • Actions
                  • Camera - Set the camera bounds for (Player group(LoopA)) to (Entire map) (Do adjust the minimap)
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • And
                        • Conditions
                          • LDSK_TotalDistance_Real[LoopA] > FurthestDistance
                          • (LoopA is in Group) == true
                    • Then
                      • ------- Figure out place
                      • Variable - Set FurthestDistance = LDSK_TotalDistance_Real[LoopA]
                      • Variable - Set HighScorePlayer = LoopA
                    • Else
              • Player Group - Remove player HighScorePlayer from Group
              • Variable - Set Gameplay_PlayerPoints_Integer[HighScorePlayer] = (Gameplay_PlayerPoints_Integer[HighScorePlayer] + LDSK_Score_Integer)
              • Variable - Set FurthestDistance = 0.0
              • UI - Display (Combine ((Name of player HighScorePlayer), (Combine (" has come in ", (Combine ((Text(Position)), (Combine (Gameplay_Position_Text[Position], (Combine (" place and is awarded ", (Combine ((Text(LDSK_Score_Integer)), " points.")))))))))))) for (All players) to Subtitle area
              • Variable - Set LDSK_Score_Integer = (LDSK_Score_Integer - 1)
              • Variable - Set Position = (Position + 1)
              • General - Wait 1.0 Real Time seconds
              • Trigger - Run Setup_UpdateLeaderboard (Ignore Conditions, Don't Wait until it finishes)
          • ------- If you have 0 pts, you get nothing!
          • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
            • Actions
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • LDSK_TotalDistance_Real[LoopA] == 0.0
                • Then
                  • Player Group - Remove player LoopA from Group
                  • UI - Display "You did not kill any Zerglings and ..." for (Player group(LoopA)) to Subtitle area
                • Else
        • Else
 
Last edited:
Level 11
Joined
Aug 1, 2009
Messages
963
Try using debug messages to read off the number of players left in the group after each player is removed, if it says that it is 0, then you can have an if/then check to see if the playergroup is empty, and break the loop if it is.

The way the GUI changes into Galaxy code to be executed might have a problem with it >_.
 
Level 3
Joined
Aug 22, 2010
Messages
34
I put in a line to tell me how many people are in the group. I put 2 computers and myself in, and it displays 3. However, it goes until it hits 12 then stops.
 
Last edited:
Level 3
Joined
Aug 22, 2010
Messages
34
Changed it to number of players in group, put 5 players in the group, ran it, it still goes 12 times. :|
 
Level 11
Joined
Aug 1, 2009
Messages
963
Do you set the player alive bools to false for people who aren't playing?

It probably loops through for all the empty slots, however, they have a distance of 0 and thus do not get set as the highest player, which means it retains the last person who was the highest player (lowest score).
 
Level 3
Joined
Aug 22, 2010
Messages
34
I opened a blank map and got it working there. It worked for ties even. I copied it over and change some variables, and now all it will do is announce who wins.

  • Data
    • Events
      • Timer - Every 1.0 seconds of Game Time
    • Local Variables
      • LoopA = 0 <Integer>
      • HighScorePlayer = 0 <Integer>
      • HighScoreDistance = 0.0 <Real>
      • Shots = 0 <Integer>
      • #Players = 0 <Integer>
      • TieGroup = (Empty player group) <Player Group>
      • ScoreAdjustment = 0 <Integer>
    • Conditions
    • Actions
      • Variable - Set #Players = NumberPlayers_Int
      • Variable - Set LDSK_Position_Integer = #Players
      • ------- How many shots taken so far
      • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
        • Actions
          • Variable - Set Shots = (Shots + LDSK_NumShotsTaken_Integer[LoopA])
      • ------- Game over, man
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • LDSK_NumShotsTaken_Integer[13] == Shots
        • Then
          • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
            • Actions
              • Camera - Set the camera bounds for (Player group(LoopA)) to (Entire map) (Do adjust the minimap)
              • Unit Group - Pick each unit in (Any units in LDSK_Visibility owned by player Any Player matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
                • Actions
                  • Unit - Remove (Picked unit) from the game
          • Trigger - Turn LDSK_Kill Off
          • Trigger - Turn LDSK_Regions Off
          • Trigger - Turn LDSK_Shoot Off
          • Trigger - Turn LDSK_Victory Off
          • ------- 0 points for 0 distance
          • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
            • Actions
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • LDSK_TotalDistance_Real[LoopA] == 0.0
                • Then
                  • Visibility - Destroy Gameplay_Visibility[LoopA]
                  • Variable - Set LDSK_HasBeenSorted[LoopA] = true
                  • Variable - Set #Players = (#Players - 1)
                  • UI - Display "You did not kill any Zerglings and ..." for (Player group(LoopA)) to Subtitle area
                • Else
          • ------- 2 bonus points for first
          • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
            • Actions
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • LDSK_TotalDistance_Real[LoopA] > HighScoreDistance
                  • LDSK_HasBeenSorted[LoopA] == false
                • Then
                  • Variable - Set HighScorePlayer = LoopA
                  • Variable - Set HighScoreDistance = LDSK_TotalDistance_Real[LoopA]
                • Else
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • LDSK_TotalDistance_Real[LoopA] == HighScoreDistance
                      • LDSK_HasBeenSorted[LoopA] == false
                    • Then
                      • Variable - Set HighScoreDistance = LDSK_TotalDistance_Real[LoopA]
                      • Player Group - Add player LoopA to TieGroup
                      • Player Group - Add player HighScorePlayer to TieGroup
                    • Else
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • (Number of players in TieGroup) > 0
            • Then
              • Variable - Set ScoreAdjustment = (Number of players in TieGroup)
              • Player Group - Pick each player in TieGroup and do (Actions)
                • Actions
                  • Variable - Set Gameplay_PlayerPoints_Integer[(Picked player)] = (Gameplay_PlayerPoints_Integer[(Picked player)] + LDSK_Score_Integer)
                  • Variable - Set LDSK_HasBeenSorted[(Picked player)] = true
                  • Variable - Set #Players = (#Players - 1)
                  • UI - Display (Combine (Gameplay_PlayerColor_Text[(Picked player)], (Combine ((Name of player (Picked player)), (Combine (" has received ", (Combine ((Text(LDSK_Score_Integer)), (Combine (" points for tying for first!", Gameplay_PlayerColor_Text[13])))))))))) for (All players) to Subtitle area
                  • Player Group - Remove player (Picked player) from TieGroup
              • Variable - Set LDSK_Score_Integer = (LDSK_Score_Integer - ScoreAdjustment)
              • Variable - Set LDSK_Position_Integer = (LDSK_Position_Integer + ScoreAdjustment)
            • Else
              • Variable - Set Gameplay_PlayerPoints_Integer[HighScorePlayer] = (Gameplay_PlayerPoints_Integer[HighScorePlayer] + (LDSK_Score_Integer + 2))
              • Variable - Set LDSK_HasBeenSorted[HighScorePlayer] = true
              • UI - Display (Combine (Gameplay_PlayerColor_Text[HighScorePlayer], (Combine ((Name of player HighScorePlayer), (Combine (" has received ", (Combine ((Text((LDSK_Score_Integer + 2))), (Combine (" points for winning!", Gameplay_PlayerColor_Text[13])))))))))) for (All players) to Subtitle area
              • Variable - Set #Players = (#Players - 1)
              • Variable - Set LDSK_Position_Integer = (LDSK_Position_Integer + 1)
              • Variable - Set LDSK_Score_Integer = (LDSK_Score_Integer - 1)
          • Variable - Set HighScoreDistance = 0.0
          • ------- 2nd place ---> #player place
          • General - While (Conditions) are true, do (Actions)
            • Conditions
              • #Players > 0
            • Actions
              • General - For each integer LoopA from 1 to 12 with increment 1, do (Actions)
                • Actions
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • LDSK_TotalDistance_Real[LoopA] > HighScoreDistance
                      • LDSK_HasBeenSorted[LoopA] == false
                    • Then
                      • Variable - Set HighScorePlayer = LoopA
                      • Variable - Set HighScoreDistance = LDSK_TotalDistance_Real[LoopA]
                    • Else
                      • General - If (Conditions) then do (Actions) else do (Actions)
                        • If
                          • LDSK_TotalDistance_Real[LoopA] == HighScoreDistance
                          • LDSK_HasBeenSorted[LoopA] == false
                        • Then
                          • Variable - Set HighScoreDistance = LDSK_TotalDistance_Real[LoopA]
                          • Player Group - Add player LoopA to TieGroup
                          • Player Group - Add player HighScorePlayer to TieGroup
                        • Else
              • General - If (Conditions) then do (Actions) else do (Actions)
                • If
                  • (Number of players in TieGroup) > 0
                • Then
                  • Variable - Set ScoreAdjustment = (Number of players in TieGroup)
                  • Player Group - Pick each player in TieGroup and do (Actions)
                    • Actions
                      • Variable - Set Gameplay_PlayerPoints_Integer[(Picked player)] = (Gameplay_PlayerPoints_Integer[(Picked player)] + LDSK_Score_Integer)
                      • Variable - Set LDSK_HasBeenSorted[(Picked player)] = true
                      • Variable - Set #Players = (#Players - 1)
                      • General - If (Conditions) then do (Actions) else do (Actions)
                        • If
                          • LDSK_Score_Integer == 1
                        • Then
                          • UI - Display (Combine ("You", (Combine (" have received ", (Combine ((Text(LDSK_Score_Integer)), (Combine (" point for tying for ", (Combine ((Text(LDSK_Position_Integer)), (Combine (Gameplay_Position_Text[LDSK_Position_Integer], " place!")))))))))))) for (Player group((Picked player))) to Subtitle area
                        • Else
                          • UI - Display (Combine ("You", (Combine (" have received ", (Combine ((Text(LDSK_Score_Integer)), (Combine (" points for tying for ", (Combine ((Text(LDSK_Position_Integer)), (Combine (Gameplay_Position_Text[LDSK_Position_Integer], " place!")))))))))))) for (Player group((Picked player))) to Subtitle area
                      • Player Group - Remove player (Picked player) from TieGroup
                  • Variable - Set LDSK_Score_Integer = (LDSK_Score_Integer - ScoreAdjustment)
                  • Variable - Set LDSK_Position_Integer = (LDSK_Position_Integer + ScoreAdjustment)
                • Else
                  • Variable - Set Gameplay_PlayerPoints_Integer[HighScorePlayer] = (Gameplay_PlayerPoints_Integer[HighScorePlayer] + LDSK_Score_Integer)
                  • General - If (Conditions) then do (Actions) else do (Actions)
                    • If
                      • LDSK_Score_Integer == 1
                    • Then
                      • UI - Display (Combine ("You", (Combine (" have received ", (Combine ((Text(LDSK_Score_Integer)), (Combine (" point for coming in ", (Combine ((Text(LDSK_Position_Integer)), (Combine (Gameplay_Position_Text[LDSK_Position_Integer], " place!")))))))))))) for (Player group(HighScorePlayer)) to Subtitle area
                    • Else
                      • UI - Display (Combine ("You", (Combine (" have received ", (Combine ((Text(LDSK_Score_Integer)), (Combine (" points for coming in ", (Combine ((Text(LDSK_Position_Integer)), (Combine (Gameplay_Position_Text[LDSK_Position_Integer], " place!")))))))))))) for (Player group(HighScorePlayer)) to Subtitle area
                  • Variable - Set LDSK_Score_Integer = (LDSK_Score_Integer - 1)
                  • Variable - Set LDSK_Position_Integer = (LDSK_Position_Integer + 1)
                  • Variable - Set #Players = (#Players - 1)
                  • Variable - Set LDSK_HasBeenSorted[HighScorePlayer] = true
              • Variable - Set HighScoreDistance = 0.0
          • Trigger - Turn (Current trigger) Off
          • Trigger - Run Setup_NextLevel (Ignore Conditions, Don't Wait until it finishes)
        • Else
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
While I am dropping by ill tell you the 2 correct solutions.
The first is basically a copy from one array to another where you loop through all elements of an unsorted sequential array, pop (remove from array and use value) the one which has the highest value (the best) and then add it to an ordered array that is sequential (each element is followed by another element until there are no more elements). You can even use the destination array as the source array as long as the array index is not the player index (an entry in the array is a player index) and that you move whatever is in the destination index to the index the item was poped. The disadvantage of this is an efficency of O(n(n+1)/2) where n is the number of items to sort but with a problem like this will probably be the easiest.

The other solution is an algerthim which converts an unsorted sequential array into a sorted sequential array. The idea is that it compairs index n with index n+1 and if index n+1 is better than index n it will swap the data. There are two parts to this, the first loop goes from n=0 until there are no more elements to compare (n+1 is void). The second part runs only if n+1 is better than n whereby it will then keep the current n but use a separate variable (m in this description) so to run backwards comparing index m with index m-1 and swaping if m is better than m-1 from m=n until m=0 or m-1 is better than m. This algerthim does not require blank sequential space to be used and makes the source its desternation. It also has the potential to be more efficent than the previous sujestion as it keeps the scope size very small at any one time meaning its efficency can be anywhere from O(n) (an order list or partly order list with no more than 1 pair swap to get it ordered) to O(n(n-1)/2) (this would be the case of an ultimate badly ordered array where it is put in inverse order to maximize the distance each variable gets moved). As you can see this has clear cut advantages over the previous efficency wise however do keep in mind that each itteration in it might be slower on its own.
 
Level 3
Joined
Aug 22, 2010
Messages
34
That post reminds me of my computer science classes. :p

I did it the way above, forgot to check if the player is in the game though. Fixed it. Thanks for your time anyhow.
 
Status
Not open for further replies.
Top