- Joined
- Aug 3, 2004
- Messages
- 2,891
I need this spell to work on non-hero units.
JASS:
//******************************************************************************
//* *
//* Graverobber *
//* v1.02 *
//* *
//* By: Rising_Dusk *
//* *
//******************************************************************************
//**************************************
//* LIBRARY REQUIREMENTS:
//* - GroupUtils
//*
scope Graverobber initializer Init
globals
//*************************************************************
//* Configuration Constants
//* Raw codes
private constant integer SPELL_ID = 'A02W'
private constant integer INVIS_ID = 'Apiv'
//* System related
private constant real TIMER_INTERVAL = 0.05
//*************************************************************
//* System Variables
private timer CheckTimer = CreateTimer()
private group CasterGroup = CreateGroup()
private boolexpr Checker = null
private trigger Trg = CreateTrigger()
endglobals
//*****************************************************************
//* Configuration Functions
private constant function AreaOfEffect takes integer lvl returns real
//* Spell Area of Effect Radius
return 450.
endfunction
private constant function Corpses takes integer lvl returns integer
//* Number of corpses necessary
return 3-lvl
endfunction
private function Check takes nothing returns boolean
//* The boolexpr for finding a corpse
return GetUnitTypeId(GetFilterUnit()) != 0 and IsUnitType(GetFilterUnit(), UNIT_TYPE_GROUND) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_SUMMONED) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and GetWidgetLife(GetFilterUnit()) <= 0.405
endfunction
//*****************************************************************
private function Conditions takes nothing returns boolean
return GetLearnedSkill() == SPELL_ID
endfunction
private function Enumeration takes nothing returns nothing
local unit e = GetEnumUnit()
local unit s = null
local integer lvl = GetUnitAbilityLevel(e, SPELL_ID)
local real x = GetUnitX(e)
local real y = GetUnitY(e)
//* Loop through all corpses to count them
if GetWidgetLife(e) > 0.405 then
set bj_groupCountUnits = 0
call GroupEnumUnitsInRange(ENUM_GROUP, x, y, AreaOfEffect(lvl), Checker)
call ForGroup(ENUM_GROUP, function CountUnitsInGroupEnum)
if bj_groupCountUnits >= Corpses(lvl) and GetUnitAbilityLevel(e, INVIS_ID) <= 0 then
call UnitAddAbility(e, INVIS_ID)
elseif bj_groupCountUnits < Corpses(lvl) and GetUnitAbilityLevel(e, INVIS_ID) > 0 then
call UnitRemoveAbility(e, INVIS_ID)
endif
endif
call GroupClear(ENUM_GROUP)
set e = null
set s = null
endfunction
private function Callback takes nothing returns nothing
call ForGroup(CasterGroup, function Enumeration)
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if FirstOfGroup(CasterGroup) == null then
call TimerStart(CheckTimer, TIMER_INTERVAL, true, function Callback)
endif
call GroupAddUnit(CasterGroup, u)
set u = null
endfunction
private function Init takes nothing returns nothing
call TriggerAddAction(Trg, function Actions)
call TriggerAddCondition(Trg, Condition(function Conditions))
call TriggerRegisterAnyUnitEventBJ(Trg, EVENT_PLAYER_HERO_SKILL)
set Checker = Condition(function Check)
endfunction
endscope