- Joined
- Sep 16, 2008
- Messages
- 47
Hi, i got a problem because spell i created is not mui for unknow reason and game is crashing sometimes.
here is code:
here is code:
JASS:
scope Multishoot /* version 1.0
****************************************************************************************************************************************
*
* Requires:
* - GroupUtils
*
*
*
*
*
*
*
*
*
*
*
*
*
*
****************************************************************************************************************************************/
globals
private constant integer SPELL_CODE = 'A000'
private constant integer DUMMY_CODE = 'u001'
private constant integer AMMOUT = 7
private constant real CREATE_DIST = 75
private constant real ANGLE_MAX = 45
private constant real DUMMY_HEIGHT = 75
private constant real DUMMY_SIZE = 100
private constant real DAMAGE_RANGE = 35
private constant string DAMAGE_EFFECT_ATTACH = "chest"
private constant string DAMAGE_EFFECT = "Abilities\\Spells\\Other\\BlackArrow\\BlackArrowMissile.mdl"
private constant boolean COLLIDE = true
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_MAGIC
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_DEATH
endglobals
/*********************************************************************************/
/*********************************************************************************/
globals
private constant real array M_DAMAGE
private constant real array M_SPEED
private constant real array M_DISTANCE
endglobals
/*********************************************************************************/
/*********************************************************************************/
private function onConfig takes nothing returns nothing
set M_DAMAGE[1] = 15
set M_DAMAGE[2] = 30
set M_DAMAGE[3] = 45
set M_DISTANCE[1] = 800
set M_DISTANCE[2] = 900
set M_DISTANCE[3] = 1000
set M_SPEED[1] = 500
set M_SPEED[2] = 550
set M_SPEED[3] = 600
endfunction
/*********************************************************************************/
/*********************************************************************************/
globals
private constant real INTERVAL = 0.031250
private constant timer TIMER = CreateTimer()
endglobals
/*********************************************************************************/
/*********************************************************************************/
private struct Multishoot
private thistype next
private thistype prev
private static integer count = 0
private static unit caster
private static player owner
private static real speed
private static real damage
private static integer left
private static group IgnoreGroup
private static unit array dummy
private static real array distance
private static real array angle
private static group array DamageGroup
private method onDestroy takes nothing returns nothing
call this.deallocate()
set this.next.prev = this.prev
set this.prev.next = this.next
set count = count - 1
if count == 0 then
call PauseTimer(TIMER)
endif
endmethod
private static method onLoop takes nothing returns nothing
local thistype this = thistype(0).next
local integer i = 0
local real dx
local real dy
local real mx
local real my
local unit D
loop
exitwhen this == 0
loop
exitwhen i == AMMOUT
set dx = GetUnitX(this.dummy[i])
set dy = GetUnitY(this.dummy[i])
set mx = dx + this.speed * Cos(this.angle[i])
set my = dy + this.speed * Sin(this.angle[i])
call SetUnitX(this.dummy[i], mx)
call SetUnitY(this.dummy[i], my)
set this.DamageGroup[i] = NewGroup()
call GroupUnitsInArea(this.DamageGroup[i], mx, my, DAMAGE_RANGE)
loop
set D = FirstOfGroup(this.DamageGroup[i])
exitwhen D == null
if IsUnitInGroup(D, this.IgnoreGroup) == false and IsUnitAlly(D, this.owner) == false then
call UnitDamageTarget(this.caster, D, this.damage, false, true, ATTACK_TYPE, DAMAGE_TYPE, null)
call DestroyEffect(AddSpecialEffectTarget(DAMAGE_EFFECT, D, DAMAGE_EFFECT_ATTACH))
call GroupAddUnit(this.IgnoreGroup, D)
if COLLIDE then
set this.distance[i] = this.distance[i] - this.distance[i]
endif
endif
call GroupRemoveUnit(this.DamageGroup[i], D)
endloop
call ReleaseGroup(this.DamageGroup[i])
set this.distance[i] = this.distance[i] - this.speed
if this.distance[i] <= 0 then
call KillUnit(this.dummy[i])
set this.dummy[i] = null
set this.left = this.left - 1
endif
set i = i + 1
endloop
if this.left == 0 then
call this.onDestroy()
set this.caster = null
call ReleaseGroup(this.IgnoreGroup)
endif
set this = this.next
endloop
endmethod
private static method onCast takes nothing returns boolean
local thistype this = thistype.allocate()
local integer i = 0
local integer level
local real cx
local real cy
local real tx
local real ty
local real crx
local real cry
local real angles
local real anglesinc
local unit u
set this.next = 0
set this.prev = thistype(0).prev
set thistype(0).prev.next = this
set thistype(0).prev = this
set count = count + 1
if count == 1 then
call TimerStart(TIMER, INTERVAL, true, function thistype.onLoop)
endif
set this.caster = GetTriggerUnit()
set this.owner = GetOwningPlayer(this.caster)
set level = GetUnitAbilityLevel(this.caster, SPELL_CODE)
set this.damage = M_DAMAGE[level]
set this.speed = M_SPEED[level] * INTERVAL
set this.left = AMMOUT
set this.IgnoreGroup = NewGroup()
set cx = GetUnitX(this.caster)
set cy = GetUnitY(this.caster)
set tx = GetSpellTargetX()
set ty = GetSpellTargetY()
set angles = Atan2(ty - cy, tx- cx) - ANGLE_MAX
set anglesinc = ANGLE_MAX * 2 / AMMOUT
loop
exitwhen i == AMMOUT
set crx = cx + CREATE_DIST * Cos(angles)
set cry = cy + CREATE_DIST * Sin(angles)
set u = CreateUnit(this.owner, DUMMY_CODE, crx, cry, GetUnitFacing(this.caster) + angles)
call SetUnitFlyHeight(u, DUMMY_HEIGHT, 0)
call SetUnitScale(u, DUMMY_SIZE * 0.01, DUMMY_SIZE * 0.01, DUMMY_SIZE * 0.01)
set this.dummy[i] = u
set this.angle[i] = angles
set this.distance[i] = M_DISTANCE[level]
set angles = angles + anglesinc
set i = i + 1
endloop
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function thistype.onCast))
call onConfig()
set t = null
endmethod
endstruct
endscope