HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Leaderboard unit count

04-15-2009, 06:33 AM#1
flatleyld
Something is wrong with my triggers in that it wont count the units of every player and post them in the leaderboard.

Trigger:
Create Board
Collapse Events
Time - Timer expires
Conditions
Collapse Actions
Wait 2.00 game-time seconds
Leaderboard - Create a leaderboard for (All players) titled Units remaining
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Picked player) controller) Equal to User
Collapse Then - Actions
Leaderboard - Add (Picked player) to (Last created leaderboard) with label (Name of (Picked player)) and value 0
Else - Actions
Leaderboard - Show (Last created leaderboard)
Set UnitCount[(Player number of (Owner of (Picked unit)))] = (Number of units in (Units owned by (Matching player)))
Leaderboard - Change the value for (Matching player) in (Last created leaderboard) to UnitCount[(Player number of (Owner of (Picked unit)))]

Any ideas?
04-15-2009, 11:47 AM#2
Anitarf
This is your problem:
Trigger:
Set UnitCount[(Player number of (Owner of (Picked unit)))] = (Number of units in (Units owned by (Matching player)))
You use options like (matching player) and (picked unit) in a place where they have no meaning.
04-15-2009, 04:42 PM#3
flatleyld
What is the proper way to use picked unit, and matching unit, etc.? Any ideas on the proper set up of this variable?
04-15-2009, 06:32 PM#4
Anitarf
Matching Player/Unit is only used in the conditions for the "pick every player/unit matching condition" action. Picked Player/Unit is only used in the actions of that action. Anywhere else, they have no meaning and return null.

What you want is a loop. I don't really use GUI so this may not be in exactly the right words, but:

for each integer A from 1 to 12 do actions:
Set UnitCount[(integer A)] = (Number of units in (Units owned by (Player(integer A))))
04-15-2009, 06:58 PM#5
flatleyld
The GUI isn't letting me set the variable to (Number of units in (Units owned by (Player(integer A))))

I'm not given the choice to use (Player(Integer A))))

It's either matching player, or picked player that seems the most likely, but they don't work.
04-15-2009, 11:44 PM#6
flatleyld
Okay, so what I need to do correctly is set the variable right. I'm clearly not doing that. So, how do get set that variable to store a count of each players units? Once I get this correct I should be able to get the leader board working right.
04-16-2009, 12:33 AM#7
Anitarf
Quote:
Originally Posted by flatleyld
The GUI isn't letting me set the variable to (Number of units in (Units owned by (Player(integer A))))

I'm not given the choice to use (Player(Integer A))))
Try "conversion - convert player index to player".
04-16-2009, 04:52 AM#8
flatleyld
Thanks, that got me to the line of code you said I should try. But it didn't work. I changed the full trigger around a little bit. See what you think, and where I'm going wrong. The leaderboard still shows 0.

Trigger:
Create Board
Collapse Events
Time - Timer expires
Conditions
Collapse Actions
Wait 1.00 game-time seconds
Collapse For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Set UnitCount[(Integer A)] = (Number of units in (Units owned by (Player((Integer A)))))
Leaderboard - Create a leaderboard for (All players) titled Units remaining
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Picked player) controller) Equal to User
Collapse Then - Actions
Leaderboard - Add (Picked player) to (Last created leaderboard) with label (Name of (Picked player)) and value UnitCount[(Integer A)]
Else - Actions
Leaderboard - Show (Last created leaderboard)
04-16-2009, 05:43 AM#9
0zyx0
Trigger:
Create Board
Collapse Events
Time - Timer expires
Conditions
Collapse Actions
Wait 1.00 game-time seconds
Collapse For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Set UnitCount[(Integer A)] = (Number of units in (Units owned by (Player((Integer A)))))
Leaderboard - Create a leaderboard for (All players) titled Units remaining
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Picked player) controller) Equal to User
Collapse Then - Actions
Leaderboard - Add (Picked player) to (Last created leaderboard) with label (Name of (Picked player)) and value UnitCount[Player Number of (Picked Player))]
Else - Actions
Leaderboard - Show (Last created leaderboard)

You are using integer A outside a loop. This should be better.
04-16-2009, 06:12 AM#10
flatleyld
Awesome! That worked! Thank you very much. In testing the leaderboard, I found that my update trigger is only working once. When a unit dies of player owning that unit should lose a unit remaining that is displayed in the leaderboard. Here is the trigger:
Trigger:
Board Update
Collapse Events
Unit - A unit Dies
Conditions
Collapse Actions
Leaderboard - Change the value for (Owner of (Dying unit)) in (Last created leaderboard) to (UnitCount[(Player number of (Picked player))] - 1)
Leaderboard - Sort (Last created leaderboard) by Value in Descending order

Any ideas why it's only working once. Well, I shouldn't say once. Each player get's 1 unit updated on the board then it does nothing if another unit dies.
04-16-2009, 07:01 AM#11
snowtiger
IDK, but I would just recount all units when someone dies, because if you just reduce the number by one, and your trigger somehow misses a unit, you will always be off by 1. If you instead recount, even if you miss one, it will only display the wrong number temporarily.

EDIT: and I would also make a variable to store your leaderbord in, you never now if last created leaderbord is the good one...
04-16-2009, 08:17 AM#12
0zyx0
Or you can have a separate trigger to change UnitCount every time a unit dies. And you can't use picked player outside
Trigger:
Player Group - Pick every player in (All players) and do (Actions)
04-16-2009, 01:26 PM#13
Anitarf
Of course it only works once, since you always set the value of the leaderboard to UnitCount-1, so, no matter how many units die, the leaderboard will always be set to however many units where there at the start minus one. What you need to do is either count the units again, or decrease the variable by 1 using the set variable action.
04-16-2009, 05:25 PM#14
flatleyld
Sorry to keep bugging everyone about this. Late last night I had the thought to just recount all of the units every time a unit died. I thought that it would be something easy for me to do. But alas, it doesn't work for me. Here's what I did with the update trigger:

Trigger:
Board Update
Collapse Events
Unit - A unit Dies
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Set UnitCount[(Integer A)] = (Number of units in (Units owned by (Player((Integer A)))))
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Collapse Then - Actions
Leaderboard - Change the value for (Picked player) in (Last created leaderboard) to UnitCount[(Player number of (Picked player))]
Else - Actions
Leaderboard - Sort (Last created leaderboard) by Value in Descending order

It doesn't update at all.