• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Gold System Wanted

Status
Not open for further replies.
Level 5
Joined
Oct 20, 2019
Messages
60
Hello, iv'e been looking around and searched for a gold system that fits my map but it doesn't seem to be a tutorial about it and other posts about gold income are all mostly about a in game time repeated trigger.

Maybe i missed to look somewhere but anyhow, i'll just explain what im searhing for.

I'm making a survival map where it comes waves of creatures and bosses and you'll have to defend your city against them.
What i would like to add is a gold system that makes all players that are playing (player 1-5) to share the amount of gold they are getting from killing the creatures and bosses.

To put simply, if player 1 is getting the last hit on a enemy unit and receives 40 gold then i would like all the rest of the 4 players to receives the same amount of gold.

I'm pretty new to triggers so i don't know how advanced this is but i would really appreciate the help =)
 
Level 9
Joined
Sep 20, 2015
Messages
385
You can use a player group, and them when a unit is killed you give gold to all the players

upload_2019-11-2_21-58-38.png


Instead of all players you put something like Survivors
 
Level 39
Joined
Feb 27, 2007
Messages
5,036
@wc3neverdies that's not really what the OP wants because it doesn't track gold from kills and share it.

The easiest way to do this (IMO) is to read the gold bounty fields from a unit when it dies and use those numbers to generate gold for other players. The potential problem with this is that if your gold bounty fields don't have a 0 in either number of dice or sides per die then the amount given to the killer is randomly rolled between the min and max based on those fields. If you have a 0 in either (or both) of the fields I mentioned then it only awards the base gold bounty on death. With a randomized bounty you will not be certain you're giving the exact same gold to other players.

  • Events
    • Time - Elapsed game time is 0.50 seconds //don't use the map init event
  • Conditions
  • Actions
    • Player Group - Add Player 1 (Red) to HUMANS
    • Player Group - Add Player 2 (Blue) to HUMANS
    • Player Group - Add Player 3 (Teal) to HUMANS
    • Player Group - Add Player 4 (Purple) to HUMANS
    • Player Group - Add Player 5 (Yellow) to HUMANS
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Owner of (Killing Unit)) is in HUMANS) equal to True
    • ((Triggering Unit) belongs to an enemy of (Owner of (Killing Unit))) equal to True //don't gain gold from killing your allies or your own units
  • Actions
    • Set GOLD = (Unit: (Triggering unit)'s Integer Field: Gold Bounty Awarded - Base ('ubba')) //I'm assuming you're using a flat gold bounty per unit here, if randomized you'll have to make this line more complicated
    • Player Group - Remove (Owner of (Killing Unit)) from HUMANS
    • Player Group - Pick every player in HUMANS and do (Actions)
      • Loop - Actions
        • Player - Add GOLD to (Picked Player) current gold //this action is called "player - add property"
    • Player Group - Add (Owner of (Killing Unit)) to HUMANS
 
Level 5
Joined
Oct 20, 2019
Messages
60
The easiest way to do this (IMO) is to read the gold bounty fields from a unit when it dies and use those numbers to generate gold for other players. The potential problem with this is that if your gold bounty fields don't have a 0 in either number of dice or sides per die then the amount given to the killer is randomly rolled between the min and max based on those fields. If you have a 0 in either (or both) of the fields I mentioned then it only awards the base gold bounty on death. With a randomized bounty you will not be certain you're giving the exact same gold to other players.

  • Events
    • Time - Elapsed game time is 0.50 seconds //don't use the map init event
  • Conditions
  • Actions
    • Player Group - Add Player 1 (Red) to HUMANS
    • Player Group - Add Player 2 (Blue) to HUMANS
    • Player Group - Add Player 3 (Teal) to HUMANS
    • Player Group - Add Player 4 (Purple) to HUMANS
    • Player Group - Add Player 5 (Yellow) to HUMANS
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Owner of (Killing Unit)) is in HUMANS) equal to True
    • ((Triggering Unit) belongs to an enemy of (Owner of (Killing Unit))) equal to True //don't gain gold from killing your allies or your own units
  • Actions
    • Set GOLD = (Unit: (Triggering unit)'s Integer Field: Gold Bounty Awarded - Base ('ubba')) //I'm assuming you're using a flat gold bounty per unit here, if randomized you'll have to make this line more complicated
    • Player Group - Remove (Owner of (Killing Unit)) from HUMANS
    • Player Group - Pick every player in HUMANS and do (Actions)
      • Loop - Actions
        • Player - Add GOLD to (Picked Player) current gold //this action is called "player - add property"
    • Player Group - Add (Owner of (Killing Unit)) to HUMANS
[/QUOTE]

This looks very promising, i will gladly test this =)
However, i lack a great deal of experience regarding triggers and i'm a bit of a newbie x)
Could you give me some more information? =)
Like what type of Variables are you using and also where to find these conditions, i had no problem finding ((Triggering Unit) belongs to an enemy of (Owner of (Killing Unit))) equal to True but im having problems finding how to get ((Owner of (Killing Unit)) is in HUMANS) equal to True
I'm guessing you're using Player Group variable for HUMANS and Integer variable for GOLD but im not 100% certain of this since im new at this.
 
Level 39
Joined
Feb 27, 2007
Messages
5,036
For conditions, always check what is being compared. Here it's <something> equal to true. "True" is a boolean value, therefore it is a boolean comparison. From within that comparison window it's probably called "player group contains unit" or something of that nature. Yes they are a player group and integer. These should be deducible from context about the way they are used.
 
Last edited:
Level 5
Joined
Oct 20, 2019
Messages
60
For conditions, always check what is being compared. Here it's <something> equal to true. "True" is a boolean value, therefore it is a boolean comparison. From within that comparison window it's probably called "player group contains unit" or something of that nature. Yes they are a player group and integer. These should be deducible from context about the way they are used.

Thank you for your help, it seems to be working really nice =)
+rep
 
Level 2
Joined
Nov 10, 2019
Messages
14
To be sure to get the exact same through a kill with randomized gold bounty, wouldn't you just be able to compare gold before the kill, with gold after the kill. And then add the difference to the players?
 
Level 39
Joined
Feb 27, 2007
Messages
5,036
Sure, but when the death event fires the player has already gained gold so the only way to know what the gold was before is to run a low timeout periodic timer and hope only one unit died since the last ping.

You could store the player’s gold from the last death event and compare it, but if they gain gold in other ways or buy/sell something in that time you’ll miss it. Those can be accounted for too but I think it would instead be easier just to randomize the gold given manually instead.
 
Level 2
Joined
Nov 10, 2019
Messages
14
When a unit is being attacked, the trigger "attacking begins" runs, and will run "check for gold updates" trigger by setting boolred/blue to true.

Owner of attacking unit should be set to the player setting off the action, while owner of attacked unit should NOT equal to team mates, or yourself for that matter.

  • attacking begins
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Attacking unit)) Equal to Player 1 (Red)
          • (Owner of (Attacked unit)) Not equal to Player 1 (Red)
          • (Owner of (Attacked unit)) Not equal to Player 2 (Blue)
          • (Owner of (Attacked unit)) Not equal to Player 3 (Teal)
          • (Owner of (Attacked unit)) Not equal to Player 4 (Purple)
        • Then - Actions
          • Set boolred = True
          • Trigger - Turn on check for gold updates red <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Attacking unit)) Equal to Player 2 (Blue)
          • (Owner of (Attacked unit)) Not equal to Player 1 (Red)
          • (Owner of (Attacked unit)) Not equal to Player 2 (Blue)
          • (Owner of (Attacked unit)) Not equal to Player 3 (Teal)
          • (Owner of (Attacked unit)) Not equal to Player 4 (Purple)
        • Then - Actions
          • Set boolblue = True
          • Trigger - Turn on check for gold updates blue <gen>
        • Else - Actions
When a unit dies boolred will be set to off, so that "check for goldupdates" doesn't run for infinity.
"redgoldint 2" is calculated by red's current gold, after the kill, minus red's gold before the kill through the integer "redgoldint". You might want to make redgoldint, bluegoldint, tealgoldint and purpgoldint variables indo indexes. this way you'll have half as many variables. Like I did with tealgoldint & purpgoldint.

Now while we're waiting from the attack begins till a unit dies by an attack, there's a gap where gold given by allied, other triggers, selling or buying items etc, could eventually screw up the amount of gold passed to redgoldint2. Therefore the check for gold updates triggers are created.

  • unit dies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Killing unit)) Equal to Player 1 (Red)
          • (Owner of (Dying unit)) Not equal to Player 1 (Red)
          • (Owner of (Dying unit)) Not equal to Player 2 (Blue)
          • (Owner of (Dying unit)) Not equal to Player 3 (Teal)
          • (Owner of (Dying unit)) Not equal to Player 4 (Purple)
        • Then - Actions
          • Set boolred = False
          • Set redgoldint2 = ((Player 1 (Red) Current gold) - redgoldint)
          • Set redgoldint = (Player 1 (Red) Current gold)
          • Player Group - Pick every player in (All players matching ((Color of (Picked player)) Not equal to Red)) and do (Player - Add redgoldint2 to (Picked player) Current gold)
          • Set bluegoldint = ((Player 2 (Blue) Current gold) + redgoldint2)
          • Set tealgoldint[1] = ((Player 3 (Teal) Current gold) + redgoldint2)
          • Set purpgoldint[1] = ((Player 4 (Purple) Current gold) + redgoldint2)
        • Else - Actions
While boolred/boolblue is true, we're waiting for the unit to die we're checking every 10 seconds for a gold change, and then updating the redgoldint/bluegoldint to the players current gold. When the current gold has changed, the trigger runs itself once more until a unit dies.

  • check for gold updates red
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • boolred Equal to True
        • Then - Actions
          • Wait until (redgoldint Not equal to (Player 1 (Red) Current gold)), checking every 0.10 seconds
          • Set redgoldint = (Player 1 (Red) Current gold)
          • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions
  • check for gold updates blue
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • boolblue Equal to True
        • Then - Actions
          • Wait until (bluegoldint Not equal to (Player 2 (Blue) Current gold)), checking every 0.10 seconds
          • Set bluegoldint = (Player 2 (Blue) Current gold)
          • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions
This should work for you, then you don't need to manually randomize gold bounty of every unit in your desire.

EDIT:
red/blue/teal/purpgoldint are integer variables.
boolred/blue are boolean variables set to false by default.
Players could be added to a player could to shorten conditions.
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,036
That is absolutely not going to work, and I would not recommend using it. I don’t really have the time to critique that method right now but I’ll circle back to this thread after I sleep. In short, though:

  • The ‘unit is attacked’ event doesn’t fire for spell casts so the trigger will not ‘see’ the gold right before the killing blow from spells or periodic effects.
  • “Wait for condition” should realistically never be used. It’s not bad per se, but it should be avoided. It also can’t check every 0.10 seconds because it’s limited by the TriggerSleepAction minimum of ~0.27s
  • There is a lot of hardcoding of separate variables where arrays should be used instead.
 
Status
Not open for further replies.
Top