• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

[General] Player trains a unit counter & gold.

Status
Not open for further replies.
Level 2
Joined
Sep 7, 2011
Messages
10
Greetings,

How do you make it so that when (Player Red) trains (Footman) make his income increase +1 every second for every (Footman) trained thereof.

I have been reading about variables since I am fairly new to this and it's honestly getting me a headache as I can't figure out how this works. :goblin_wtf:

I am also doing it for multiple unit-types as well as different players, but knowing how to do this with footman alone should be enough for me to understand.

Thank you for your time. :wink:
 
Level 8
Joined
Jan 8, 2010
Messages
493
the following trigger will increase a counter (in this case, Gold which an integer variable) everytime Player 1 finishes training a Footman.
  • Finish Training
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Footman
      • (Owner of (Trained unit)) Equal to Player 1 (Red)
    • Actions
      • Set Gold = (Gold + 1)
  • Gold Trigger
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Player - Add Gold to Player 1 (Red) Current gold
note that these triggers will add gold to Player 1's current gold regardless if a trained Footman dies. if a dying Footman will decrease his income, create another trigger where the variable Gold decreases whenever a Footman owned by Player 1 dies.

if you want to have only 1 trigger (instead of those three), you can just use
  • Gold Trigger
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup=true
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red) of type Footman) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Player - Add 1 to Player 1 (Red) Current gold
            • Else - Actions
that trigger picks every Footman Player 1 has, checks if it is alive and then adds 1 Gold to Player 1's current gold. If he has 20 Footmen and 4 suddenly died, this trigger will add 16 gold. but if the gold increases only by training a Footman and has no way to decrease, the first trigger is enough.
 
Level 2
Joined
Sep 7, 2011
Messages
10
Sorry, perhaps there's a misunderstanding.
It was my fault because I had worded my problem incorrectly.

What I am having trouble with is that when [Player1 Red] Created a [Footman] and is successfully completed then [Every 45 Seconds] Increase [Player1 Red] gold + 1.

So if I had 35 created over the course of the game, Player Red would get 35 gold every 45 seconds.

Or if Player Red made a riflemen he would get granted 5 gold for the 45 seconds that overlaps.

So lets say Player 1 Red makes 5 footman and 1 rilemen over the course of the game, he would get 10 gold per 45 seconds that elapse.

I'm trying to make a "Create X unit" Recieve X gold = to what unit was trained every 45 seconds.

If there's confusion, please let me know. This is something I can't quite grasp the concept of creating.

Thank you for your time.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
  • Increase Income
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Footman
        • Then - Actions
          • Set Income[(Player number of (Owner of (Trained unit)))] = (Income[(Player number of (Owner of (Trained unit)))] + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Rifleman
        • Then - Actions
          • Set Income[(Player number of (Owner of (Trained unit)))] = (Income[(Player number of (Owner of (Trained unit)))] + 5)
        • Else - Actions
  • Give Income
    • Events
      • Time - Every 45.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer i) from 1 to 12, do (Actions)
        • Loop - Actions
          • Player - Add Income[i] to (Player(i)) Current gold
Note: In the above trigger, you must change 12 to however many players you have.

A Question:
If you train one Footman, your income is 1. If the Footman dies, do you want the income to remain the same or decrease?
 
Level 2
Joined
Sep 7, 2011
Messages
10
Remain the same.
However, I don't understand how to implement the following:

Set Income[(Player number of (Owner of (Trained unit)))] = (Income[(Player number of (Owner of (Trained unit)))] + 1)

Could you break it down?
 
Level 8
Joined
Jan 8, 2010
Messages
493
Income is an arrayed integer variable. when creating a variable, tick the []Array check box. you can just leave the size at 1.

i assume you know how to set a variable in triggers. set Income[Index] = Value
click Index.
Player - Player Number -> Click Triggering Player
Owner Of Unit -> Click (Triggering Unit)
Event Response - Trained Unit

click Value
Arithmetic -> Click Value
..then just follow the example on Index.
 
Level 2
Joined
Sep 7, 2011
Messages
10
Thank you both for your help! The demo map executed what I wanted to implement in my map correctly. :fp: + Rep

-- A question for clarification --
You stated that "In the above trigger, you must change 12 to however many players you have"

I have 10 players (2 of which are computers) does this integer mean if effects all players? I don't care if the computer is apart of the integer. I am just double checking if the 1 - 12 integer will effect all players creating footman, riflemen, etc?

-- Another question --
How do I display in text to [Player X] how much gold he has recieved throughout the game? Like Red, Blue, Whomever will recieve a message [every 45 seconds] stating they got [N] amount of gold.
Would this complicate the original trigger?
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
1. It doesn't really matter - I would set it to 10. Just as long as it is equal to or greater than the number of players.

2.
  • Give Income
    • Events
      • Time - Every 45.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Player - Add Income[i] to (Player(i)) Current gold
          • Game - Display to (Player group((Player(i)))) the text: (Your income is |cffffcc00 + ((String(Income[i])) + |r gold.))
 
Level 2
Joined
Sep 7, 2011
Messages
10
The text: (Your income is |cffffcc00 + ((String(Income)) + |r gold.)) Doesn't seem to work. In-game it displays: Your income is + ((String(Income)) + gold.

Is there something I'm doing incorrectly?
 
Level 8
Joined
Jan 8, 2010
Messages
493
the part ((String(Income)) is not really a text. you will have to use the function (Convert Integer To String) and use the variable Income.

when you use the Game - Text Message function, don't write anything yet but look for the Concatenate Strings function. you will see String 1 + String 2.
click String 1.
write Your income is |cffffcc00. click Ok.
click String 2. look for Concetenate Strings function again.
click String 1. look for Convert Integer To String function.
i know it will be defaulted to Player Number of (Triggering Player). change it to the variable Income[Index]. for the Index change it to variable i. click Ok.
Click String 2. write |r gold.

using Concatenate Strings function will help you use variables or other functions that are not really strings.
 
Status
Not open for further replies.
Top