1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  5. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  6. The 13th Music Contest Poll is up! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  7. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Victory Condition Kill Count

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

  1. Mechcash

    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.

    Thanks in advance.
     
  2. Chaosium

    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.
     
  3. TriggerHappy

    TriggerHappy

    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

    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

    Mechcash

    Joined:
    May 30, 2018
    Messages:
    123
    Resources:
    0
    Resources:
    0
    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.
     
  6. Chaosium

    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

    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".
     
  8. map designer

    map designer

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

    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?
    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.
     
  10. Sabe

    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

    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

    Mechcash

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

    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

    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

    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 --------