//*************************************************************************
//*
//* Globals required
//*
//*************************************************************************
//* udg_BountyHash Hashtable for data storage
//* All the rest variables are declared by systems used
//*************************************************************************
//*
//* Code itself
//*
//*************************************************************************
function GiveBounty takes nothing returns boolean
local unit u = GetTriggerUnit()
local unit l
local integer id
local integer i
local integer n = 0
local real d
if IsUnitInGroup(u, udg_Creeps) then
set id = GetHandleId(u)
set i = LoadInteger(udg_BountyHash, id, 0)
if i > 0 then
loop
exitwhen 0 == i
loop
exitwhen udg_BountyUnitType[n] == GetUnitTypeId(u) or n > udg_BountyIndexSize
set n = n + 1
endloop
set l = LoadUnitHandle(udg_BountyHash, id, i)
set d = LoadReal(udg_BountyHash, id, -i) / udg_BountyDamageTaken[GetUnitUserData(u)] * udg_BountyBase[n]
set d = GetRandomReal(udg_BountyRandomMin * d, udg_BountyRandomMax * d)
if l == GetKillingUnit() then
set d = d * udg_BountyOnKillingBlow
endif
call SetPlayerState(GetOwningPlayer(l), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(l), PLAYER_STATE_RESOURCE_GOLD) + R2I(d))
//* Create floating text part
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, "+" + I2S(R2I(d)), 0.024)
call SetTextTagPos(bj_lastCreatedTextTag, GetUnitX(l)-16.0, GetUnitY(l), 0.0)
call SetTextTagColor(bj_lastCreatedTextTag, 255, 220, 0, 255)
call SetTextTagVelocity(bj_lastCreatedTextTag, 0., 0.03)
call SetTextTagPermanent(bj_lastCreatedTextTag, false)
call SetTextTagVisibility(bj_lastCreatedTextTag, true)
call SetTextTagLifespan(bj_lastCreatedTextTag, 3.0)
call SetTextTagFadepoint(bj_lastCreatedTextTag, 2.0)
set l = null
set i = i - 1
endloop
endif
call GroupRemoveUnit(udg_Creeps, u)
call FlushChildHashtable(udg_BountyHash, id)
endif
set u = null
return false
endfunction
function CountBounty takes nothing returns boolean
local integer id = GetHandleId(udg_DamageEventTarget)
local integer n = GetUnitUserData(udg_DamageEventTarget)
local integer i
if udg_DamageEventAmount > 0.00 and IsUnitInGroup(udg_DamageEventTarget, udg_Creeps) then
set udg_BountyDamageTaken[n] = udg_BountyDamageTaken[n] + udg_DamageEventAmount
set i = LoadInteger(udg_BountyHash, id, 0)
set n = i + 1
loop
exitwhen 0 == i
if LoadUnitHandle(udg_BountyHash, id, i) == udg_DamageEventSource then
call SaveReal(udg_BountyHash, id, -i, LoadReal(udg_BountyHash, id, -i) + udg_DamageEventAmount)
return false
endif
set i = i - 1
endloop
call SaveUnitHandle(udg_BountyHash, id, n, udg_DamageEventSource)
call SaveReal(udg_BountyHash, id, -n, udg_DamageEventAmount)
call SaveInteger(udg_BountyHash, id, 0, n)
endif
return false
endfunction
function BountyAddUnit takes nothing returns boolean
if not IsUnitType(udg_UDexUnits[udg_UDex], UNIT_TYPE_HERO) then
call GroupAddUnit(udg_Creeps, udg_UDexUnits[udg_UDex])
call SaveInteger(udg_BountyHash, GetHandleId(udg_UDexUnits[udg_UDex]), 0, 0)
set udg_BountyDamageTaken[udg_UDex] = 0.00
endif
return false
endfunction
//***************************************************************************
function InitTrig_CallBounty takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_DamageEvent", EQUAL, 1.00)
call TriggerAddCondition(t, Filter(function CountBounty))
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t, Filter(function GiveBounty))
set t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, 1.00)
call TriggerAddCondition(t, Filter(function BountyAddUnit))
set t = null
endfunction