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

Scoreboard stat update

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
So guys I have a tricky question ...first of I made a simple trigger for a really basic scoreboard:
upload_2019-5-26_20-31-17.png


which updates the number of a player after he made a kill

upload_2019-5-26_20-31-48.png


I have following problem: I made 1 ability, where a hero summons an unit , this unit is uncontrolable (I made it change teams after it has been summoned. to achieve this uncontrolable effect)

upload_2019-5-26_20-35-12.png


now when this summoned unit kills an enemy, it should also update the score for the player who summoned it, but it doesn't. After the summoned unit kills something it doesn't count towards the players kills, but I would like it to.
Is there a way to fix this issue?
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,010
I believe giving a unit the Ward classification makes it uncontrollable (no buttons on the UI). You could try that instead. The problem with kills is that you're using "Owner of Killing unit" which refers to player 23.... You need to in some way save the original owner of the unit so you can credit them instead. The easiest way to do that would be to set the unit's Custom Value = the summoning player's number when created, then check to see if the unit that did the killing had a non-zero custom value. If so, credit Player(Custom Value) instead:

  • -------- in enter trigger --------
  • Unit - Set (Triggering Unit) Custom value to (Player Number of (Owner of (Triggering Unit)))
  • Unit - Change ownership of (Triggering Unit) to Player 23 (Emerald) and Change color
  • -------- in death trigger --------
  • If (All conditions) then (Actions) else (Actions)
    • If - Conditions
      • (Custom value of (Killing Unit)) greater than 0
    • Then - Actions
      • Set PN = Custom value of (Killing Unit)
    • Else - Actions
      • Set PN = Player number of (Owner of (Killing unit))
  • Set Player_Kills[PN] = Player_Kills[PN] + 1
How To Post Your Trigger. Also move your leaderboard show action in the first trigger outside of the else and outside of the player group pick; it should happen after the LB is fully created.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
The easiest way to do that would be to set the unit's Custom Value = the summoning player's number when created, then check to see if the unit that did the killing had a non-zero custom value. If so, credit Player(Custom Value) instead:
Custom values can conflict with unit indexers. In such a case one can use a hashtable instead to map a value to a unit. If using hashtable one must remember to clear the mappings when the unit is removed from the game to prevent a leak.
 
Level 2
Joined
May 28, 2019
Messages
13
This might be a longer way to go about what you are trying to do but my idea is you can use unit groups to keep track of which units spawned for each player. So the trigger would look like this
upload_2019-5-28_11-23-10.png


You would have to repeat this for each player in the game and then your score trigger would look like this

upload_2019-5-28_11-25-12.png


Note: the condition is a bollean comparison - unit in unit group

And then lastly you will want to make another trigger to check when that summoned unit dies and to remove it from the unit group (if you don't plan to have many of these units at all you might be able to just leave it alone)

So something like

Unit dies

condition: Dying unit is in RedsUnits

Action: Remove Dying unit from RedsUnits
 

Attachments

  • upload_2019-5-28_11-21-50.png
    upload_2019-5-28_11-21-50.png
    20.1 KB · Views: 27
  • upload_2019-5-28_11-24-37.png
    upload_2019-5-28_11-24-37.png
    8.7 KB · Views: 47
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
This might be a longer way to go about what you are trying to do but my idea is you can use unit groups to keep track of which units spawned for each player. So the trigger would look like this
View attachment 324006

You would have to repeat this for each player in the game and then your score trigger would look like this

View attachment 324008

Note: the condition is a bollean comparison - unit in unit group

And then lastly you will want to make another trigger to check when that summoned unit dies and to remove it from the unit group (if you don't plan to have many of these units at all you might be able to just leave it alone)

So something like

Unit dies

condition: Dying unit is in RedsUnits

Action: Remove Dying unit from RedsUnits

Thank you for your suggestion . I will have a look on it :)
 
Level 7
Joined
May 30, 2018
Messages
290
This might be a longer way to go about what you are trying to do but my idea is you can use unit groups to keep track of which units spawned for each player. So the trigger would look like this
View attachment 324006

You would have to repeat this for each player in the game and then your score trigger would look like this

View attachment 324008

Note: the condition is a bollean comparison - unit in unit group

And then lastly you will want to make another trigger to check when that summoned unit dies and to remove it from the unit group (if you don't plan to have many of these units at all you might be able to just leave it alone)

So something like

Unit dies

condition: Dying unit is in RedsUnits

Action: Remove Dying unit from RedsUnits

I'm kinda getting stuck at the "RedsUnits" part, which kind of variable has "RedsUnits" to be?
 
Level 7
Joined
May 30, 2018
Messages
290
I believe giving a unit the Ward classification makes it uncontrollable (no buttons on the UI). You could try that instead. The problem with kills is that you're using "Owner of Killing unit" which refers to player 23.... You need to in some way save the original owner of the unit so you can credit them instead. The easiest way to do that would be to set the unit's Custom Value = the summoning player's number when created, then check to see if the unit that did the killing had a non-zero custom value. If so, credit Player(Custom Value) instead:

  • -------- in enter trigger --------
  • Unit - Set (Triggering Unit) Custom value to (Player Number of (Owner of (Triggering Unit)))
  • Unit - Change ownership of (Triggering Unit) to Player 23 (Emerald) and Change color
  • -------- in death trigger --------
  • If (All conditions) then (Actions) else (Actions)
    • If - Conditions
      • (Custom value of (Killing Unit)) greater than 0
    • Then - Actions
      • Set PN = Custom value of (Killing Unit)
    • Else - Actions
      • Set PN = Player number of (Owner of (Killing unit))
  • Set Player_Kills[PN] = Player_Kills[PN] + 1
How To Post Your Trigger. Also move your leaderboard show action in the first trigger outside of the else and outside of the player group pick; it should happen after the LB is fully created.


would you be so kind and decipher the "PN"-Variable for me. I have no clue what kind of variable I have to put in :(
 
Level 9
Joined
Jul 30, 2018
Messages
445
You can see what kind of variable any variable is by looking at what comes after the = sign. For example: PN = Custom Value of (Killing Unit). Custom Value is an integer, therefore PN is an integer type variable. RedsUnits above there is a Unit Group type variable.

Also you don't have to make Red Player and Emerald Player treat each other allies every time a unit enters the game. You can move those two actions to your Map Initialization trigger, unless you for some reason want to constantly change the alliances back and forth.
 
Level 7
Joined
May 30, 2018
Messages
290
  • updating stats
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Killing unit) belongs to an ally of Player 1 (Red)) Equal to True
      • (Unit-type of (Triggering unit)) Not equal to Imp
      • (Unit-type of (Triggering unit)) Not equal to Acolyte
      • ((Triggering unit) is Summoned) Equal to False
    • Actions
      • Set Player_Kills[(Player number of (Owner of (Killing unit)))] = (Player_Kills[(Player number of (Owner of (Killing unit)))] + 1)
      • Leaderboard - Change the value for (Owner of (Killing unit)) in (Last created leaderboard) to Player_Kills[(Player number of (Owner of (Killing unit)))]
      • Leaderboard - Sort (Last created leaderboard) by Value in Descending order
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Killing unit)) Greater than 0
        • Then - Actions
          • Set PN = (Custom value of (Killing unit))
        • Else - Actions
          • Set PN = (Player number of (Owner of (Killing unit)))
      • Set Player_Kills[PN] = (Player_Kills[PN] + 1)
I copied @Pyrogasm 's trigger. Sadly it doesn't work for me .... :s or did I implement it wrong?
 
Last edited:
Level 2
Joined
May 28, 2019
Messages
13
Your "enter region" trigger needs to have the "Unit - Set (Triggering Unit) Custom value to (Player Number of (Owner of (Triggering Unit)))" action in it

