Moderator
M
Moderator
13 Dec 2011
Bribe: Approved.
Bribe: Approved.
/*
===Luck Aura v1.3
===By Mckill2009
INSTALLATION:
- Copy the custom dummy unit/buff/abilities to your map
- You MUST input or change the correct rawID's (see below)
- To view rawID, press CTRL+D in the object editor
- Copy ALL the required libraries and the LuckAura trigger to your map (SimError is optional)
- Change the CONFIGURABLES and AOE if needed
- DONE!
REQUIRED LIBRARIES:
- RegisterPlayerUnitEvent by Magtheridon96
- Table by Bribe
- SpellEffectEvent by Bribe
- *SimError (Optional)
FULL DESCRIPTION:
Once activated, it brings good luck to the caster and his allies, giving a chance to drop random items from kills depending on the level of the spell.
|cffffcc00Level 1|r - 15% of Level 1 items,
|cffffcc00Level 2|r - 20% of Level 1-3 items.
|cffffcc00Level 3|r - 25% of Level 1-4 items.
|cffffcc00Level 4|r - 30% of Level 1-5 items.
|cffffcc00Spell lasts 30 seconds.|r
*/
scope LuckAura
globals
private Table lu //NEVER TOUCH THIS!
private constant itemtype ITEMID = ITEM_TYPE_ANY
private constant real AOE = 600 //Buff Effect or range, make sure that this matches the AOE of DUMMY_SPELL_ID
private constant integer SPELL_ID = 'A001' //Hero ability rawID
private constant integer DUMMY_SPELL_ID = 'A000' //Buff Aura rawID
private constant integer DUMMY_ID = 'h000' //Dummy Unit rawID
private constant integer BUFF = 'B000' //Buff Aura rawID
endglobals
//===CONFIGURABLES:
private function GetDuration takes integer i returns real
return 30.
endfunction
private function GetChance takes integer i returns integer
return 10 + i * 5
endfunction
//===END OF CONFIGURABLES
private function EnemyDies takes unit u, unit k returns nothing
local unit first
local integer level
call GroupEnumUnitsInRange(bj_lastCreatedGroup,GetUnitX(k),GetUnitY(k),AOE,null)
loop
set first = FirstOfGroup(bj_lastCreatedGroup)
exitwhen first==null
if UnitAlive(first) and lu.has(GetHandleId(first)) then
set level = lu[GetHandleId(first)]
if GetRandomInt(1,100) <= GetChance(level) and not IsUnitType(u, UNIT_TYPE_STRUCTURE) then
if level==1 then
call CreateItem(ChooseRandomItemEx(ITEMID, 1), GetUnitX(u), GetUnitY(u))
else
call CreateItem(ChooseRandomItemEx(ITEMID, GetRandomInt(1,level+1)), GetUnitX(u), GetUnitY(u))
endif
endif
endif
call GroupRemoveUnit(bj_lastCreatedGroup,first)
endloop
endfunction
private function EnemyDiesCond takes nothing returns nothing
if (GetUnitAbilityLevel(GetKillingUnit(), BUFF) > 0) and IsUnitEnemy(GetKillingUnit(),GetTriggerPlayer()) then
call EnemyDies(GetTriggerUnit(), GetKillingUnit())
endif
endfunction
private struct Luck
unit caster
unit dummy
real duration
private static timer tim
private static integer index = 0
private static integer array indexAR
private static thistype DATA
private static method looper takes nothing returns nothing
local thistype this
local integer i = 0
loop
set i = i+1
set this = indexAR[i]
if .duration > 0 and UnitAlive(.caster) then
set .duration = .duration - 0.5
call SetUnitX(.dummy, GetUnitX(.caster))
call SetUnitY(.dummy, GetUnitY(.caster))
else
call KillUnit(.dummy)
call lu.remove(GetHandleId(.caster))
set .caster = null
set .dummy = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set i = i-1
set index = index - 1
if index==0 then
call PauseTimer(tim)
call DestroyTimer(tim)
endif
endif
exitwhen i==index
endloop
endmethod
private static method cast takes nothing returns nothing
local thistype this
local unit u = GetTriggerUnit()
local timer t
local integer timerID
local integer casterID = GetHandleId(u)
local integer level
local player p = GetTriggerPlayer()
if not lu.has(casterID) then
set this = allocate()
set level = GetUnitAbilityLevel(u, SPELL_ID)
set lu[casterID] = level
set .caster = GetTriggerUnit()
set .dummy = CreateUnit(p, DUMMY_ID, GetUnitX(u), GetUnitY(u), 0)
set .duration = GetDuration(level)
if index==0 then
set tim = CreateTimer()
call TimerStart(tim, 0.5, true, function thistype.looper)
endif
set index = index + 1
set indexAR[index] = this
call UnitAddAbility(dummy, DUMMY_SPELL_ID)
call SetUnitAbilityLevel(dummy, DUMMY_SPELL_ID, level)
else
call IssueImmediateOrder(u, "stop")
static if LIBRARY_SimError then
call SimError(p, "Can't be used yet!")
endif
endif
set u = null
set p = null
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function EnemyDiesCond)
set lu = Table.create()
endmethod
endstruct
endscope