//===Simple Missile System
//Created by: Mckill2009
//Requires:
//- Jass New Gen Pack By Vexorian
//- Timer32 By Jesus4Lyf ([url]http://www.thehelper.net/forums/showthread.php/132538-Timer32[/url])
//How to Install:
//- Create 2 triggers named MS and T32x, convert it to custom text >>> EDIT >>> CONVERT TO CUSTOM TEXT
//- Create 1 dummy unit as the caster of the stun
//- Create 1 unit modeled as shochwave
//- Copy the Timer32 library from [url]http://www.thehelper.net/forums/showthread.php/132538-Timer32[/url] and paste it to your T32x trigger
//- Copy the code I made and paste it to the MS trigger
//- Take note that you MUST overwrite all text from MS and T32x when pasting
//- Change the raw code of DUMMY_ID if needed, raw codes can be viewed by pressing CTRL + D from object editor
library SimpleMissileSystem uses T32x
globals
private constant integer DUMMY_ID = 'h001' //raw code of the UNIT dummy, change this if needed, but it MUST have mana
private constant integer MISSILE_SPEED = 30 //speed in which the missile travels
private constant attacktype ATK = ATTACK_TYPE_NORMAL
private constant damagetype DMG = DAMAGE_TYPE_NORMAL
private constant boolean ENABLE_FIRST_TARGET = false //set to true if you want to enable first target spell
endglobals
private struct MS
unit missile
real angle
real distance
real xdist = 0
real aoe
real damage
integer abilId
integer orderId
integer level
boolean check = true
private static thistype DATA
private static method filterfirst takes nothing returns boolean
local thistype this = DATA
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(.missile)) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD)
endmethod
private static method damageall takes nothing returns boolean
local thistype this = DATA
local unit u = GetFilterUnit()
if IsUnitEnemy(u, GetOwningPlayer(.missile)) and not IsUnitType(u, UNIT_TYPE_DEAD) then
call UnitDamageTarget(.missile, u, .damage, false, false, ATK, DMG, null)
endif
set u = null
return false
endmethod
method periodic takes nothing returns nothing
local unit first
local unit dummy
local real x
local real y
if .distance > .xdist then
set x = GetUnitX(.missile)
set y = GetUnitY(.missile)
set .xdist = .xdist + MISSILE_SPEED
call SetUnitX(.missile, x + MISSILE_SPEED * Cos(.angle))
call SetUnitY(.missile, y + MISSILE_SPEED * Sin(.angle))
set DATA = this
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, .aoe, function thistype.damageall)
if ENABLE_FIRST_TARGET then
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, .aoe, function thistype.filterfirst)
set first = FirstOfGroup(bj_lastCreatedGroup)
if .check and first != null then
set .check = false
set dummy = CreateUnit(GetOwningPlayer(.missile), DUMMY_ID, x, y, 0)
call UnitAddAbility(dummy, .abilId)
call SetUnitAbilityLevel(dummy, .abilId, .level)
call IssueTargetOrderById(dummy, .orderId, first)
endif
endif
else
call KillUnit(.missile)
call .stopPeriodic()
call .destroy()
endif
set first = null
set dummy = null
endmethod
implement T32x
static method create takes unit m, real a, real d, real ao, real dam, integer ab, integer o, integer l returns thistype
local thistype this = thistype.allocate()
set .missile = m
set .angle = a
set .distance = d
set .aoe = ao
set .abilId = ab
set .orderId = o
set .level = l
set .damage = dam * T32x_PERIOD
call .startPeriodic()
return this
endmethod
endstruct
//this is the only function you will call
//Sample >>> call SetMissile(missile, GetSpellTargetX(), GetSpellTargetY(), 200, 100, 'AHtb', 852095, 1)
function SetMissile takes unit missile, real xDist, real yDist, real aoe, real damage, integer abilId, integer orderId, integer level returns nothing
local real x = GetUnitX(missile)
local real y = GetUnitY(missile)
local real angle = Atan2(yDist-y, xDist-x)
local real distance = SquareRoot((xDist-x)*(xDist-x) + (yDist-y)*(yDist-y))
call MS.create(missile, angle, distance, aoe, damage, abilId, orderId, level)
endfunction
endlibrary