Now in this "unit dies" trigger you need to delete the first action alltogether, it should not be in there.

Move the leaderboard changes to the very end of the trigger

You also need to fix the first leaderboard action. Remember that "killing unit" is owned by player 23. I am confusing myself too much on this so I will let you work out a solution but you need to use your variables here

Lastly you can remove the condition for killing unit belonging to an ally. The custom value will check which player it is. Having that condition in there would force you to remake the trigger for each player in the game but it's not needed

I think just those changes should make it work

EDIT:

I think I figured out the leaderboard so this might be what everything would look like

  • Untitled Trigger 002
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Footman
    • Actions
      • Unit - Set the custom value of (Entering unit) to (Player number of (Owner of (Entering unit)))
      • Player - Make (Owner of (Entering unit)) treat Player 23 (Emerald) as an Ally
      • Player - Make Player 23 (Emerald) treat (Owner of (Entering unit)) as an Ally
      • Unit - Change ownership of (Entering unit) to Player 23 (Emerald) and Retain color
One note: you might want to retain color when changing ownership to show it is still technically red's unit

  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Not equal to Footman
      • (Unit-type of (Dying unit)) Not equal to Footman
      • ((Triggering unit) is Summoned) Equal to False
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Killing unit)) Greater than 0
        • Then - Actions
          • Set PN = (Custom value of (Killing unit))
        • Else - Actions
          • Set PN = (Player number of (Owner of (Killing unit)))
      • Set Player_Kills[PN] = (Player_Kills[PN] + 1)
      • Leaderboard - Change the value for (Player(PN)) in (Last created leaderboard) to Player_Kills[PN]
The 2 variables are

Player_Kills --- This is an integer with array size of however many players there can be

PN --- This is an integer without an array


side note: I learned a lot from trying to figure this out so thanks :)
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
Your "enter region" trigger needs to have the "Unit - Set (Triggering Unit) Custom value to (Player Number of (Owner of (Triggering Unit)))" action in it

Now in this "unit dies" trigger you need to delete the first action alltogether, it should not be in there.

Move the leaderboard changes to the very end of the trigger

You also need to fix the first leaderboard action. Remember that "killing unit" is owned by player 23. I am confusing myself too much on this so I will let you work out a solution but you need to use your variables here

Lastly you can remove the condition for killing unit belonging to an ally. The custom value will check which player it is. Having that condition in there would force you to remake the trigger for each player in the game but it's not needed

I think just those changes should make it work

EDIT:

I think I figured out the leaderboard so this might be what everything would look like

  • Untitled Trigger 002
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Footman
    • Actions
      • Unit - Set the custom value of (Entering unit) to (Player number of (Owner of (Entering unit)))
      • Player - Make (Owner of (Entering unit)) treat Player 23 (Emerald) as an Ally
      • Player - Make Player 23 (Emerald) treat (Owner of (Entering unit)) as an Ally
      • Unit - Change ownership of (Entering unit) to Player 23 (Emerald) and Retain color
One note: you might want to retain color when changing ownership to show it is still technically red's unit

  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Not equal to Footman
      • (Unit-type of (Dying unit)) Not equal to Footman
      • ((Triggering unit) is Summoned) Equal to False
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Killing unit)) Greater than 0
        • Then - Actions
          • Set PN = (Custom value of (Killing unit))
        • Else - Actions
          • Set PN = (Player number of (Owner of (Killing unit)))
      • Set Player_Kills[PN] = (Player_Kills[PN] + 1)
      • Leaderboard - Change the value for (Player(PN)) in (Last created leaderboard) to Player_Kills[PN]
The 2 variables are

Player_Kills --- This is an integer with array size of however many players there can be

PN --- This is an integer without an array


side note: I learned a lot from trying to figure this out so thanks :)

I cannot thank you and of course anyone else enough! It finally works :-D!! thank you thank you thank you guys
 
Status
Not open for further replies.
Top