JASS:
//check nonstructure, alive, and enemy for ug
function EnemyCheck takes nothing returns boolean
if ( IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)) then
return false
endif
if (not ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())))) then
return false
endif
if ( not (IsUnitAliveBJ(GetFilterUnit()))) then
return false
endif
return true
endfunction
//actions
function TriggerAct takes nothing returns nothing
local unit c
local unit ta
local location l1
local location l2
local player p
local unit t2
local unit t3
local integer n
local unit b1
local unit b2
local unit b3
local unit b4
local unit b5
local unit b6
local unit b7
local group g
local location l3
//declared variables
if (not(GetSpellAbilityID() == 'A000')) then
return
endif
set c = GetSpellAbilityUnit()
set ta = GetSpellTargetUnit()
set p = GetOwningPlayer(GetTriggerUnit())
set l1 = GetUnitLoc(c)
set l2 = GetUnitLoc(ta)
set n = GetUnitAbilityLevelSwapped('A000', c)
set g = GetUnitsInRangeOfLocMatching(250.00, l2, Condition(function EnemyCheck))
set t2 = GroupPickRandomUnit(g)
set t3 = GroupPickRandomUnit(g)
call DestroyGroup(g)
set g = null
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
//main variables set
//following creates dummy units to cast individual missiles
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b1 = GetLastCreatedUnit()
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b2 = GetLastCreatedUnit()
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b3 = GetLastCreatedUnit()
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b4 = GetLastCreatedUnit()
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b5 = GetLastCreatedUnit()
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b6 = GetLastCreatedUnit()
set l3 = PolarProjectionBJ(l1, 75.00, ( GetUnitFacing(c) + GetRandomReal(-45.00, 45.00) ))
call CreateNUnitsAtLocFacingLocBJ( 1, 'h000', p, l3, l2 )
set b7 = GetLastCreatedUnit()
call RemoveLocation(l3)
set l3 = null
//following issues first 3 to cast
call IssueTargetOrderBJ( b1, "thunderbolt", ta )
call TriggerSleepAction( 0.10 )
call IssueTargetOrderBJ( b2, "thunderbolt", t2 )
call TriggerSleepAction( 0.10 )
call IssueTargetOrderBJ( b3, "thunderbolt", t3 )
call TriggerSleepAction( 0.10 )
//issues additional 2 to cast if spell is level 2
if (n>=2) then
call IssueTargetOrderBJ( b4, "thunderbolt", ta )
call TriggerSleepAction( 0.10 )
call IssueTargetOrderBJ( b5, "thunderbolt", t2 )
call TriggerSleepAction( 0.10 )
endif
//orders last 2 to cast if spell is level 3
if (n==3) then
call IssueTargetOrderBJ( b6, "thunderbolt", ta )
call TriggerSleepAction( 0.10 )
call IssueTargetOrderBJ( b7, "thunderbolt", t3 )
endif
//wait to allow all orders to complete
call TriggerSleepAction( 0.75 )
//removes dummies from game
call RemoveUnit( b1 )
call RemoveUnit( b2 )
call RemoveUnit( b3 )
call RemoveUnit( b4 )
call RemoveUnit( b5 )
call RemoveUnit( b6 )
call RemoveUnit( b7 )
//null and leakproofing
set b1 = null
set b2 = null
set b3 = null
set b4 = null
set b5 = null
set b6 = null
set b7 = null
set c = null
set ta = null
call RemoveLocation(l1)
set l1 = null
call RemoveLocation(l2)
set l2 = null
set t2 = null
set t3 = null
endfunction
//condition
function Con takes nothing returns boolean
return ( GetSpellAbilityId() == 'A000' )
endfunction
//initialize trigger and create local instance
function InitTrig_MagicMissile takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Con ) )
call TriggerAddAction( t, function TriggerAct )
set t = null
endfunction
That's the code for my magic missile spell, works exactly as planned in game (3 missiles if level 1, 5 if 2, 7 if 3, selects targets semi-randomly.), just wondering if someone with more experience with jass can give me a couple pointers on streamlining it, and look it over for leaks?
Last edited: