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

Victory Condition Kill Count

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
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.

Thanks in advance.
 
Level 20
Joined
Aug 29, 2012
Messages
833
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.
 
Level 7
Joined
May 30, 2018
Messages
290
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)

Pardon me, but where do I find "GetPlayerScore", sorry just can't find it
 
Level 7
Joined
May 30, 2018
Messages
290
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.

upload_2019-4-29_21-18-10.png


I came up with this, bit it doesn't seem to work. Please enlighten me on what I did wrong Sir.
 
Level 20
Joined
Aug 29, 2012
Messages
833
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 :)
 
Pardon me, but where do I find "GetPlayerScore", sorry just can't find it
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".
 
Level 7
Joined
May 30, 2018
Messages
290
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 :)

Aww sorry to disturb you again, but still doesn't seem to work :c any other suggestions?
upload_2019-4-30_19-54-42.png

Or did I do something wrong with the kill_count variable?
upload_2019-4-30_19-56-12.png


Thanks in advance.
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
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.
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).
 
Level 16
Joined
May 2, 2011
Messages
1,345
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).
what?

it would return 0 but the value be saved/manipulated????
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
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 --------
 
Status
Not open for further replies.
Top