//Spell Name: Combat Knife
//Created by: Mckill2009
scope CombatKnife initializer init
globals
private constant integer SPELL_ID = 'A000'
private constant attacktype ATK = ATTACK_TYPE_PIERCE
private constant damagetype DMG = DAMAGE_TYPE_NORMAL
private constant string SFX = "Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl"
private constant string ATTACHMENT = "chest"
private constant real AOE = 90
private unit TEMP_UNIT
endglobals
private function GetDamageMin takes integer i returns real
return 1 + i * 2.
endfunction
private function GetDamageMax takes integer i returns real
return 3 + i * 9.
endfunction
private function OrganicUnit takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_MECHANICAL) and not IsUnitType(u, UNIT_TYPE_ANCIENT) and /*
*/not IsUnitType(u, UNIT_TYPE_TOWNHALL)
endfunction
private function FilterUnit takes nothing returns boolean
local unit u = GetFilterUnit()
local boolean b = GetWidgetLife(u) > 0.405 and IsUnitEnemy(TEMP_UNIT, GetOwningPlayer(u)) and not IsUnitType(u, UNIT_TYPE_FLYING)
set u = null
return b
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit first
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real x1
local real y1
local real facing = GetUnitFacing(u)*bj_DEGTORAD
local integer level = GetUnitAbilityLevel(u, SPELL_ID)
local real damage = GetRandomReal(GetDamageMin(level), GetDamageMax(level))
local texttag tag
set x1 = x+90*Cos(facing)
set y1 = y+90*Sin(facing)
set TEMP_UNIT = u
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x1, y1, AOE, function FilterUnit)
set first = FirstOfGroup(bj_lastCreatedGroup)
if first !=null then
set tag = CreateTextTag()
call UnitDamageTarget(u, first, damage, false, false, ATK, DMG, null)
if OrganicUnit(first) then
call DestroyEffect(AddSpecialEffectTarget(SFX, first, ATTACHMENT))
endif
call SetTextTagPosUnit(tag, first, 0.)
call SetTextTagText(tag, I2S(R2I(damage)), 0.02)
call SetTextTagPermanent(tag, false)
call SetTextTagVelocity(tag, 0.03, 0.03)
call SetTextTagLifespan(tag, 3)
call SetTextTagFadepoint(tag, 0.01)
endif
call IssueImmediateOrder(u, "stop")
set u = null
set first = null
set tag = null
endfunction
private function Cond takes nothing returns boolean
return GetSpellAbilityId()==SPELL_ID
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
call TriggerAddCondition(t, Condition(function Cond))
call TriggerAddAction(t, function Actions)
set t = null
endfunction
endscope