- Joined
- Oct 15, 2008
- Messages
- 17
Hi, after reading through few tutorials i've tried making a spell which should pick units in an AOE and make them move on the spot randomly for 3 seconds but the code is not working.
I have timerutils.
here is the code:
I have timerutils.
here is the code:
JASS:
scope DrunkenParty initializer Init
//===========================================================================
//=============================SETUP START===================================
//===========================================================================
globals
private constant integer SPELL_ID = 'A02G' //the rawcode of the spell
private constant real INTERVAL = 0.03
endglobals
private function Duration takes integer level returns real
return 3.
endfunction
private function Range takes integer level returns real
return 200.
endfunction
private function Targets takes unit target returns boolean
//the units the spell will affect
return (IsUnitType(target, UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) == false)
endfunction
//===========================================================================
//=============================SETUP END=====================================
//===========================================================================
globals
private group all
private group copy
private boolexpr b
endglobals
//===========================================================================
//Function made by Blade.dk; Search for [url=http://www.wc3campaigns.com]wc3campaigns.com[/url] for more info
private function CopyGroup takes group g returns group
set bj_groupAddGroupDest = CreateGroup()
call ForGroup(g, function GroupAddGroupEnum)
return bj_groupAddGroupDest
endfunction
//===========================================================================
private function Pick takes nothing returns boolean
return Targets(GetFilterUnit())
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL_ID
endfunction
private struct Data
unit caster
unit target
real spellX
real spellY
location effectLoc
real duration
real range
integer level
endstruct
private function Loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local Data data = Data(GetTimerData(t))
call UnitDamageTarget(data.caster, data.caster, 15, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
call GroupEnumUnitsInRange(all, data.spellX, data.spellY, data.range, b)
set copy = CopyGroup(all)
set data.target = FirstOfGroup(copy)
loop
exitwhen(data.target == null)
set data.target = FirstOfGroup(copy)
call GroupRemoveUnit(copy, data.target)
if IsUnitEnemy(data.target, GetOwningPlayer(data.caster))==true then
set data.effectLoc = GetUnitLoc(data.target)
call SetUnitPositionLoc(data.target, PolarProjectionBJ(data.effectLoc, 4.00, GetRandomDirectionDeg()))
endif
endloop
set data.duration = data.duration - INTERVAL
if data.duration <= 0. then
call ReleaseTimer(t)
call data.destroy()
endif
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local location spellLoc = GetSpellTargetLoc()
local location effectLoc
local real spellX = GetLocationX(spellLoc)
local real spellY = GetLocationY(spellLoc)
local unit caster = GetTriggerUnit()
local unit target
local integer level = GetUnitAbilityLevel(caster, SPELL_ID)
local timer t = NewTimer()
local Data data = Data.create()
set data.caster = caster
set data.target = target
set data.spellX = spellX
set data.spellY = spellY
set data.effectLoc = effectLoc
set data.duration = Duration(level)
set data.range = Range(level)
set data.level = level
call SetTimerData(t, integer(data))
call TimerStart(t, INTERVAL, true, function Loop)
call RemoveLocation(spellLoc)
set effectLoc = null
set spellLoc = null
set target = null
set caster = null
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger DrunkenPartyTrg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(DrunkenPartyTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(DrunkenPartyTrg, Condition( function Conditions ) )
call TriggerAddAction(DrunkenPartyTrg, function Actions )
//setting globals
set all = CreateGroup()
set copy = CreateGroup()
set b = Condition(function Pick)
endfunction
endscope