function SiphonGold_SpellId takes nothing returns integer
return 'XXXX' //Your spell id
endfunction
function SiphonGold_GoldPerSecond takes integer level returns integer
return 10+5*level
endfunction
function SiphonGold_ExtraGoldFinishGold takes integer level returns integer
return 100+50*level
endfunction
function SiphonGold_AttachPoint takes nothing returns string
return "chest"
endfunction
function SiphonGold_TextTag_Caster takes texttag text,unit c, integer gold returns nothing
call SetTextTagVisibility(text,true)
call SetTextTagPosUnit(text,c,GetUnitFlyHeight(c))
call SetTextTagColor(text,255,0,177,0) //text in rgba
call SetTextTagVelocity(text,0,0.022) //Speed
call SetTextTagText(text,I2S(gold)+"!",0.023) //Text and Size
call SetTextTagFadepoint(text,1) //Duration Before Fading
call SetTextTagLifespan(text,2) //Total Duration
call SetTextTagPermanent(text,false)
endfunction
function SiphonGold_TextTag_Target takes texttag text,unit u, integer gold returns nothing
call SetTextTagVisibility(text,true)
call SetTextTagPosUnit(text,u,GetUnitFlyHeight(u))
call SetTextTagColor(text,255,0,177,0) //text in rgba
call SetTextTagVelocity(text,0,0.022) //Speed
call SetTextTagText(text,I2S(gold)+"!",0.023) //Text and Size
call SetTextTagFadepoint(text,1) //Duration Before Fading
call SetTextTagLifespan(text,2) //Total Duration
call SetTextTagPermanent(text,false)
endfunction
function SiphonGold_Main takes nothing returns nothing
local unit c=GetTriggerUnit()
local unit u=GetSpellTargetUnit()
local trigger ex=CreateTrigger()
local trigger fin=CreateTrigger()
local timer t=CreateTimer()
local integer s=GetSpellAbilityId()
local integer l=GetUnitAbilityLevel(c,s)
local integer gold=SiphonGold_GoldPerSecond(l)
call TriggerRegisterUnitEvent(ex,c,EVENT_UNIT_DEATH)
call TriggerRegisterUnitEvent(ex,c,EVENT_UNIT_SPELL_ENDCAST)
call TriggerRegisterUnitEvent(fin,c,EVENT_UNIT_SPELL_FINISH)
loop
call TimerStart(t,1.00,false,null)
loop
exitwhen GetTriggerExecCount(ex)>0 or TimerGetRemaining(t)==0.00
call TriggerSleepAction(0)
endloop
exitwhen GetTriggerExecCount(ex)>0 or GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED)<=0
if gold>GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED) then
set gold= GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED)
endif
call SiphonGold_TextTag_Caster(CreateTextTag(),c,gold)
call SiphonGold_TextTag_Caster(CreateTextTag(),u,gold)
call SetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED,-gold+GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED))
call SetPlayerState(GetOwningPlayer(c),PLAYER_STATE_GOLD_GATHERED,gold+GetPlayerState(GetOwningPlayer(c),PLAYER_STATE_GOLD_GATHERED))
call DestroyEffect(AddSpellEffectTargetById(s,EFFECT_TYPE_TARGET,u,SiphonGold_AttachPoint()))
call DestroyEffect(AddSpellEffectTargetById(s,EFFECT_TYPE_CASTER,c,SiphonGold_AttachPoint()))
endloop
if GetTriggerExecCount(fin)>0 and GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED)>0 then
call TriggerSleepAction(0)
set gold=SiphonGold_ExtraGoldFinishGold(l)
if gold>GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED) then
set gold= GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED)
endif
call SiphonGold_TextTag_Caster(CreateTextTag(),c,gold)
call SiphonGold_TextTag_Caster(CreateTextTag(),u,gold)
call SetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED,-gold+GetPlayerState(GetOwningPlayer(u),PLAYER_STATE_GOLD_GATHERED))
call SetPlayerState(GetOwningPlayer(c),PLAYER_STATE_GOLD_GATHERED,gold+GetPlayerState(GetOwningPlayer(c),PLAYER_STATE_GOLD_GATHERED))
endif
call DestroyTrigger(fin)
call DestroyTrigger(ex)
call DestroyTimer(t)
set fin=null
set ex=null
set c=null
set t=null
set u=null
endfunction
function SiphonGold_Condition takes nothing returns boolean
return GetSpellAbilityId()==SiphonGold_SpellId()
endfunction
function InitTrig_SiphonGold takes nothing returns nothing
local trigger t=CreateTrigger()
local integer i=0
call TriggerAddAction(t,function SiphonGold_Main)
call TriggerAddCondition(t,Condition(function SiphonGold_Main))
loop
exitwhen i>16
call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
set i=i+1
endloop
set t=null
endfunction