scope fanOfToxicKnives initializer init
//****************************************************
//START OF THE CONFIGURATION
//****************************************************
globals
constant integer abilityId = 'A000'//Hero ability rawcode
constant integer abilityId2 = 'A001'//Slow ability rawcode
constant string slowOrder = "slow"//Slow ability order
constant string missileModel = "Abilities\\Weapons\\WardenMissile\\WardenMissile.mdl"//Missile model
constant integer unitType = 'u001'//Unit type of the missile and caster
constant real interval = 0.03125//Interval of the spell (0.03125 = 32FPS)
constant damagetype damageType = DAMAGE_TYPE_NORMAL//Damage type of the deal
constant attacktype attackType = ATTACK_TYPE_NORMAL//Attack type of the deal
constant weapontype weaponType = WEAPON_TYPE_WHOKNOWS//Weapon type of the deal
real missileScale = 1.9//Scale of the missile
integer colorRed = 120//Red color of the missile
integer colorGreen = 255//Green color of the missile
integer colorBlue = 0//Blue color of the missile
real speed = 1200//Movement speed of the missile
endglobals
private function damageDealed takes integer level returns real
return 90. + 30. * level//Damage dealed each level
endfunction
private function areaOfEffect takes integer level returns real
return 220. + 80. * level//Area of effect each level
endfunction
//****************************************************
//END OF THE CONFIGURATION
//****************************************************
struct knive
unit dealer
unit target
unit dummy
boolean quit
integer level
effect eff
endstruct
globals
timer Tim = CreateTimer()
knive array Ar
integer Total = 0
endglobals
private function action takes nothing returns nothing
local knive kn
local integer i = 0
local real x
local real y
local real x1
local real y1
local real angle
local unit caster
loop
exitwhen i >= Total
set kn = Ar[i]
set x = GetUnitX(kn.dummy)
set y = GetUnitY(kn.dummy)
set x1 = GetUnitX(kn.target)
set y1 = GetUnitY(kn.target)
set angle = bj_RADTODEG * Atan2(y1 - y, x1 - x)
call SetUnitPosition(kn.dummy, x + speed * interval * Cos(bj_DEGTORAD * angle), y + speed * interval * Sin(bj_DEGTORAD * angle))
call SetUnitFacing(kn.dummy, angle)
set kn.quit = IsUnitType(kn.target, UNIT_TYPE_DEAD) or IsUnit(kn.target, null)
if SquareRoot((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)) < 50 then
call UnitDamageTarget(kn.dealer, kn.target, damageDealed(kn.level), true, false, attackType, damageType, weaponType)
set kn.quit = true
endif
if kn.quit then
call SetUnitExploded(kn.dummy, true)
call KillUnit(kn.dummy)
call DestroyEffect(kn.eff)
set caster = CreateUnit(GetOwningPlayer(kn.dealer), unitType, x1, y1, 0)
call UnitAddAbility(caster, abilityId2)
call SetUnitAbilityLevel(caster, abilityId2, kn.level)
call IssueTargetOrder(caster, slowOrder, kn.target)
call UnitApplyTimedLife(caster, 'BTLF', 0.5)
set caster = null
set Ar[i] = Ar[Total - 1]
set Total = Total - 1
call kn.destroy()
set caster = null
endif
set i = i + 1
endloop
if Total == 0 then
call PauseTimer(Tim)
endif
endfunction
private function run takes nothing returns boolean
local knive kn
local unit caster
local unit picked
local real x
local real y
local real x1
local real y1
local real angle
local player pla
local integer level
if GetSpellAbilityId() == abilityId then
set caster = GetTriggerUnit()
set pla = GetOwningPlayer(caster)
set level = GetUnitAbilityLevel(caster, abilityId)
set x = GetUnitX(caster)
set y = GetUnitY(caster)
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, areaOfEffect(level), null)
loop
set picked = FirstOfGroup(bj_lastCreatedGroup)
exitwhen picked == null
call GroupRemoveUnit(bj_lastCreatedGroup, picked)
if IsUnitEnemy(picked, pla) and not IsUnitType(picked, UNIT_TYPE_DEAD) and not IsUnitType(picked, UNIT_TYPE_STRUCTURE) and not IsUnitType(picked, UNIT_TYPE_MAGIC_IMMUNE) then
set kn = knive.create()
set x1 = GetUnitX(picked)
set y1 = GetUnitY(picked)
set angle = bj_RADTODEG * Atan2(y1 - y, x1 - x)
set kn.dealer = caster
set kn.target = picked
set kn.level = level
set kn.dummy = CreateUnit(pla, unitType, x + 50 * Cos(bj_DEGTORAD * angle), y + 50 * Sin(bj_DEGTORAD * angle), angle)
set kn.eff = AddSpecialEffectTarget(missileModel, kn.dummy, "origin")
set kn.quit = false
call SetUnitScale(kn.dummy, missileScale, missileScale, missileScale)
call SetUnitVertexColor(kn.dummy, colorRed, colorGreen, colorBlue, 255)
if Total == 0 then
call TimerStart(Tim, interval, true, function action)
endif
set Total = Total + 1
set Ar[Total - 1] = kn
endif
endloop
set caster = null
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer index = 0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(t, Condition(function run))
set bj_lastCreatedUnit = CreateUnit(Player(0), unitType, 0, 0, 0)
call UnitAddAbility(bj_lastCreatedUnit, abilityId)
call UnitAddAbility(bj_lastCreatedUnit, abilityId2)
call RemoveUnit(bj_lastCreatedUnit)
set bj_lastCreatedUnit = null
if missileScale > 3 then
set missileScale = 3
elseif missileScale < 0.4 then
set missileScale = 0.4
endif
if colorRed > 255 then
set colorRed = 255
elseif colorRed < 0 then
set colorRed = 0
endif
if colorGreen > 255 then
set colorGreen = 255
elseif colorGreen < 0 then
set colorGreen = 0
endif
if colorBlue > 255 then
set colorBlue = 255
elseif colorBlue < 0 then
set colorBlue = 0
endif
if speed > 1800 then
set speed = 1800
elseif speed < 50 then
set speed = 50
endif
set t = null
endfunction
endscope