// SPECIAL THANKS: Tom_Kazansky for his incredible wisdom concerning the creation of texttags ; )/////// VER 00globals // Set To false if you want to add bounty on your own way. constant boolean AUTO_ADD_BOUNTY =
trueendglobals //! runtextmacro AddUnitValue( "BountyMax", "integer", "0" ) //! runtextmacro AddUnitValue( "BountyMin", "integer", "0" )library BountySystem
initializer InitBountySystem
needs Hash, Utilities, BountyMinAttacherUnit, BountyMaxAttacherUnit
globals private constant real DefaultGainValue = 1.0
// 1 = 100%; 0.5 = 50% private constant real DefaultGiveValue = 1.0
private real array PlayerBountyGive
private real array PlayerBountyGain
private integer Bounty = 0
private unit BountyGiver =
null private player BountyGetter =
null private player BountyGiverOwner =
null private constant trigger BountyTrigger = CreateTrigger
() private trigger array AttachedTrigger
private integer AttachedTriggerNum = -1
private constant trigger TriggerHandler = CreateTrigger
() constant integer PLAYER_BOUNTY_GIVE = -1
constant integer PLAYER_BOUNTY_GAIN = 1
endglobals function GetBountyUnit
takes nothing returns unit return BountyGiver
endfunction function GetTriggerBounty
takes nothing returns integer return Bounty
endfunction function GetBountyPlayer
takes nothing returns player return BountyGetter
endfunction function GetBountyGiver
takes nothing returns player return BountyGiver
endfunction function TriggerRegisterBountyEvent
takes trigger toregister
returns nothing set AttachedTriggerNum = AttachedTriggerNum + 1
set AttachedTrigger
[ AttachedTriggerNum
] = toregister
endfunction function SetPlayerBounty
takes integer playerid,
real give,
real gain
returns nothing set PlayerBountyGive
[ playerid
] = give
set PlayerBountyGain
[ playerid
] = gain
endfunction function GetPlayerBounty
takes integer playerid,
integer bountytype
returns real if bountytype == PLAYER_BOUNTY_GIVE
then return PlayerBountyGive
[ playerid
] elseif bountytype == PLAYER_BOUNTY_GAIN
then return PlayerBountyGain
[ playerid
] endif return 0.0
endfunction private function GetUnitTypeBounty
takes integer unittypeid
returns integer return GetRandomInt
( GetUnitTypeBountyMin
( unittypeid
), GetUnitTypeBountyMax
( unittypeid
) ) endfunction function SetUnitTypeBounty
takes integer unittypeid,
integer min,
integer max
returns nothing call SetUnitTypeBountyMin
( unittypeid, min
) call SetUnitTypeBountyMax
( unittypeid, max
) endfunction private function TriggerHandler_Actions
takes nothing returns nothing local integer loopIndicator = 0
local unit trigUnit = GetTriggerUnit
( ) local integer trigUnitID = GetUnitTypeId
( trigUnit
) local integer bounty = GetUnitTypeBounty
( trigUnitID
) local player bountyPlayer = GetOwningPlayer
( GetKillingUnit
() ) local player bountyGiver = GetOwningPlayer
( trigUnit
) set Bounty = bounty
set BountyGetter = bountyPlayer
set BountyGiver = trigUnit
set BountyGiverOwner = bountyGiver
if IsPlayerEnemy
( BountyGiverOwner, BountyGetter
) then loop exitwhen loopIndicator > AttachedTriggerNum
if TriggerEvaluate
( AttachedTrigger
[ loopIndicator
] ) then call TriggerExecute
( AttachedTrigger
[ loopIndicator
] ) endif set loopIndicator = loopIndicator + 1
endloop endif set trigUnit =
null endfunction private function BountyTrigger_Actions
takes nothing returns nothing local integer bountyAmount = GetTriggerBounty
( ) local unit bountyUnit = GetBountyUnit
( ) local player bountyPlayer = GetBountyPlayer
( ) local player bountyGiver = BountyGiverOwner
local integer bountyPlayerId = GetPlayerId
( bountyPlayer
) local integer bountyGiverId = GetPlayerId
( bountyGiver
) set bountyAmount = R2I
( bountyAmount * PlayerBountyGive
[ bountyGiverId
] * PlayerBountyGain
[ bountyPlayerId
] ) call CreateBountyText
( bountyAmount, bountyUnit, bountyPlayer
) call SetPlayerState
( bountyPlayer, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState
( bountyPlayer, PLAYER_STATE_RESOURCE_GOLD
) + bountyAmount
) call SetPlayerState
( bountyPlayer, PLAYER_STATE_GOLD_GATHERED, GetPlayerState
( bountyPlayer, PLAYER_STATE_GOLD_GATHERED
) + bountyAmount
) set bountyUnit =
null endfunction private function InitBountySystem
takes nothing returns nothing local integer playerIndex = 0
call TriggerRegisterAnyUnitEventBJ
( TriggerHandler, EVENT_PLAYER_UNIT_DEATH
) call TriggerAddAction
( TriggerHandler,
function TriggerHandler_Actions
) loop exitwhen playerIndex > NUMPLAYERS
set PlayerBountyGive
[ playerIndex
] = DefaultGiveValue
set PlayerBountyGain
[ playerIndex
] = DefaultGainValue
set playerIndex = playerIndex + 1
endloop // Please outcomment the following two lines if you do not want to distribute bounty as usually! if AUTO_ADD_BOUNTY
then call TriggerRegisterBountyEvent
( BountyTrigger
) call TriggerAddAction
( BountyTrigger,
function BountyTrigger_Actions
) endif endfunctionendlibrary