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

Giving gold to player with lowest amount of kills

Status
Not open for further replies.
Level 7
Joined
Aug 5, 2010
Messages
147
I have a trigger that gives gold to players at the end of a wave, i am trying to give extra gold to the player with the lowest kills.

I have managed to make it so Player 1 gets extra gold but the method i used to do this would mean i have to create a lot of extra actions that i dont think i need to do, as im guessing their is a better way to do this. My trigger also does not account for when multiple players have the same amount of kills.

Trigger is below

  • Gold After Wave
    • Events
    • Conditions
    • Actions
      • Set GoldAfterWave = (GoldAfterWave + (Random integer number between 20 and 40))
      • Set PlayerGroup[7] = (All allies of Player 1 (Red))
      • Player Group - Pick every player in PlayerGroup[7] and do (Actions)
        • Loop - Actions
          • Player - Add GoldAfterWave to (Picked player) Current gold
      • Game - Display to PlayerGroup[7] the text: (|cff00FF00You have completed a wave and have been given |r + (|cffFDD017 + ((String(GoldAfterWave)) + ( Gold + |r))))
      • For each (Integer A) from 2 to 9, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Kills[1] Less than Kills[(Integer A)]
            • Then - Actions
              • Player - Add (GoldAfterWave / 2) to Player 1 (Red) Current gold
              • Game - Display to PlayerGroup[7] the text: ((MultiBoard_Colours[1] + (Name of Player 1 (Red))) + (|r |cff00FF00has been given|r |cffFDD017 + ((String((GoldAfterWave / 2))) + ( Extra Gold + |r |cff00FF00for having the lowest amount of kills.|r))))
            • Else - Actions
      • Custom script: call DestroyForce(udg_PlayerGroup[7])
 

EdgeOfChaos

E

EdgeOfChaos

I can't really track what you're doing right now. Here is a basic set of steps/algorithm to find the player with the lowest amount of kills.

1: Initialize a variable for the lowest number of kills found for any player. Set it initially to a very high number (like 1000000)
2: Initialize a variable for the player number of the player with the least amount of kills. Set it initially to -1 or something.
3: Loop through each player.
4: If player's kills are less than lowest kills found:
5: Set the lowest kills found to this player's kills
6: Set the player number found to this player's number

And you're done. You will have found the lowest # of kills and which player that is.

If you want to treat same kills in a fair way, it becomes more complex and I recommend you get the basic functionality first.

Here's some code, I don't promise this works as-is but should show the process:
JASS:
local integer lowestKills = 1000000
local integer playerNum = -1
local integer i = 0
loop
   exitwhen i >= 12
   if(udg_Kills[i] < lowestKills)then
      set lowestKills = udg_Kills[i]
      set playerNum = i
   endif
   set i = i + 1
endloop
 
Level 7
Joined
Aug 5, 2010
Messages
147
I created your trigger in GUI form and then added to it to give gold to the player with the lowest kills. I tested it with 3 players me and 2 ai, i was getting most kills player 2 was getting some kills and player 3 no kills, trigger worked for 3 waves. i then let player 3 get a kill and the trigger stopped working.

Triggers Below

  • Gold After Wave
    • Events
    • Conditions
    • Actions
      • Set GoldAfterWave = (GoldAfterWave + (Random integer number between 20 and 40))
      • Set PlayerGroup[7] = (All allies of Player 1 (Red))
      • Player Group - Pick every player in PlayerGroup[7] and do (Actions)
        • Loop - Actions
          • Player - Add GoldAfterWave to (Picked player) Current gold
      • Game - Display to PlayerGroup[7] the text: (|cff00FF00You have completed a wave and have been given |r + (|cffFDD017 + ((String(GoldAfterWave)) + ( Gold + |r))))
      • Custom script: call DestroyForce(udg_PlayerGroup[7])
      • Trigger - Run Gold After Wave Low Kills <gen> (ignoring conditions)
  • Gold After Wave Low Kills
    • Events
    • Conditions
    • Actions
      • Set PlayerGroup[7] = (All allies of Player 1 (Red))
      • Set LowestKills = 100000
      • Set PlayerNumber = -1
      • Set I = 1
      • For each (Integer I) from 1 to 9, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Kills[I] Less than LowestKills
            • Then - Actions
              • Set LowestKills = Kills[I]
              • Set PlayerNumber = I
            • Else - Actions
              • Set I = (I + 1)
      • Set PlayerGroup_LowKills = (Player group((Player(PlayerNumber))))
      • Player Group - Pick every player in PlayerGroup_LowKills and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Player - Add (GoldAfterWave / 2) to (Picked player) Current gold
              • Game - Display to PlayerGroup[7] the text: ((MultiBoard_Colours[PlayerNumber] + (Name of (Picked player))) + (|r |cff00FF00has been given|r |cffFDD017 + ((String((GoldAfterWave / 2))) + ( Extra Gold + |r |cff00FF00for having the lowest amount of kills.|r))))
            • Else - Actions
      • Custom script: call DestroyForce(udg_PlayerGroup[7])
      • Custom script: call DestroyForce(udg_PlayerGroup_LowKills)
 
Status
Not open for further replies.
Top