Snippet Damage Show and Order

ArmyOfFrogs

New Member
Reaction score
20
This is a trigger snippet/system thing I just implemented into my map, thought some other people would possibly like it. It stores players' damage dealt, then can be shown to players, in order from greatest to least. Credits to Chocobo for the first 2 triggers pretty much, Romek for Leaderboard idea, and Komaqtion for leak fixing :)
Code:
Variables used
Name                    Array                  Type
DamageMeter             Yes                    Integer
Player                  Yes                    Player
DmgeShowOrder           Yes                    Integer
DmgShowNames            Yes                    String
Temp_Group              No                     Unit Group
Temp_PGroup             No                    Player Group

Players are stored in Player[PlayerNumber]
Player Colors are just strings storing the hexcode for their colors


These first two detect units in the map
Trigger:
  • Damage Detect New Units
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Trigger - Add to DamagesAdd <gen> the event (Unit - (Triggering unit) Takes damage)


Trigger:
  • Preplaced Units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Temp_Group = (Units in (Playable map area))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Trigger - Add to DamageAdd <gen> the event (Unit - (Picked unit) Takes damage)
      • Custom script: call DestroyGroup(udg_Temp_Group)


This will add it to the variable storing the total damage dealt
Trigger:
  • DamageAdd
    • Events
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Damage source)) Equal to Player 1 (Red)
          • (Owner of (Damage source)) Equal to Player 2 (Blue)
          • (Owner of (Damage source)) Equal to Player 3 (Teal)
          • (Owner of (Damage source)) Equal to Player 4 (Purple)
          • (Owner of (Damage source)) Equal to Player 5 (Yellow)
          • (Owner of (Damage source)) Equal to Player 6 (Orange)
          • (Owner of (Damage source)) Equal to Player 7 (Green)
          • (Owner of (Damage source)) Equal to Player 8 (Pink)
          • (Owner of (Damage source)) Equal to Player 9 (Gray)
          • (Owner of (Damage source)) Equal to Player 10 (Light Blue)
    • Actions
      • Set DamageMeter[(Player number of (Owner of (Damage source)))] = (DamageMeter[(Player number of (Owner of (Damage source)))] + (Integer((Damage taken))))


This is the first part of showing the damage to the players
Trigger:
  • DmgShow
    • Events
      • Player - Player 1 (Red) types a chat message containing -dmg as An exact match
      • Player - Player 2 (Blue) types a chat message containing -dmg as An exact match
      • Player - Player 3 (Teal) types a chat message containing -dmg as An exact match
      • Player - Player 4 (Purple) types a chat message containing -dmg as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -dmg as An exact match
      • Player - Player 6 (Orange) types a chat message containing -dmg as An exact match
      • Player - Player 7 (Green) types a chat message containing -dmg as An exact match
      • Player - Player 8 (Pink) types a chat message containing -dmg as An exact match
      • Player - Player 9 (Gray) types a chat message containing -dmg as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -dmg as An exact match
    • Conditions
    • Actions
      • Trigger - Run DmgOrder <gen> (ignoring conditions)
      • Wait 0.50 seconds
      • Set Temp_PGroup = (Player group(Player[(Player number of (Triggering player))]))
      • For each (Integer A) from 1 to PlayersActive, do (Actions)
        • Loop -
          • Game - Display to Temp_PGroup the text: (((DmgShowNames[(Integer A)]) + <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> + (String(DamageMeter[DmgShowOrder[(Integer A)]]))))
      • Custom script: call DestroyForce(udg_Temp_PGroup)


Here is the second part which organizes the damage dealt, so it can be properly displayed :)
Trigger:
  • DmgOrder
    • Events
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled damage order
      • Leaderboard - Hide (Last created leaderboard)
      • Player Group - Pick every player in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User))) and do (Actions)
        • Loop - Actions
          • Leaderboard - Add (Picked player) to (Last created leaderboard) with label Rank and value DamageMeter[(Player number of (Picked player))]
      • Leaderboard - Sort (Last created leaderboard) by Value in Descending order
      • For each (Integer A) from 1 to PlayersActive, do (Actions)
        • Loop - Actions
          • Set DmgShowNames[(Integer A)] = (Name of (Player in position (Integer A) of (Last created leaderboard)))
          • Set DmgShowOrder[(Integer A)] = (Position of Player[(Integer A)] in (Last created leaderboard))
      • Leaderboard - Destroy (Last created leaderboard)


There you have it. Every time a player damages a unit, it stores the damage dealt in an array. When they type -dmg it will order the damage dealt from greatest to least, then display it to him in order.

Please point out if you see something I'm missing or that needs correcting. Thanks and I hope this is useful :)

Known problems
If a player skips a slot (I.E, 1 2 3 are occupied, 4 is empty then theres someone at 5) it will not display properly.
Status: No clue how to fix that.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Nice system :D Maybe a screenshot of how the leaderboard looks ;)

Just a couple of leaks here and there:
Preplaced Units
Code:
Unit Group - Pick every unit in [COLOR="Red"](Units in (Playable map area))[/COLOR] and do (Actions)

