| 05-09-2006, 08:25 PM | #1 |
What is the trigger for a building that does +5 gold per second? My map consists of +5 +10 +25 +50 Gold per second buildings |
| 05-09-2006, 08:29 PM | #2 |
You could use a timer. Events: Time - Every 1.00 sec of the game Conditions: Actions: Unit Group - Pick every building blabla. Player - Add 5 gold to owner of picked unit |
| 05-09-2006, 08:48 PM | #3 | |
Quote:
|
| 05-09-2006, 09:00 PM | #4 |
But, ofc, that will leak. This is what you want, something like this will work great You need a variable called AddGoldUnits as an array, the variable is a Unit Type Trigger: Then, create another trigger, click Edit at the top, click Convert to Custom Text. then paste the following writing below, and just the writing in the box. JASS:function Trig_Add_Gold_Actions takes nothing returns nothing // If your not familair with JASS, dont read below local group array TempGroup local integer loopN = 0 set bj_forLoopAIndex = 1 set bj_forLoopAIndexEnd = 12 loop exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd set TempGroup[1] = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), udg_AddGoldUnits[1]) set TempGroup[2] = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), udg_AddGoldUnits[2]) set TempGroup[3] = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), udg_AddGoldUnits[3]) set TempGroup[4] = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetForLoopIndexA()), udg_AddGoldUnits[4]) call AdjustPlayerStateBJ( CountUnitsInGroup(TempGroup[1])*5, ConvertedPlayer(GetForLoopIndexA()), PLAYER_STATE_RESOURCE_GOLD ) call AdjustPlayerStateBJ( CountUnitsInGroup(TempGroup[2])*10, ConvertedPlayer(GetForLoopIndexA()), PLAYER_STATE_RESOURCE_GOLD ) call AdjustPlayerStateBJ( CountUnitsInGroup(TempGroup[3])*25, ConvertedPlayer(GetForLoopIndexA()), PLAYER_STATE_RESOURCE_GOLD ) call AdjustPlayerStateBJ( CountUnitsInGroup(TempGroup[4])*50, ConvertedPlayer(GetForLoopIndexA()), PLAYER_STATE_RESOURCE_GOLD ) set bj_forLoopAIndex = bj_forLoopAIndex + 1 endloop loop exitwhen loopN == 4 set TempGroup[loopN] = null set loopN = loopN + 1 endloop endfunction //=========================================================================== function InitTrig_Add_Gold takes nothing returns nothing set gg_trg_Add_Gold = CreateTrigger( ) call TriggerRegisterTimerEventPeriodic( gg_trg_Add_Gold, 1.00 ) call TriggerAddAction( gg_trg_Add_Gold, function Trig_Add_Gold_Actions ) endfunction The second trigger MUST be called 'Add Gold' unfortunatly |
| 05-09-2006, 09:06 PM | #5 |
May I point out how completely leaky that trigger is...? Also no need for the local array for unit types, since the global works just fine. |
| 05-09-2006, 09:24 PM | #6 |
You mixed up array indexing. 1,2,3,4 first then 0,1,2,3 later. I recommend Thunder's solution as it is far simpler. Packing the types into unnamed arrays, while a step in the right direction, is not helpful with out some more abstraction. |
| 05-09-2006, 09:29 PM | #7 |
Don't type your posts in all color. Only use color if you want to highlight something important. |
| 05-10-2006, 08:28 AM | #8 |
Yea, sorry guys, i had around 1 minute to do all this, i was in such a rush, i edited the code loads of times, but dident update much of it on wc3c, just on trigger editor, sorry i shouldent have posted without a proper answer |
| 05-10-2006, 08:38 AM | #9 |
Don't forget to check if the buildings are actually built; I see maps *all the time* where buildings take effect as soon as you start construction. |
| 05-10-2006, 03:58 PM | #10 |
Ok, sorry for the bad messup, iv redone it completly, it should work like a charm now. For this, you need: 2 Triggers, 1 of them call what you want, the other MUST be called "Add Gold to Player" , case sensitive. 1 Varaible array[size of 4] which is a Unit Type. In your trigger which is not named Add Gold to Player, add something like this: Trigger: Once that is done, in your other trigger that is named Add Gold to Player, click edit at the top and then Convert to Custom text, and paste this code in: JASS:function Trig_Add_Gold_to_Player_Actions takes nothing returns nothing local group array goldUnits local integer loopN = 1 local integer loopTypesN = 1 loop exitwhen loopN == 12 loop exitwhen loopTypesN == 4 set goldUnits[loopTypesN] = GetUnitsOfPlayerAndTypeId(ConvertedPlayer(loopN), udg_GoldUnitTypes[loopTypesN]) set loopTypesN = loopTypesN + 1 endloop set loopN = loopN + 1 call AdjustPlayerStateBJ((CountUnitsInGroup(goldUnits[1])*5)+(CountUnitsInGroup(goldUnits[2])*10)+(CountUnitsInGroup(goldUnits[3])*25)+(CountUnitsInGroup(goldUnits[4])*50), ConvertedPlayer(loopN), PLAYER_STATE_RESOURCE_GOLD) endloop set loopN = 1 loop exitwhen loopN == 4 call DestroyGroup(goldUnits[loopN]) set goldUnits[loopN] = null set loopN = loopN + 1 endloop set loopN = 0 set loopTypesN = 0 endfunction //=========================================================================== function InitTrig_Add_Gold_to_Player takes nothing returns nothing set gg_trg_Add_Gold_to_Player = CreateTrigger() call TriggerRegisterTimerEventPeriodic( gg_trg_Add_Gold_to_Player, 1.00) call TriggerAddAction(gg_trg_Add_Gold_to_Player, function Trig_Add_Gold_to_Player_Actions) endfunction Sorry for the mix up before EDIT: @ Vuen... Unfortunatly, i dident put this in, that will require more triggers with something like, 'A unit finishes construction', then add it to the group. |
