Name | Type | is_array | initial_value |
//------- Readme! -------
//
//How to install?
//
//1. Copy Possession and Uncontrol abilities to your map
//2. Copy this trigger and paste it in your map
//3. Create 2 variables and name them ( AbilityPossession and AbilityUncontrol )
//4. Set them to be your abilitys in your map at map init or where you create vars
// see example in this map
//5. Enjoy!!!
//
//Note: For thous who are skilled whit jass just edit rawcodes
// you don't need vars
//Possession rawcode
constant function Pos_RawCode takes nothing returns integer
return udg_AbilityPossession
endfunction
//Uncontrole rawcode
constant function Unc_RawCode takes nothing returns integer
return udg_AbilityUncontrol
endfunction
//Unit & Integer Conversions
constant function U2I takes unit u returns integer
return u
return 0
endfunction
constant function I2U takes integer i returns unit
return i
return null
endfunction
//Main condition ( in unit )
function Trig_Possession_Condition takes nothing returns boolean
return GetSpellAbilityId() == Pos_RawCode()
endfunction
//Main condition ( out unit )
function Trig_Leave_Condition takes nothing returns boolean
return GetSpellAbilityId() == Unc_RawCode()
endfunction
//Main condition ( unit death )
function Trig_PosDeath_Condition takes nothing returns boolean
return GetUnitUserData( GetTriggerUnit() ) != 0
endfunction
//Main action ( in unit )
function Trig_Possession_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit u2 = GetSpellTargetUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real x2 = GetUnitX(u2)
local real y2 = GetUnitY(u2)
local player p = GetOwningPlayer(u)
local effect e = null
call TriggerSleepAction( bj_WAIT_FOR_COND_MIN_INTERVAL )
if ( GetUnitUserData(u2) != 0 ) then
call DisplayTextToPlayer( p, 0., 0., "|cffffcc00Unit is already controled|r" )
set u = null
set u2 = null
set p = null
return
endif
call PauseUnit( u2, true )
call SetUnitUserData( u2, U2I(u) )
call SetUnitUserData( u, GetPlayerId(GetOwningPlayer(u2)) )
call SetUnitFacingTimed( u2, bj_RADTODEG * Atan2(y-y2, x-x2), .25 )
if ( IsUnitType( u, UNIT_TYPE_DEAD ) or IsUnitType( u2, UNIT_TYPE_DEAD ) ) then
call SetUnitUserData( u2, 0 )
call SetUnitUserData( u, 0 )
call PauseUnit( u, false )
call PauseUnit( u2, false )
set u = null
set u2 = null
set p = null
return
endif
call PauseUnit( u, true )
call ShowUnit( u, false )
call TriggerSleepAction( SquareRoot( (x2-x)*(x2-x) + (y2-y)*(y2-y) ) / 1200. )
call PauseUnit( u2, false )
call SetUnitOwner( u2, p, true )
call UnitAddAbility( u2, Unc_RawCode() )
if ( GetLocalPlayer() == p ) then
call ClearSelection()
call SelectUnit( u2, true )
endif
set e = AddSpecialEffectTarget( "Abilities\\Spells\\Undead\\Possession\\PossessionTarget.mdl", u2, "overhead" )
call TriggerSleepAction( 1.75 )
call DestroyEffect( e )
set u = null
set u2 = null
set p = null
set e = null
endfunction
//Main action ( out unit )
function Trig_Uncontrol_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit u2 = I2U( GetUnitUserData(u) )
local effect e = null
call SetUnitOwner( u, Player(GetUnitUserData(u2)), true )
call TriggerSleepAction( bj_WAIT_FOR_COND_MIN_INTERVAL )
call ShowUnit( u2, true )
call PauseUnit( u2, false )
call SetUnitPosition( u2, GetUnitX(u), GetUnitY(u) )
call SetUnitUserData( u, 0 )
call SetUnitUserData( u2, 0 )
set e = AddSpecialEffectTarget( "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl", u2, "overhead" )
call TriggerSleepAction( 1.75 )
call DestroyEffect( e )
set u = null
set u2 = null
set e = null
endfunction
//Main action ( unit death )
function Trig_PosDeath_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit u2 = I2U( GetUnitUserData(u) )
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local effect e = null
call TriggerSleepAction( bj_WAIT_FOR_COND_MIN_INTERVAL )
call ShowUnit( u2, true )
call PauseUnit( u2, false )
call SetUnitPosition( u2, x, y )
call SetUnitUserData( u, 0 )
call SetUnitUserData( u2, 0 )
set e = AddSpecialEffectTarget( "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl", u2, "overhead" )
call TriggerSleepAction( 1.75 )
call DestroyEffect( e )
set u = null
set u2 = null
set e = null
endfunction
//===========================================================================
function InitTrig_Possession takes nothing returns nothing
//Init triggers
local integer i = 0
local trigger t = null
local trigger td = null
set gg_trg_Possession = CreateTrigger( )
set t = CreateTrigger()
set td = CreateTrigger()
loop
exitwhen ( i >= bj_MAX_PLAYERS )
call TriggerRegisterPlayerUnitEvent( gg_trg_Possession, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
call TriggerRegisterPlayerUnitEvent( t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
call TriggerRegisterPlayerUnitEvent( td, Player(i), EVENT_PLAYER_UNIT_DEATH, null )
set i = i + 1
endloop
call TriggerAddCondition( gg_trg_Possession, Condition( function Trig_Possession_Condition ) )
call TriggerAddCondition( t, Condition( function Trig_Leave_Condition ) )
call TriggerAddCondition( td, Condition( function Trig_PosDeath_Condition ) )
call TriggerAddAction( gg_trg_Possession, function Trig_Possession_Actions )
call TriggerAddAction( t, function Trig_Uncontrol_Actions )
call TriggerAddAction( td, function Trig_PosDeath_Actions )
set gg_trg_Possession = null
set t = null
set td = null
endfunction