HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trigger: Generic Spell Trigger For Items

02-03-2003, 02:42 PM#1
Darky28
Hi Folks...
I created a generic spell casting trigger for items which you might use freely in your maps.

You can change some variables to fit for your items...
The variable "enemy" can have the values 1 or 0. If its 1 the spell is cast on the enemy/neutral unit in range and if its 0 the spell is cast on own units.
The variable "radius" is the size if the spell range around the caster, Increase or decrease the value to affect more or less units.
The variable "spell" contains the command which is cast on the unit.

DemoMap:
http://www.wc3sear.ch/spellcast.zip

Greetings Darky26

Code:
//============================================================================
// Trigger:       Spell Cast
// Script Author: Darky26
// Info:          This Trigger casts a spell on all units around the caster.
//                
//
//                enemy: 0 = Target own units 1 = Target enemy/neutral units
//                spell: change its tho the command you want for example "antimagicshell"
//                radius: the radius of the item.
//============================================================================

function Trig_Spell_Conditions takes nothing returns boolean
    return ( GetUnitTypeId(GetSummonedUnit()) == 'nrdr' )
endfunction

function Trig_Spell_Filter takes nothing returns boolean
    local integer enemy = 0 // 0 = Target own units 1 = Target enemy/neutral units
    if (enemy == 1) then
        return ( GetOwningPlayer(GetFilterUnit()) != GetOwningPlayer(GetSummoningUnit()) )
    else
        return ( GetOwningPlayer(GetFilterUnit()) == GetOwningPlayer(GetSummoningUnit()) ) 
    endif
endfunction

function Trig_Spell_CastSpell takes nothing returns nothing
    local string spell = "antimagicshell" // Change the spell to whatever you want
    call CreateNUnitsAtLocFacingLocBJ( 1, 'nC01' , Player(0), GetUnitLoc(GetEnumUnit()), GetUnitLoc(GetEnumUnit()) )
    call IssueTargetOrderBJ( GetLastCreatedUnit(), spell, GetEnumUnit() )
endfunction

function Trig_Spell_RemoveCaster takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function Trig_Spell_Actions takes nothing returns nothing
    local real radius = 512 // change this value for bigger or smaller range
    call RemoveUnit( GetSummonedUnit() )
    call ForGroup( GetUnitsInRangeOfLocMatching(radius, GetUnitLoc(GetSummoningUnit()), Condition(function Trig_Spell_Filter)), function Trig_Spell_CastSpell )
    call TriggerSleepAction( 0.10 )
    call ForGroup( GetUnitsOfTypeIdAll('nC01'), function Trig_Spell_RemoveCaster)
endfunction

//===========================================================================

function InitTrig_Spell_Cast takes nothing returns nothing
    set gg_trg_Spell_Cast = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Spell_Cast, Player(0), EVENT_PLAYER_UNIT_SUMMON )
    call TriggerAddCondition( gg_trg_Spell_Cast, Condition( function Trig_Spell_Conditions ) )
    call TriggerAddAction( gg_trg_Spell_Cast, function Trig_Spell_Actions )
endfunction