scope MovingStrike initializer Init
// +-------------------------------------------------------------------------------+
// | Possession - Created by Chaos_Knight. Requires a vJass preprocessor! |
// +-------------------------------------------------------------------------------+
// | Gives a small chance to permanently change control of the target unit |
// | to the owner of the attacker. |
// +-------------------------------------------------------------------------------+
// | How to Import: |
// | - Create a new trigger |
// | - Convert it to Custom text (Edit > Convert to Custom Text) |
// | - Replace everything there with this code |
// | - Change the constants to suit yourself |
// | - Enjoy! |
// +-------------------------------------------------------------------------------+
// |-------------|
// | Constants: |
// |-------------|
globals
// The effect created on the target when it is being possessed:
private constant string EFFECT = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
private constant string EFFECT2 = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl"
// Which is attached to the targets:
private constant string EFFECT_POSITION = "weapon,left"
private constant string EFFECTPOSITION = "weapon,right"
private constant integer DUMMYSPELLID = 'Q009'
// The Raw code of the ability
private constant integer ID = 'A008'
endglobals
private constant function CHANCE takes integer level returns integer
// The chance of a unit being possessed. "level" is the level of the ability.
return level * 2
endfunction
// |------------------|
// | End of Constants |
// |------------------|
// DO NOT EDIT BELOW THIS LINE!
private function True takes nothing returns boolean
return true
endfunction
private function Cons takes nothing returns boolean
return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetAttacker())) and GetRandomInt(0, 100) <= CHANCE(GetUnitAbilityLevel(GetAttacker(), ID)) and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false and GetUnitAbilityLevel(GetAttacker(), ID) > 0
endfunction
private function Move takes nothing returns nothing
local unit u = GetAttacker()
local unit t = GetTriggerUnit()
local real x1 = GetUnitX( u )
local real y1 = GetUnitY( u )
local real x2 = GetUnitX( t )
local real y2 = GetUnitY( t )
local real angle = Atan2(y2 - y1, x2 - x1)
call SetUnitX( u , x2 + 128 * Cos(angle))
call SetUnitY( u , y2 + 128 * Sin(angle))
set u = null
set t = null
endfunction
private function Attack takes nothing returns nothing
local unit u = GetAttacker()
local unit t = GetTriggerUnit()
local real dmg = 25 * GetUnitAbilityLevel( u ,ID )
call UnitDamageTarget( u , t , dmg , true , true , ATTACK_TYPE_CHAOS , DAMAGE_TYPE_FIRE , WEAPON_TYPE_WHOKNOWS )
endfunction
private function Moving takes nothing returns nothing
local unit u = GetAttacker()
local unit t = GetTriggerUnit()
local real dmg = 25 * GetUnitAbilityLevel( u , ID )
local texttag TT = CreateTextTag()
call SetTextTagText( TT , "You have dealt " + R2S(dmg) + " Damage" , 100 )
call SetTextTagColor( TT , 200 , 125 , 255 , 255 )
call SetTextTagPos( TT , GetUnitX(u) , GetUnitY(u) , 100 )
call SetTextTagVisibility( TT , true )
call SetTextTagLifespan( TT, 5 )
call DestroyEffect(AddSpecialEffectTarget(EFFECT, u, EFFECT_POSITION))
call DestroyEffect(AddSpecialEffectTarget(EFFECT2, u, EFFECTPOSITION))
call Move()
call Attack()
set u = null
set t = null
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
set i = i + 1
endloop
call TriggerAddCondition(t, Filter(function Cons))
call TriggerAddAction(t, function Moving)
endfunction
endscope