• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

---> Help me with Income Trigger <---

Status
Not open for further replies.
Level 3
Joined
Aug 18, 2008
Messages
52
Hey, I want to make a trigger that gives 1 gold per 30 seconds as long as a certain unit is alive. I also want it to be like... if you have 30 of that unit (which will be 'Civ Building 1') -> you get 1 gold per 30 seconds X(times) 30 (because you have 30 of those units). I want it to do that with ay number of units. Can someone help?

Rep will be given if it works :grin::grin::grin::grin::grin: so plz help. If you can, add a picture of exactly what the trigegr looks like. I'm a visual type of guy.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
  • Events
    • Every 40 seconds of game time
  • Actions
    • For Each Integer A from 1 to 12 do
      • Loop - Actions
        • set Temp_Unit_Group = All units owned by Player(Integer A) matching: matching unit is a Civ Building 1 equal to true
        • Unit Group - Pick every unit in Temp_Unit_Group and do
          • Player - add 1 gold to Player(Integer A)
        • Custom script: call DestroyGroup(udg_Temp_Unit_Group)
Temp_Unit_Group is - obviously - a unit group variable
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
LoL? Just go to your variable editor (CTRL + B) and create a variable (CTRL + N) of name Temp_Unit_Group and type Unit Group.

Otherwise, use:
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in All units owned by Player(Integer A) matching: matching unit is a Civ Building 1 equal to true and do
    • Player - add 1 gold to Player(Integer A)
 
Level 3
Joined
Aug 18, 2008
Messages
52
sorry im new, but a quick learner with everything but variables. so i name it temp _unit_group and then i... do unit group... how do i preset a unit
 
Level 17
Joined
May 6, 2008
Messages
1,598
Easier;

  • Events
    • Time - Every x seconds.
  • Conditions
  • Actions
    • Unit Group - Pick every units in (Playable Map Area) matching (Matching unit equal to (Income Building))
      • Actions - Loop
        • Player - Add 1 gold to (Owner of (Picked unit))
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Please do not double post.

A variable is the same as the mathimatical equvelents. It represents a value and stores a value for later use.

Huurka's trigger is not recomended as it leaks a group, and groups are one of the largest kinds of variable and so not recomendable to leak.

There are 2 ways to do this which I will give in pusdocode.
1. Every 30 seconds
2. Find every unit of type 'Civ Building 1' that is alive
3. Add 1 gold to the owner of the building for each unit that was found

This is basically what Huurka did but has to be done in a way that it does not leak a group and also checks if they are alive.

Way 2 looks more impressive (better eye candy) as the income remains the same but appears to be added all the time instead of a lump some every 30 seconds.
2 triggers are needed

Globals
Integer Array IncomeBuildings
Timer Array IncomeTime

Build
1. A building is finished being built.
2. The building is of type 'Civ Building 1'
3. Add 1 to IncomeBuildings (at index of the player number of the owner of the built building).
4. Start the timer IncomeTime (at the index of the player number of the owner of the built building) perodically with an expiry time of (30 divided by IncomeBuildings (at index of the player number of the owner of the built building)) running the Income piece of code.

Income
1. Find the player for which the expired timer represented the income of.
2. Add 1 gold to that player's total gold.

Death
1. A unit Dies.
2. The unit is of type 'Civ Building 1'
3. Remove 1 from IncomeBuildings (at index of the player number of the owner of the dieing unit).
4. Start the timer IncomeTime (at the index of the player number of the owner of the dieing unit) perodically with an expiry time of (30 divided by IncomeBuildings (at index of the player number of the owner of the dieing unit)) running the Income piece of code.

As you can see method 2 is slightly more complex but it is up to you what to use.
 
Level 3
Joined
Aug 18, 2008
Messages
52
I FIGURED IT OUT
For those of you who dont understand this either... you need to set variables.
You make a trigegr called set variables and set each varibale to a unit or anythign else that you need. the setup goes like this>>>> ACTIONS
<Variable name> <variable type> <value> (which in my case is a unit)>
VARIABLES ARE HARD BUT KEEP TRYING EVERY1

SET VARIABLE
Events
Map initialization
Conditions
Actions
Set Civ_1 = (Units of type Civ Building 1)
Set Civ_2 = (Units of type Civ Building 2)
Set Civ_3 = (Units of type Civ Building 3)
Set Civ_4 = (Units of type Civ Building 4)
Set Civ_5 = (Units of type Civ Building 5)
Set Civ_6 = (Units of type Civ Building 6)
Set Civ_7 = (Units of type Civ Building 7)
 
Level 3
Joined
Aug 18, 2008
Messages
52
Then i put the variables into a normal trigger


Civ 1 income
Events
Time - Every 30.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in Civ_1 and do (Player - Add 1 to (Owner of (Picked unit)) Current gold)
 
  • Angry
Reactions: Rui

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
But then you noticed that if the buildings die you still get full income althou some are dead.
Equally well, the value does not update if more buildings are added.

Arrays would be a lot more efficent as it would be 1 variable set that works for all players. and 1 trigger that works for all players.

Also counting the ammount to add before adding would be more efficent as variable opperations are much faster than native opperations, especially since in GUI they use a few wrapper functions which makes it even slower.

Also may I point out that his trigger does not leak as it uses a constant group which is always stored in a variable (leaks only occur if objects like locations, effects or groups become lost in the memory as there are no references to them).

goombawithgun,
Do not double post (read rules).
 
Status
Not open for further replies.
Top