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

[Solved] Damage leaderboard

Status
Not open for further replies.
Level 7
Joined
Feb 23, 2020
Messages
253
How do you make a leaderboard based on the total damage dealt?

I've tried this, but this does not seem to work properly. The biggest issues i'm having here is that it only detects player brown (Computer) for some reason, and with every attack he does, the damage dealt tracker is increased by 1. 1-3-6-10-15-21 etc. (The attacking unit have 1-1 damage).

Thanks in advance! :)

  • Run
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Hashtable = (Last created hashtable)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Leaderboard - Create a leaderboard for (All players) titled Damage Dealt
          • Set VariableSet Leaderboard = (Last created leaderboard)
          • Leaderboard - Add (Picked player) to Leaderboard with label (Name of (Picked player)) and value 0
          • Leaderboard - Show Leaderboard
  • Damage
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load 0 of 0 from Hashtable.) Not equal to 0
        • Then - Actions
          • Player Group - Pick every player in (All players matching ((Owner of (Attacking unit)) Equal to (Matching player)).) and do (Actions)
            • Loop - Actions
              • Set VariableSet DamageDone[(Player number of (Picked player))] = (DamageDone[(Player number of (Picked player))] + ((Load 1 of 1 from Hashtable.) - (Integer((Life of (Attacking unit))))))
              • Leaderboard - Change the value for (Picked player) in Leaderboard to DamageDone[(Player number of (Picked player))]
              • Leaderboard - Sort Leaderboard by Value in Descending order
        • Else - Actions
          • Player Group - Pick every player in (All players matching ((Owner of (Attacking unit)) Equal to (Matching player)).) and do (Actions)
            • Loop - Actions
              • Set VariableSet DamageDone[(Player number of (Picked player))] = (DamageDone[(Player number of (Picked player))] + ((Integer((Max life of (Attacked unit)))) - (Integer((Life of (Attacked unit))))))
              • Leaderboard - Change the value for (Picked player) in Leaderboard to DamageDone[(Player number of (Picked player))]
              • Leaderboard - Sort Leaderboard by Value in Descending order
 
Level 28
Joined
Feb 18, 2014
Messages
3,580
"Pick every player" overwrites all players until the last player is checked, which is player 12 (brown) in this case. You'll have to index them first. Like this :
  • Run
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled Damage Delt
      • Set Leaderboard = (Last created leaderboard)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Leaderboard - Add (Player((Integer A))) to Leaderboard with label (Name of (Player((Integer A)))) and value 0
      • Leaderboard - Show Leaderboard
 
Level 7
Joined
Feb 23, 2020
Messages
253
"Pick every player" overwrites all players until the last player is checked, which is player 12 (brown) in this case. You'll have to index them first. Like this :
  • Run
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled Damage Delt
      • Set Leaderboard = (Last created leaderboard)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Leaderboard - Add (Player((Integer A))) to Leaderboard with label (Name of (Player((Integer A)))) and value 0
      • Leaderboard - Show Leaderboard
I see, thank you. Do you know how to fix the damage part?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,557
"Pick every player" overwrites all players until the last player is checked, which is player 12 (brown) in this case. You'll have to index them first. Like this :
  • Run
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled Damage Delt
      • Set Leaderboard = (Last created leaderboard)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Leaderboard - Add (Player((Integer A))) to Leaderboard with label (Name of (Player((Integer A)))) and value 0
      • Leaderboard - Show Leaderboard
That's not actually the issue here. The issue here is that he's creating the Leaderboard inside of the Pick every player function. He's essentially creating a new Leaderboard for EACH picked player, so 12 in total if there are 12 players. He's also Showing the Leaderboard 12 times. It's perfectly fine to use Pick every player in order to to create and add players to a leaderboard-if it's done correctly.

So all he has to do is move "Create a leaderboard" to outside of the Pick function (above or below the Hashtable for instance) as well as move "Show Leaderboard" outside of the Pick function (below the Pick function).

@Xzere
You need to create a new trigger and give it the Event "DamageEvent becomes equal to 1.00". Search for "Real" in the Events search box.

The trigger will then run whenever a unit takes damage. From there you can reference the damaging unit and the damaged unit using the variable "DamageEventSource" and "DamageEventTarget". The source is the unit that dealt the damage, the target is the unit that got damaged.
 
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
That's not actually the issue here. The issue here is that he's creating the Leaderboard inside of the Pick every player function. He's essentially creating a new Leaderboard for EACH picked player, so 12 in total if there are 12 players. He's also Showing the Leaderboard 12 times. It's perfectly fine to use Pick every player in order to to create and add players to a leaderboard-if it's done correctly.

So all he has to do is move "Create a leaderboard" to outside of the Pick function (above or below the Hashtable for instance) as well as move "Show Leaderboard" outside of the Pick function (below the Pick function).

@Xzere
You need to create a new trigger and give it the Event "DamageEvent becomes equal to 1.00". Search for "Real" in the Events search box.

The trigger will then run whenever a unit takes damage. From there you can reference the damaging unit and the damaged unit using the variable "DamageEventSource" and "DamageEventTarget". The source is the unit that dealt the damage, the target is the unit that got damaged.
I see, thank you for your response :)
I have tried that too, but it does not really seem to work either. The problem is that the dmg increases (on the leaderboard), I.E a unit deals 25 dmg, then it says 25, and it somehow stores that number to plus it with the next attack, I.E 25. Which means it will say i've dealt 75 damage. And for some reason it does not register the first 2 attacks :/
 
Level 14
Joined
Feb 7, 2020
Messages
387
I see, thank you for your response :)
I have tried that too, but it does not really seem to work either. The problem is that the dmg increases (on the leaderboard), I.E a unit deals 25 dmg, then it says 25, and it somehow stores that number to plus it with the next attack, I.E 25. Which means it will say i've dealt 75 damage. And for some reason it does not register the first 2 attacks :/
Can you post the new triggers you are using?
 
Level 7
Joined
Feb 23, 2020
Messages
253
Can you post the new triggers you are using?

  • Creating Leaderboard
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled Damage Dealt
      • Set VariableSet Leaderboard = (Last created leaderboard)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) controller) Equal to User
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Leaderboard - Add (Picked player) to Leaderboard with label (Name of (Picked player)) and value 0
            • Else - Actions
      • Leaderboard - Show Leaderboard
  • Damage
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load 0 of 0 from Hashtable.) Not equal to 0
        • Then - Actions
          • Player Group - Pick every player in (All players matching ((Owner of GDD_DamageSource) Equal to (Matching player)).) and do (Actions)
            • Loop - Actions
              • Leaderboard - Change the value for (Picked player) in Leaderboard to DamageDone[(Player number of (Picked player))]
              • Set VariableSet DamageDone[(Player number of (Picked player))] = (DamageDone[(Player number of (Picked player))] + ((Load 1 of 1 from Hashtable.) - (Integer((Life of GDD_DamageSource)))))
              • Leaderboard - Sort Leaderboard by Value in Descending order
        • Else - Actions
          • Player Group - Pick every player in (All players matching ((Owner of GDD_DamageSource) Equal to (Matching player)).) and do (Actions)
            • Loop - Actions
              • Leaderboard - Change the value for (Picked player) in Leaderboard to DamageDone[(Player number of (Picked player))]
              • Set VariableSet DamageDone[(Player number of (Picked player))] = (DamageDone[(Player number of (Picked player))] + ((Integer((Max life of GDD_DamagedUnit))) - (Integer((Life of GDD_DamagedUnit)))))
              • Leaderboard - Sort Leaderboard by Value in Descending order
This is what i'm using for the moment
 
Level 14
Joined
Feb 7, 2020
Messages
387
Which damage engine are you using, or is it custom? Is Game - GDD_Event becomes Equal to 0.00 correct for listening for damage taken? It's typically a number greater than zero for detection.

Also, your code is contrived with the use of Player Groups.

This is much simpler:

  • Leaderboard - Change the value for (Owner of DamageEventSource) in (Last created leaderboard) to YourVarHere[(Player number of (Owner of DamageEventSource))]
As for the amount, this part is confusing for me:

  • (DamageDone[(Player number of (Picked player))] + ((Load 1 of 1 from Hashtable.) - (Integer((Life of GDD_DamageSource)))))
Typically, a damage engine would allow you to reference the amount dealt, versus having to do a tacky calculation on your part. You'll have to share which engine you are using or if you created your own real event.
 
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
Which damage engine are you using, or is it custom? Is Game - GDD_Event becomes Equal to 0.00 correct for listening for damage taken? It's typically a number greater than zero for detection.

Also, your code is contrived with the use of Player Groups.

This is much simpler:

  • Leaderboard - Change the value for (Owner of DamageEventSource) in (Last created leaderboard) to YourVarHere[(Player number of (Owner of DamageEventSource))]
As for the amount, this part is confusing for me:

  • (DamageDone[(Player number of (Picked player))] + ((Load 1 of 1 from Hashtable.) - (Integer((Life of GDD_DamageSource)))))
Typically, a damage engine would allow you to reference the amount dealt, versus having to do a tacky calculation on your part. You'll have to share which engine you are using or if you created your own real event.
This is the DDS i use.
GUI-Friendly Damage Detection v1.2.1
 
Last edited:
Level 14
Joined
Feb 7, 2020
Messages
387

Use this variable to increment the damage dealt: GDD_Damage.

You shouldn't have to do anything with unit life when using a damage system as its whole purpose is dealing with damage values.

  • DamageDone[(Player number of (Picked player))] = (DamageDone[(Player number of (Picked player))] + GDD_Damage)
 
Level 7
Joined
Feb 23, 2020
Messages
253
Use this variable to increment the damage dealt: GDD_Damage.

You shouldn't have to do anything with unit life when using a damage system as its whole purpose is dealing with damage values.

  • DamageDone[(Player number of (Picked player))] = (DamageDone[(Player number of (Picked player))] + GDD_Damage)
Wow it's working! Thank you very much mate! :)
 
Status
Not open for further replies.
Top