- Joined
- Mar 10, 2009
- Messages
- 5,016
Hello hivers!
1) I want to ask why if I enable the .flush(), it doesnt work well...
2) Does it leak when Im not flushing?, (in my understanding, no if it's not a handle)...
3) Should I use
3) Id like suggestion of code pls (not nullings, use TU)...
Description:
Spawns units from the XY of caster, the spawned units patrol around the
caster, if the caster moves all spawned units dies. Qty of spawn units
depends on the level of the caster.
1) I want to ask why if I enable the .flush(), it doesnt work well...
2) Does it leak when Im not flushing?, (in my understanding, no if it's not a handle)...
3) Should I use
call cast.flush()
and call out.flush()
only if condition (global integer index) is met?, like index==0?...3) Id like suggestion of code pls (not nullings, use TU)...
Description:
Spawns units from the XY of caster, the spawned units patrol around the
caster, if the caster moves all spawned units dies. Qty of spawn units
depends on the level of the caster.
JASS:
/*
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- RegisterPlayerUnitEvent by Magtheridon96
- T32 by Jesus4Lyf
- Table by Bribe
*/
scope Outbreak
globals
private constant integer SPELL_ID = 'A00C' //starfall
private constant integer UNIT_ID = 'hfoo'
private constant integer ORDER_ID = 852183 //starfall
private constant integer MIN_AOE = 400
private constant integer MAX_AOE = 1100
private Table out
private Table cast
endglobals
private function GetUnitQty takes integer i returns integer
return 0 + i * 10
endfunction
private function GetUnitLife takes integer i returns real
return 10 + i * 10.
endfunction
private function GetDuration takes integer i returns real
return 0 + i * 15.
endfunction
private interface Use
unit caster
real interval
real xLoc
real yLoc
endinterface
private struct Attacking extends Use
unit spawn
method periodic takes nothing returns nothing
local real xEn
local real yEn
local integer distx
local real angle
if not IsUnitType(.spawn, UNIT_TYPE_DEAD) and GetUnitCurrentOrder(.caster)==ORDER_ID then
set .interval = .interval + T32_PERIOD
if .interval > 3 then
set .interval = 0
if GetUnitCurrentOrder(.spawn)!=851990 then //patrol
set distx = GetRandomInt(MIN_AOE, MAX_AOE)
set angle = GetRandomReal(-5,5)
call IssuePointOrderById(.spawn, 851990, .xLoc + distx * Cos(angle), .yLoc + distx * Sin(angle))
endif
endif
else
call KillUnit(.spawn)
call .stopPeriodic()
call .deallocate()
endif
endmethod
implement T32x
static method create takes unit c,unit u, real x, real y returns thistype
local thistype this = thistype.allocate()
set .caster = c
set .spawn = u
set .xLoc = x
set .yLoc = y
set .interval = 0
call .startPeriodic()
return this
endmethod
endstruct
private struct Outbreak extends Use
real duration
real life
integer maxunit
method periodic takes nothing returns nothing
local unit d
local integer count
local integer casterID
local integer dID
if .duration > 0 and GetUnitCurrentOrder(.caster)==ORDER_ID and not IsUnitType(.caster, UNIT_TYPE_DEAD) then
set .interval = .interval + T32_PERIOD
set .duration = .duration - T32_PERIOD
if .interval > 1 then
set .interval = 0
if .maxunit > (cast[GetHandleId(.caster)]) then
set casterID = GetHandleId(.caster)
set cast[casterID] = cast[casterID] + 1
set d = CreateUnit(GetOwningPlayer(.caster), UNIT_ID, .xLoc, .yLoc, 0)
set dID = GetHandleId(d)
call UnitApplyTimedLife(d, 'BTLF', .life)
set out[dID] = 1
set out.unit[dID] = .caster
call Attacking.create(.caster, d, .xLoc, .yLoc)
set d = null
//call BJDebugMsg(I2S(cast[casterID]))
endif
endif
else
//call out.flush()
//call cast.flush()
call IssueImmediateOrder(.caster, "stop")
call .stopPeriodic()
call .deallocate()
endif
endmethod
implement T32x
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
local integer level = GetUnitAbilityLevel(GetTriggerUnit(), SPELL_ID)
set .caster = GetTriggerUnit()
set .xLoc = GetUnitX(.caster)
set .yLoc = GetUnitY(.caster)
set .interval = 0.
set .duration = GetDuration(level)
set .maxunit = GetUnitQty(level)
set .life = GetUnitLife(level)
call .startPeriodic()
return this
endmethod
private static method cond takes nothing returns nothing
if GetSpellAbilityId()==SPELL_ID then
call thistype.create()
endif
endmethod
private static method death takes nothing returns nothing
local integer casterID
local integer id
local unit u
local unit caster
if GetUnitTypeId(GetTriggerUnit())==UNIT_ID then
set u = GetTriggerUnit()
set id = GetHandleId(u)
if out[id]==1 then
set caster = out.unit[id]
set casterID = GetHandleId(caster)
set cast[casterID] = cast[casterID] - 1
set caster = null
//call out.flush()
endif
set u = null
endif
endmethod
private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.cond)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function thistype.death)
set out = Table.create()
set cast = Table.create()
endmethod
endstruct
endscope
Last edited: