scope Refund initializer init
native GetUnitGoldCost takes integer id returns integer
native GetUnitWoodCost takes integer id returns integer
globals
private constant real REFUND_RETURN_RATE_GOLD = .50 // Set the percentage return rate
private constant real REFUND_RETURN_RATE_WOOD = .50 // Set the percentage return rate
private constant real HITPOINTS_REQUIRED = 100 // Set the required life percentage of the building you are refunding
private constant string STRING_MSG = "|cff808080This building is hurt and may not be refunded." // Set the failure message for the player
private constant boolean WANT_HP_CHECK = true // If you want to check for hitpoints, set this to true. If you do not want to check hitpoints, set it to false.
private constant string SFX_MODEL = "UI\\Feedback\\GoldCredit\\GoldCredit.mdl" // Special effect model
private constant integer REFUND_ABIL_ID = 'A000' // Refund ability raw code
endglobals
private function main takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId(u)
local texttag tg
local texttag tl
local integer goldAmount
local integer woodAmount
if (GetSpellAbilityId() != REFUND_ABIL_ID) then
set u = null
return
endif
if GetUnitLifePercent(u) == HITPOINTS_REQUIRED or WANT_HP_CHECK == false then
set tg = CreateTextTag()
set tl = CreateTextTag()
set goldAmount = R2I(GetUnitGoldCost(id) * REFUND_RETURN_RATE_GOLD)
set woodAmount = R2I(GetUnitWoodCost(id) * REFUND_RETURN_RATE_WOOD)
call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, (GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + goldAmount))
call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_LUMBER, (GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_LUMBER) + woodAmount))
call KillUnit(u)
call DestroyEffect(AddSpecialEffectTarget(SFX_MODEL, u, "overhead"))
// Gold Text Tag
call SetTextTagText(tg, "(+" + I2S(goldAmount) + ")", 0.020)
call SetTextTagPos(tg, GetUnitX(u), GetUnitY(u), 0.00)
call SetTextTagColor(tg, 255, 220, 0, 255)
call SetTextTagVelocity(tg, 0, .02)
call SetTextTagVisibility(tg, true)
call SetTextTagFadepoint(tg, 0.10)
call SetTextTagLifespan(tg, 1.5)
call SetTextTagPermanent(tg, false)
// Lumber Text Tag
call SetTextTagText(tl, "(+" + I2S(woodAmount)+ ")", 0.020)
call SetTextTagPos(tl, GetUnitX(u), GetUnitY(u) - 50, 0.00)
call SetTextTagColor(tl, 0, 255, 0, 0)
call SetTextTagVelocity(tl, 0, - 0.02)
call SetTextTagVisibility(tl, true)
call SetTextTagFadepoint(tl, 0.10)
call SetTextTagLifespan(tl, 1.5)
call SetTextTagPermanent(tl, false)
else
call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, STRING_MSG)
endif
set tg = null
set tl = null
set u = null
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function main))
set t = null
endfunction
endscope