# [General]Player trains a unit counter & gold.

Status
Not open for further replies.

#### Og Nomin

Level 2
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.

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.

#### ronojales

Level 8
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.

#### Mr_Bean

Level 17
You should also make your "Gold" variable an array if he wants it to work for more than one player, which I imagine he does.

#### Og Nomin

Level 2
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.

#### Mr_Bean

Level 17
• 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?

#### Og Nomin

Level 2
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?

#### ronojales

Level 8
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.

#### Mr_Bean

Level 17
To help with ronojales' explanation, I have attached a demo map.

#### Attachments

• Income Demo Map.w3x
16.4 KB · Views: 48

#### Og Nomin

Level 2
Thank you both for your help! The demo map executed what I wanted to implement in my map correctly. + 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?

#### Mr_Bean

Level 17
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.))

#### Og Nomin

Level 2
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?

#### ronojales

Level 8
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.

Replies
2
Views
496
Replies
11
Views
750
Replies
13
Views
715
Replies
6
Views
984
Replies
5
Views
1K