• 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.

Building generates gold per x second

Status
Not open for further replies.

Rheiko

Spell Reviewer
Level 26
Joined
Aug 27, 2013
Messages
4,214
So as the title said. Basically, I'm trying to make, let's say a farm, which generates +25 gold per 10 seconds.
But I will have multiple farms at once, each generates +25 gold per 10 seconds. The thing is I want the 10 seconds timer starts after the farm finishes its construction for each farm. And of course, the value for the gold generation will also decrease if one of the farms die.

I've seen some threads about this before but I couldn't find them.
I would be really grateful if you can tell me how to make it.

Thanks in advance.
 
Code:
Event
    Building finished construction

Condition
    UnitType is from Type "Farm"

Actions

    // Indexing
    Set MaxIndex = MaxIndex + 1
    Set MaxTimeout[MaxIndex] = 10.00
    Set Farm[MaxIndex] = GetTriggeringUnit
    Set CurrentTimeout[MaxIndex] = 10.00
    Set Player[MaxIndex] = GetTriggeringPlayer
    Set Income[MaxIndex] = 25

Code:
Event
    Every 1 Seconds

Actions

    Loop for CurrentIndex from 1 to MaxIndex:

        If (Farm[CurrentIndex] is Dead == True) Then
            
            // Deindexing
           
            Set MaxTimeout[CurrentIndex] = MaxTimeout[MaxIndex]
            Set Farm[CurrentIndex] = Farm[MaxIndex]
            Set CurrentTimeout[CurrentIndex] = CurrentTimeout[MaxIndex]
            Set Player[CurrentIndex] = Player[MaxIndex]
            Set Income[CurrentIndex] = Income[MaxIndex]
            Set MaxIndex = MaxIndex - 1
            Set CurrentIndex = CurrentIndex - 1


        Else

            // Give gold income if time is up and reste timer
            Set CurrentTimeout[CurrentIndex] = CurrentTimeout[CurrentIndex] - 1
            If ( CurrentTimeout[CurrentIndex] <= 0) Then
                Set Timeout[CurrentIndex] = MaxTimeout[CurrentIndex]
                Player - Add Income[CurrentIndex] to current gold of Player[CurrentIndex]
            EndIf

        EndIf
    EndLoop

^More or less this I guess. Instead of also indexing TriggeringPlayer you always could get the owner right before you give income, so OwnerOf(Farm[CurrentIndex]) -- though this is only needed if there is a chance that the farm can change owners.
 
Status
Not open for further replies.
Top