GetTriggerUnit-
DogEntrepreneur
- Reaction score
- 129
This is a very simple snippet that allows you to periodicly add resources to a player.
Testmap:
JASS:
/*
TimedResources v1.0
This is a very simple snippet that allows you to periodicly add
resources to a player.
-How to import:
* You first need to get TimerUtils
* Create a new trigger and convert it to custom script.
* Label you trigger to "TimedResources"
* Delete all the text within it and replace it by this text.
-How to use:
* Create a new instance -> TimedResources d = TimedResources.create().
* Set all the struct memeber to a value. -> d.mainPlayer = whichPlayer.
* Use the Start() method to start Resources incomes.
* Use the Stop() method to stop Resources incomes.
*/
library TimedResources requires TimerUtils
struct TimedResources
player mainPlayer
real gainPeriod
integer gainGold
integer gainWood
private timer periodTimer
private static method periodic takes nothing returns nothing
local thistype d = GetTimerData(GetExpiredTimer())
call SetPlayerState(d.mainPlayer, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(d.mainPlayer, PLAYER_STATE_RESOURCE_GOLD) + d.gainGold)
call SetPlayerState(d.mainPlayer, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(d.mainPlayer, PLAYER_STATE_RESOURCE_LUMBER) + d.gainWood)
endmethod
method Start takes nothing returns nothing
local thistype d = this
set d.periodTimer = NewTimer()
call SetTimerData(d.periodTimer, d)
call TimerStart(d.periodTimer, d.gainPeriod, true, function thistype.periodic)
endmethod
method Stop takes nothing returns nothing
call ReleaseTimer(this.periodTimer)
set this.mainPlayer = null
set this.gainPeriod = 0.00
set this.gainGold = 0
set this.gainWood = 0
endmethod
endstruct
endlibrary
Testmap: