# Victory Condition Kill Count

Discussion in 'World Editor Help Zone' started by Mechcash, Apr 28, 2019.

1. ### Mechcash

Joined:
May 30, 2018
Messages:
123
Resources:
0
Resources:
0
Hello

I have a rather simple question. How do I create a victory condition, which triggers when a player reaches a certain kill count? Basically: A player wins, when he reaches 10 kills.

2. ### Chaosium

Joined:
Aug 29, 2012
Messages:
416
Resources:
2
Models:
2
Resources:
2
You have to keep count of each player's kills using an integer variable with an array.

E.g. Killcount[1] will be used for player 1, and so on.

Then, when an unit dies, you set Killcount[player number of owner of killing unit] to (Killcount[player number of owner of killing unit] + 1) to increase the count.

Finally, use a if/then/else to check whether Killcount[player number of owner of killing unit] is equal or greater to 10, and if so, trigger victory.

That's pretty basic but should do the trick.

### Code Moderator

Joined:
Jun 23, 2007
Messages:
3,696
Resources:
22
Spells:
11
Tutorials:
2
JASS:
9
Resources:
22
The game also keeps track of how many kills you have. If you don't need any specific conditions for the kills then you can use
`GetPlayerScore(Player(0), PLAYER_SCORE_UNITS_KILLED)`

4. ### Mechcash

Joined:
May 30, 2018
Messages:
123
Resources:
0
Resources:
0
Pardon me, but where do I find "GetPlayerScore", sorry just can't find it

5. ### Mechcash

Joined:
May 30, 2018
Messages:
123
Resources:
0
Resources:
0

I came up with this, bit it doesn't seem to work. Please enlighten me on what I did wrong Sir.

6. ### Chaosium

Joined:
Aug 29, 2012
Messages:
416
Resources:
2
Models:
2
Resources:
2
Almost there, I believe your If should be "If kill_count[(player number of (owner of killing unit))] greater than or equal to 2", because right now it only checks what's the player number of the killing unit, not their kills

7. ### Tasyen

Joined:
Jul 18, 2010
Messages:
1,448
Resources:
18
Tools:
2
Maps:
3
Spells:
8
Tutorials:
4
JASS:
1
Resources:
18
Playerscore is accessed in GUI when choosing the value of an integer (number without fractions). Inside the popup menu to select the value go to the category player. Look for something like "Player - Player Score".

Joined:
May 2, 2011
Messages:
933
Resources:
1
Maps:
1
Resources:
1
event:
unit dies.

9. ### Mechcash

Joined:
May 30, 2018
Messages:
123
Resources:
0
Resources:
0
Aww sorry to disturb you again, but still doesn't seem to work :c any other suggestions?

Or did I do something wrong with the kill_count variable?

10. ### Sabe

Joined:
Jul 30, 2018
Messages:
431
Resources:
1
Spells:
1
Resources:
1
For the victory action use Owner of (Killing unit), just like in the previous cases.

• Game - Victory (Owner of (Killing unit)) (Show dialogs, Show scores)

11. ### Chaosium

Joined:
Aug 29, 2012
Messages:
416
Resources:
2
Models:
2
Resources:
2
Yep, as Sabe said.

Also, you'll want to increase the array up to the maximum number of players in your map, otherwise it will only work for player 1.

12. ### Mechcash

Joined:
May 30, 2018
Messages:
123
Resources:
0
Resources:
0
Yeah, it actually seems to work now, thanks guys

13. ### Pyrogasm

Joined:
Feb 27, 2007
Messages:
3,696
Resources:
1
Spells:
1
Resources:
1
In this case the OP doesn’t need to. In fact in most cases you can safely ignore the GUI array size. For all primitive variables (string, real, int, boolean) it’s unnecessary since loading an uninitialized index just returns “”, 0, or false. For handle (agent would be more generic) variables it will return null which is usually not a problem (though it can be).

However, it really depends on the situation and knowledge of how GUI works behind the scenes. Some variable types for some applications need to be initialized with the variable editor. For example: unit groups. If group[x] is uninitialized and you try to add units to that group nothing will happen because it’s not an empty group variable. If you instead want to assign group[x] = units in some region<gen> then it works fine whether it was initialized or not (and if it was you would actually leak that initial group object when you assign group[x] as above).

14. ### map designer

Joined:
May 2, 2011
Messages:
933
Resources:
1
Maps:
1
Resources:
1
what?

it would return 0 but the value be saved/manipulated????

15. ### Pyrogasm

Joined:
Feb 27, 2007
Messages:
3,696
Resources:
1
Spells:
1
Resources:
1
I'm not sure I understand exactly what you're saying but in general: yes, all array indexes are always safe to access and always return the 'default' value for that type regardless of the GUI array size. Setting Size = N just assigns variable[1]...variable[N] = that default value at map init.

• -------- Int variable has size 3, default value of 6 in the Variable Editor --------
• Set Int[2] = Int[2] + 7
• -------- printing Int[2] would show 13 now --------
• Set Int[833] = Int[833] + 7
• -------- printing Int[833] would show 7 now --------

You do get mildly unpredictable (if you're not familiar with how JASS handles null arguments) behavior for handle types that are uninitialized:

• -------- Point variable has size 1 in the Variable Editor --------
• Set Point[4] = (Center of Region1 <gen>)
• Unit - Move Unit1 to Point[4]
• -------- unit1 now at center of Region1 --------
• Unit - Move Unit2 to Point[223]
• -------- unit2 now at 0,0 since the point passed was null --------
• Custom script: call RemoveLocation(udg_Point[4])
• Unit - Move Unit3 to Point[4]
• -------- unit3 now also at 0,0 showing this is the same behavior for uninitialized indices as for 'destroyed' objects --------