• 🏆 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!

Building generates gold per x second

Status
Not open for further replies.
Level 22
Joined
Aug 27, 2013
Messages
3,973
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