HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Very Simple "Bank" Trigger

03-18-2007, 04:50 AM#1
scmstrack06
This trigger is for a building that you can call a bank. You don't store money in it. It is like the money farm in sheep tag, each one you have gives you x gold every x seconds.

Code:
Bank
    Events
        Unit - A unit Finishes construction
    Conditions
        (Unit-type of (Constructed structure)) Equal to Bank
        ((Constructed structure) is alive) Equal to True - Makes it so once it is destroyed, you don't receive money anymore.
    Actions
        Wait 'EVERY X SECONDS YOU WANT THE GOLD DISTRIBUTED' seconds
        Player - Add 'ANY NUMBER OF GOLD YOU WANT GIVEN' to (Owner of (Triggering unit)) Current gold
        Trigger - Run Bank <gen> (checking conditions)
03-18-2007, 05:01 AM#2
ixmike88
Is this a contribution?
03-18-2007, 07:39 AM#3
FatalError
Hmm...nice, never thought about doing it that way. I usually do it the complicated way and have a periodic timer. But that works. XD
03-18-2007, 08:30 AM#4
Pyrogasm
Ah HA! The problem with doing it this way is that it is not MUI, and will only work for 1 bank.

EDIT: And please use [trigger], not [code], tags next time.
03-18-2007, 09:44 AM#5
NmdSnprEnigma
Tried it. MUI for more 'banks'. Didn't check for more players though.
03-18-2007, 10:30 AM#6
WNxCryptic
Best way to do it:

GUI:

Trigger:
Ent Gold
Collapse Events
Time - Every 10.00 seconds of game time
Conditions
Collapse Actions
Set temp = (All allies of (Whoever gets the periodic gold check)
Player Group - Pick every player in temp and do (Player - Add (((Number of (type of gold building) units owned by (Picked player))) x (amount of gold per building)) to (Picked player) Current gold)
Custom script: call DestroyForce( udg_temp )

JASS:
Collapse JASS:
function Trig_Gold_Func takes nothing returns nothing

 // addon is the variable for how much gold to be added, replace h001 with building raw code
 // the number "2" is how much gold is added per building
    local integer addon = ( CountLivingPlayerUnitsOfTypeId('h001', GetEnumPlayer()) * 2 )

    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_GOLD_GATHERED, GetPlayerState( GetEnumPlayer(), PLAYER_STATE_GOLD_GATHERED) + addon)
endfunction

function Trig_Gold_Actions takes nothing returns nothing

 // Replace "GetPlayersAllies(Player(0))" with whatever set of players you want to add the gold to
    local force g = GetPlayersAllies(Player(0))
    call ForForce( g, function Trig_Gold_Func )
    call DestroyForce( g )
    
    set g = null
endfunction

//===========================================================================
function InitTrig_Gold takes nothing returns nothing
    
 // the 10.00 is how often you want the periodic check to occur
    set gg_trg_Gold = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Gold, 10.00 )
    call TriggerAddAction( gg_trg_Gold, function Trig_Gold_Actions )
endfunction


You'll forgive me for any simple mistakes...I was working in JSP and can't seem to ever get it to have 0 errors when I compile a snippet of code. Anyways though, you get the jist. Its really not complicated, and is efficient.
03-18-2007, 07:05 PM#7
Dil999
If i had to do it i would use a variable for adding gold.
Unit finishes construction
Set Gold [Player Index of player constructing] equal to Gold [Player index blahblah] + Gold amount

Trigger 2
Every X seconds
Add Gold [Player Index blahblah] to players current gold.
03-19-2007, 08:19 AM#8
NmdSnprEnigma
I jmust think that scmstrak's has a certain simplicity to it, and as long as it works in all scenarios, why bother writing 2 partially redundant triggers? It also give it every x seconds from the end of construction, instead of x clock seconds, which gives a more even gain rate. It doesn't require any player loops. If two triggers accomplish the same thing, take the simpler one.

My only concern is this: I don't know enough about how WC3 handles threads. Does the first instance of this trigger ever stop running or is it constantly waiting for its "Run (this trigger) <checking conditions>" call to finish?
03-19-2007, 02:30 PM#9
WNxCryptic
It will essentially keep at least one thread open for the duration of the map. Because its in GUI without any custom script calls, its going to leak the player groups, OwnerOfTriggeringUnit will leak as well..etc. etc.

With the construction of each additional bank, it opens another thread..so in a map with more than 1 bank for each person its going to produce hundreds of threads by the end of the map.

On a side note, if the TSA function is any shorter than 15 seconds or so, the count will be innacurate (especially if the duration is shorter than 5 seconds).