/*
=====Spawn System v1.1
=====by: Mckill2009
HOW TO INSTALL:
- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
- Copy ALL that is written here and overwrite the existing texts in the custom text
- Copy the TimerUtils 2.0 by Vexorian
REQUIREMENTS:
- Jass New Gen Pack by Vexorian
- TimerUtils by Vexorian
HOW TO USE:
- Create a region(rect in Jass) in your map, this is the "r" parameter
- call SpawnSystem.create(p, unittypeid, duration, interval, sfx, r, maxcount, centerregion, life)
PARAMETER EXPLANATION:
- p (Player) = The Player where the spawned unit belong
- unittypeid (Integer) = The UnitType, this is an integer RAW CODE of a unit
- duration (Real) = The duration of the spell
- interval (Real) = The interval of the creation of the spawned unit
- life (Real) = sets the life of created unit
- sfx (String) = Used for Special Effect, strings like "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl" is an example of such
- r (Rect) = Is the rect or region square on which your unit will spawn, example like gg_trg_Region_000
- maxcount (Integer) = the maximum units created
- centerregion (Boolean) = creates center fo the region or in random places
- trig (Trigger) = creates a condition for premature stop, calls TriggerEvaluate that returns boolean, set to null to disable condition
- x (Real) = picks a coordinate (r=rect should be null if this is used)
- y (Real) = picks a coordinate (r=rect should be null if this is used)
HOW TO GET THE RAW CODE:
- You can view the raw codes by pressing CTRL+D in the object editor
- Examples of raw codes are 'uskm', 'hpea', if it's a custom unit then 'h000', 'H000' and so on...
CREDITS: For their suggestions
- watermelon_1234
- Magtheridon96
*/
library SpawnSystem uses TimerUtils
globals
//===CONFIGURABLES:
private constant integer FIXED_MAX_COUNT = 500 //sets the max unit created
endglobals
struct SpawnSystem
player p
integer uType
integer maxcount
real duration
real interval
real life
real xLoc
real yLoc
string sfx
rect r
private boolean center
private trigger trg
static method onSpawnThem takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
local unit dummy
if .duration > 0 and .maxcount > 0 and (TriggerEvaluate(.trg) or .trg==null) then
set .maxcount = .maxcount - 1
set .duration = .duration - .interval
if .r==null then
set dummy = CreateUnit(.p, .uType, .xLoc, .yLoc, 0)
else
if not .center then
set dummy = CreateUnit(.p, .uType, GetRandomReal(GetRectMinX(.r), GetRectMaxX(.r)), GetRandomReal(GetRectMinY(.r), GetRectMaxY(.r)), 0)
else
set dummy = CreateUnit(.p, .uType, GetRectCenterX(.r), GetRectCenterY(.r), 0)
endif
endif
if not IsUnitType(dummy, UNIT_TYPE_FLYING) then
call DestroyEffect(AddSpecialEffect(.sfx, GetUnitX(dummy), GetUnitY(dummy)))
else
call DestroyEffect(AddSpecialEffectTarget(.sfx, dummy,"origin"))
endif
call UnitApplyTimedLife(dummy, 'BTLF', .life)
else
call DestroyTrigger(.trg)
call ReleaseTimer(t)
call .destroy()
endif
set t = null
set dummy = null
endmethod
static method create takes player p, integer unittypeid, real duration, real interval, real lifeduration, string sfx, rect r, integer maxcount, boolean centerregion, trigger trig, real x, real y returns thistype
local thistype this = thistype.allocate()
set .p = p
set .uType = unittypeid
set .duration = duration
set .interval = interval
set .sfx = sfx
set .life = lifeduration
set .r = r
if maxcount > FIXED_MAX_COUNT then
set .maxcount = FIXED_MAX_COUNT
else
set .maxcount = maxcount
endif
set .center = centerregion
set .life = life
set .trg = trig
set .xLoc = x
set .yLoc = y
call TimerStart(NewTimerEx(this), interval, true, function thistype.onSpawnThem)
return this
endmethod
endstruct
endlibrary