That line leaks one Unit-Group... I suggest you do something like this:
Trigger:
  • Preplaced Units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Temp_Group = (Units in (Playable map area)
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Trigger - Add to DamageAdd &lt;gen&gt; the event (Unit - (Picked unit) Takes damage)
      • Custom script: call DestroyGroup(udg_Temp_Group)


DmgShow

Code:
Game - Display to [COLOR="Red"](Player group(Player[(Player number of (Triggering player))]))[/COLOR] the text: ((PlayerColors[(Integer A)] + (DmgShowNames[(Integer A)] + |r)) + (: + (String(DamageMeter[DmgShowOrder[(Integer A)]]))))

That one leaks a Player-Group... Suggestion:
Trigger:
  • Set Temp_PGroup = (Player group(Player[(Player number of (Triggering player))]))
    • Game - Display to Temp_PGroup the text: ((PlayerColors[(Integer A)] + (DmgShowNames[(Integer A)] + |r)) + <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> + (String(DamageMeter[DmgShowOrder[(Integer A)]]))))
    • Custom script: call DestroyForce(udg_Temp_PGroup)


DmgOrder

This one also leaks a Player-Group.
Code:
Player Group - Pick every player in [COLOR="Red"](All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User)))[/COLOR] and do (Actions)

And another suggestion:
Trigger:
  • Set Temp_PGroup = (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing)))
    • Player Group - Pick every player in Temp_PGroup and do (Actions)
    • Custom script: call DestroyForce(udg_Temp_PGroup)


Otherwise good jod :D
Though haven't tested yet XD
 

ArmyOfFrogs

New Member
Reaction score
20
Leaderboard is hidden, only used it for ordering the damage. Don't think theres an easy way to put those values in order outside of that. And thanks for posting the leaks, will get to fixing that ^^
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
In the first two trigger remove the units from the group other wise when a unit enters the same unit will be added to the event again
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
But not the unit enters playable map area its not :D
 

Komaqtion

You can change this now in User CP.
Reaction score
469
But then you mean that he should add that unit to a unit group, and then use a condition checking if it's in that group and if not, then add it to it and add the event ... right ?? Since no unit-group is created in that trigger so how can it be removed ??? :S
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
Yes but no checking just remove the unit. Plain and simple
 

vypur85

Hibernate
Reaction score
803
Added a little stuff. As for the unit group debate stuff, I think it can be ignored.

Code:
Damage Detect New Units
    Events
        Unit - A unit enters (Playable map area)
    Conditions
    Actions
        Trigger - Add to DamagesAdd <gen> the event (Unit - (Triggering unit) Takes damage)


Code:
Preplaced Units
    Events
        Map initialization
    Conditions
    Actions
        Set Temp_Group = (Units in (Playable map area))
        Unit Group - Pick every unit in Temp_Group and do (Actions)
            Loop - Actions
                Trigger - Add to DamageAdd <gen> the event (Unit - (Picked unit) Takes damage)
        Custom script:   call DestroyGroup(udg_Temp_Group)
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Trigger - Add to DmgShow <gen> the event (Player - (Picked player) types a chat message containing -dmg as An exact match)


Code:
DamageAdd
    Events
    Conditions
        (Owner of (Damage source)) Not equal to Player 11 (Red)
        (Owner of (Damage source)) Not equal to Player 12 (Blue)
    Actions
        Set DamageMeter[(Player number of (Owner of (Damage source)))] = (DamageMeter[(Player number of (Owner of (Damage source)))] + (Integer((Damage taken))))


Code:
DmgShow
    Events
    Conditions
    Actions
        Trigger - Run DmgOrder <gen> (ignoring conditions)
        Wait 0.50 seconds
        Set Temp_PGroup = (Player group(Player[(Player number of (Triggering player))]))
        For each (Integer A) from 1 to PlayersActive, do (Actions)
            Loop -
                Game - Display to Temp_PGroup the text: (((DmgShowNames[(Integer A)]) + (:  + (String(DamageMeter[DmgShowOrder[(Integer A)]]))))
        Custom script:   call DestroyForce(udg_Temp_PGroup)


Code:
DmgOrder
    Events
    Conditions
    Actions
        Leaderboard - Create a leaderboard for (All players) titled damage order
        Leaderboard - Hide (Last created leaderboard)
        Set Temp_PGroup = (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User)))
        Player Group - Pick every player in Temp_PGroup and do (Actions)
            Loop - Actions
                Leaderboard - Add (Picked player) to (Last created leaderboard) with label Rank and value DamageMeter[(Player number of (Picked player))]
        Leaderboard - Sort (Last created leaderboard) by Value in Descending order
        For each (Integer A) from 1 to PlayersActive, do (Actions)
            Loop - Actions
                Set DmgShowNames[(Integer A)] = (Name of (Player in position (Integer A) of (Last created leaderboard)))
                Set DmgShowOrder[(Integer A)] = (Position of Player[(Integer A)] in (Last created leaderboard))
        Leaderboard - Destroy (Last created leaderboard)
        Custom script:   call DestroyForce(udg_Temp_PGroup)

Edit:
My comment: I personally feel that this snippet is not such a good idea. It's too general and simple.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top