// Warp Jump
//
// By Ross Dubery
//
// Teleports the Warper a long distance, allowing him to move rapidly about the map.
// Whilst warping the Warper is vulnerable to attacks.
// Warp time depends on distance travelled.
// Deals damage on arrival in an area based on distance travelled.
//
// There are two things that require changing
// 1 - The ability code, highlighted below (A001)
// 2 - The ability code variable (A001)
//
// Checks for ability, change 'A001' to your spell ID
//
function warp_jump_conditions takes nothing returns boolean
return ( GetSpellAbilityId() == 'A001' )
endfunction
//
// Main Ability
//
function warp_jump_actions takes nothing returns nothing
//
//Initialise
//
//Local Variables
local unit LastUnit
local unit NewUnit
local real Distance
local real Scale
local real Area
local real Damage
local real Phase
local real SleepLen
local real Index
local real IndexInc
local real TransTicks
local boolean FixedDamage
local boolean FixedArea
local boolean FixedPhase
local boolean Transparency
local integer Ability
local integer LastTrans
local integer NewTrans
local integer MinTrans
local integer TickAmount
local integer NumTicks
local effect StompEffect
local effect LastEffect
local effect NewEffect
local location TargetPos
local location UnitPos
//Define the scale of distance
set Scale = 800.0 // Recomended scale
//Choose whether damage, phase time and area are fixed or not
set FixedDamage = false // Scale damage
set FixedArea = false // Scale area
set FixedPhase = false // Scale phase
//Choose if you want the unit to fade in and out or not
set Transparency = true // Scale transparency
//If you said true for any of the above, modify these values
set Damage = 100.00 // The damage dealt on arrival || If damage is negative it will heal units
set Area = 200.00 // The area the damage is dealt in
set Phase = 1.00 // Phase is not decreased at all
set MinTrans = 55 // The most transparent a unit can go
// If phase is > 1.00 it will decrease phase time
// If phase is < 1.00 it will increase phase time
// The lowest phase can go is 0.01
// 0 < MinTrans < 255
//Define the ability code, replace 'A001' with your abiltiy code
set Ability = 'A001' // Ability code
//Leave these alone
set LastUnit = GetSpellAbilityUnit()
set UnitPos = GetUnitLoc(LastUnit)
set TargetPos = GetSpellTargetLoc()
set Distance = (DistanceBetweenPoints(TargetPos, UnitPos)/Scale)
set IndexInc = 0.05
//If damage, phase time and area are not fixed use the following formulae
if ( not FixedDamage) then
set Damage = ( 10 * Distance * I2R(GetUnitAbilityLevel(LastUnit,Ability)) )
endif
if (not FixedArea) then
set Area = ( I2R(GetUnitAbilityLevel(LastUnit,Ability)) * 100.00 )
endif
if (not FixedPhase) then
set Phase = GetUnitAbilityLevel(LastUnit,Ability)
endif
//Ensure phase and area are greater then 0
// and TransTicks is greater then 6 and less then 120
if (Phase < 0.01) then
set Phase = 0.01
endif
if (Area < 0.01) then
set Area = 0.01
endif
if (MinTrans < 0) then
set MinTrans = 0
else
if (MinTrans > 255) then
set MinTrans = 255
endif
endif
//Calculate Sleep Length and Tick Amount
if (Transparency) then
set SleepLen = 0.27
set TransTicks = SleepLen*(Distance/Phase)
//Calculate Sleep Length and Tick Amount
set TickAmount = (R2I((255-MinTrans)/(TransTicks/IndexInc)))
else
set SleepLen = (Distance/Phase)
if(SleepLen < 0.27) then
set SleepLen = 0.27
endif
endif
//Preload resources
call Preload("Abilities\\Spells\\Orc\\Voodoo\\VoodooAuraTarget.mdl")
call Preload("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl")
//
// Body of Ability
//
// Damage the target location with magical damage
call UnitDamagePoint( LastUnit, 0, Area, GetLocationX(TargetPos), GetLocationY(TargetPos), Damage, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS )
set StompEffect = AddSpecialEffectLoc( "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", TargetPos )
call DestroyEffect( StompEffect )
// Move casting unit to the target location
call SetUnitPosition( LastUnit, GetLocationX(TargetPos), GetLocationY(TargetPos))
// Remove positive and negative magical buffs and aura buffs
call UnitRemoveBuffsEx(LastUnit, true, true, true, false, false, true, true)
// Create "partial" unit from casting unit stats
set NewUnit = CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), GetUnitTypeId(LastUnit), GetLocationX(UnitPos), GetLocationY(UnitPos), GetUnitFacing(LastUnit) )
// Check if casting unit is a hero || Will not copy items
if (IsHeroUnitId(GetUnitTypeId(LastUnit))) then
call SetHeroLevel(NewUnit, GetHeroLevel(LastUnit), false)
call ModifyHeroSkillPoints(NewUnit, bj_MODIFYMETHOD_SET, GetHeroSkillPoints(LastUnit))
endif
call SetUnitColor( NewUnit, GetPlayerColor(GetOwningPlayer(LastUnit)) )
call SetUnitUseFood(NewUnit, false)
// Set Life and Mana
call SetUnitState(NewUnit, UNIT_STATE_MANA, GetUnitState(NewUnit, UNIT_STATE_MAX_MANA) * RMaxBJ(0,GetUnitStatePercent(LastUnit, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)) * 0.01)
call SetUnitState(NewUnit, UNIT_STATE_LIFE, GetUnitState(NewUnit, UNIT_STATE_MAX_LIFE) * RMaxBJ(0,GetUnitStatePercent(LastUnit, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)) * 0.01)
// Add the warp effects
set NewEffect = AddSpecialEffectTarget( "Abilities\\Spells\\Orc\\Voodoo\\VoodooAuraTarget.mdl", NewUnit, "overhead" )
set LastEffect = AddSpecialEffectTarget( "Abilities\\Spells\\Orc\\Voodoo\\VoodooAuraTarget.mdl", LastUnit, "overhead" )
// Pauses the units and animation indefinitely and make them partially transparant
call PauseUnit( LastUnit, true )
call PauseUnit( NewUnit, true )
call SetUnitTimeScale( LastUnit, 0.00 )
call SetUnitTimeScale( NewUnit, 0.00 )
// Sleep for a while, depending on the level of the ability and distance travelled
// Ensure that the sleep goes for 0.27 seconds
//Loop through transticks if transparency is enabled
if (not Transparency) then
call TriggerSleepAction(SleepLen)
else
set Index = 0.00
set LastTrans = MinTrans
set NewTrans = 255
loop
exitwhen (Index > TransTicks)
call SetUnitVertexColor(LastUnit, 255, 255, 255, LastTrans)
call SetUnitVertexColor(NewUnit, 255, 255, 255, NewTrans)
set LastTrans = LastTrans + TickAmount
set NewTrans = NewTrans - TickAmount
call TriggerSleepAction(SleepLen)
set Index = Index + IndexInc
endloop
call SetUnitVertexColor(LastUnit, 255, 255, 255, LastTrans)
call SetUnitVertexColor(NewUnit, 255, 255, 255, NewTrans)
endif
// Unpause the casting unit
call SetUnitTimeScalePercent( LastUnit, 100.00 )
call PauseUnit( LastUnit, false )
call SetUnitVertexColor(LastUnit, 255, 255, 255, 255)
// Remove warp effects
call DestroyEffect( LastEffect )
call DestroyEffect( NewEffect )
// Check if unit died in transit
if ( not(GetUnitState(NewUnit, UNIT_STATE_LIFE) <= 0) ) then
if ( not(GetUnitState(LastUnit, UNIT_STATE_LIFE) <= 0) ) then
call SetUnitState(LastUnit, UNIT_STATE_LIFE, GetUnitState(LastUnit, UNIT_STATE_MAX_LIFE) * RMaxBJ(0,RMinBJ(GetUnitStatePercent(LastUnit, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE), GetUnitStatePercent(NewUnit, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE))) * 0.01)
call RemoveUnit( NewUnit )
endif
else
call SetUnitExploded(LastUnit, true)
call KillUnit(LastUnit)
endif
// Clean up
call RemoveUnit( NewUnit )
call RemoveLocation(TargetPos)
call RemoveLocation(UnitPos)
set LastUnit = null
set NewUnit = null
set StompEffect = null
set NewEffect = null
set LastEffect = null
set TargetPos = null
set UnitPos = null
endfunction
//
// Anti Leak Filter used to recover trigger leaks
//
function AntiLeakFilter takes nothing returns boolean
return true
endfunction
//===========================================================================
function InitTrig_Warp_Jump takes nothing returns nothing
local trigger WarpJump
local filterfunc filter
local integer index
set WarpJump = CreateTrigger( )
set filter = Filter(function AntiLeakFilter)
set index = 0
loop
call TriggerRegisterPlayerUnitEvent(WarpJump, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, filter)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition( WarpJump, Condition( function warp_jump_conditions ) )
call TriggerAddAction( WarpJump, function warp_jump_actions )
call DestroyFilter(filter)
set WarpJump = null
set filter = null
endfunction