library SimpleSpawnSystem requires T32
//
// *Simple Spawn System*
// by baassee
//
// *Requirements*
// T32 by Jesus4Lyf
//
// *Standard information*
//
// A perfect system for TDs, AOSes, hero defences etc. It can create waves that spawn
// different amount of units. Waves are of course chooseable and you can also choose
// if you want the units to have no collision or maybe a different owner. This is a bit
// different towards my other system yet it's the same but with more features and better
// coding. The system have a few globals which starts with SPAWN"LETTERS". These are used
// for the the functions which ends with an "Ex". Basically if the spawnings like in mauls
// ,tds the owner of the creeps are the same so you can set this to this "player" and the
// system will use this and you will have less arguments to think of, nice huh?
//
// I remade my Simple Spawn System in GUI into vJASS, this means that the system
// exists in GUI too for those who want it yet it will be a huge performance
// increaser to use this system but of course it won't matter which one you choose
// they will do exactly the same thing.
//
// After v1.1b, the spawnsystem uses J4L's T32 Which is the best timer system out there
// please beaware that the period is no longer choose able but instead this is a
// major performance increase.
//
// Read the how to import below and read about the functions and how to use them.
// I also showed in an example how to use this in GUI as this is GUI-Friendly.
//
//
// *How to import*
//
// 1. Copy over T32, either the trigger in this category or from here:
// http://www.thehelper.net/forums/showthread.php/132538-Timer32
//
// 2. Copy over this trigger. Follow the setup below this section for extra
// configurations.
//
// 3. Credit me for this system and Jesus4Lyf for T32.
//
// 4. Now you are done! You can now use the system!
//
//
// *SETUP PART*
//
globals
//where the effect is attached to a spawned unit
private constant string ATTACH = "origin"
//
// BELOW HERE YOU CAN SET SOME CONSTANT GLOBALS WHICH ARE USED FOR THE FUNCTIONS
// WHICH ENDS WITH "Ex". They are used to predefine all stuff except the unit type.
// Also there are more than one "Ex" function for your needs.
//
// As example I've chosen Lightblue just for the example but just change the number "9"
// to the number of the player.
// REMEMBER! that player red is number 0 and blue number 1 and so on.
//
private constant player SPAWNPLAYER = Player(9)
//
// The interval between each "wave" of spawnings. This is used if you want
// a constant spawning flow. Useful I guess.
//
private constant real SPAWNINTERVAL = 1.5
//
// The x coordinate which the units will spawn on, if you have multiple spawning coordinates
// but still wants to use the Ex functions use the normal Ex function.
//
private constant real SPAWNX = 894.
//
// The y coordinate which the units will spawn on. Same as above.
//
private constant real SPAWNY = -1276.
//
// The spawns facing angle, please have a value between 0 and 360.
//
private constant real SPAWNFACE = 180.
//
// The spawn amount each interval, prefer 1. Won't bug with more of course.
//
private constant integer SPAWNAMOUNT = 1
//
// The amount of spawn waves, this can be a bit tricky if you have a boss stage
// so use another function for the boss in that case.
//
private constant integer SPAWNWAVES = 10
//
// If spawned units should have collision or not.
//
private constant boolean SPAWNCOLLISION = false
//
// If you want a special effect when the unit is spawned, set it here else just set it to ""
//
private constant string SPAWNEFFECT = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
endglobals
private struct SpawnSystem
//members that the create method takes
integer id //the unit id
integer w // the amount of waves
integer am// spawn amount per spawning, usually 1
real sx// spawn x coordinate
real sy// spawn y coordinate
real rmin// random minimum value
real rmax// random maximum value
real face// the facing of the spawned unit
player owner// the owner of the spawned unit
boolean coll = true // if the collision should be turned on
string eff = ""//the spawning effects
// initially it's on
//members which is just inside the struct
real count = 0. //just a count variable
real dur //the duration of each spawning interval
boolean multi = false// if the units are more than 1, initially false
//the loop method
private method periodic takes nothing returns nothing
local integer i // and integer used if the .multi member is true else not
// ordinary if to check if the instance has ended or not
//it ends when the number of waves equals to 0
if .w > 0 then
//if not we do another check if we should spawn a unit
//or just increase the count member
if .count >= .dur then
// if it has reached or are above we reset the count
set .count = 0.
set .w = .w - 1 //reduces amount of waves
// now we check if the amount is bigger than 1
// which is what we set into the multi member
if .multi then
set i = .am // here we use the integer i
// we loop threw amount of spawned units
loop
exitwhen i == 0 // i is used for this cause
// creates unit
// the bj is used for the pathing
set bj_lastCreatedUnit = CreateUnit(.owner, .id, .sx, .sy, .face)
// if collision should be off then we set the pathing of the unit to false
if not .coll then
call SetUnitPathing(bj_lastCreatedUnit, false) //which we do here
endif
if .eff != "" then
call DestroyEffect(AddSpecialEffectTarget(.eff, bj_lastCreatedUnit, ATTACH))
endif
// reduce i so the loop can end
set i = i - 1
endloop
//else we check some other stuff like not collision
//to set the unit into the variable so we do like this
else
set bj_lastCreatedUnit = CreateUnit(.owner, .id, .sx, .sy, .face)
call SetUnitPathing(bj_lastCreatedUnit, .coll)
endif
//check the effect stuff
if .eff != "" then
//we create the effect if needed
call DestroyEffect(AddSpecialEffectTarget(.eff, bj_lastCreatedUnit, ATTACH))
endif
// here is just a check if the interval is constant
// else we just re-set the interval to a new randomized value
if .rmin != .rmax then
set .dur = GetRandomReal(.rmin, .rmax)
endif
else
// if the count isn't above the interval
// we increase it
set .count = .count + T32_PERIOD
endif
// if the instance has ended, we recycle
else
call .stopPeriodic()
call .destroy() // and the struct
endif // that was it! like I said, simple.
endmethod
//the spawn system create method
static method create takes integer unitid, integer waves, integer amount, real x, real y, real rmin, real rmax, real facing, player owner, boolean collision, string eff returns thistype
local thistype this = thistype.allocate() //initiallies
//below we set necessary information into our struct members
set .id = unitid //the id of the unit type
set .w = waves // amount of waves
set .am = amount // amount of spawnings each "wave"
//just some performance and bug fixes with collision
if amount > 1 then
set .multi = true //used if the amount spawned are greater than 1
endif
// spawn coordinates
set .sx = x //x coordinate
set .sy = y //y coordinate
// this is used for our feature "random spawning interval"
// uses min value and max value for GetRandomReal.
// if it's constant, it's checks a few lines below
set .rmin = rmin //the minimum value
set .rmax = rmax //the maxium value
set .face = facing //facing of the spawned unit
set .owner = owner //the owner of the spawned unit
//checks if the effect string is not nothing so we can store the string.
if eff != "" then
set .eff = eff
endif
// as collision is set to true by default
//I'll set the collision anyways
set .coll = collision
// here are some debugging
// if the minimum value is greater than the max value
// it resets the min value with a random value added
if rmin > rmax then
set .rmin = rmax - GetRandomReal(0., rmax - 1)
// debug message
debug call BJDebugMsg("Spawn System Error - Your random minimum value was greater than the max value.")
endif
// here comes the check if the intervals are constant
// if not then we just randomize the duration
if rmin != rmax then
set .dur = GetRandomReal(rmin, rmax)
else // else we set it to the rmin
set .dur = rmin
endif
call .startPeriodic()
// now we're done, move on to the loop!
return this
endmethod
implement T32x
endstruct
function CreateSpawnWave takes integer unitid, integer waves, integer amount, real x, real y, real rmin, real rmax, real face, player owner, boolean collision, string eff returns SpawnSystem
return SpawnSystem.create(unitid, waves, amount, x, y, rmin, rmax, face, owner, collision, eff)
endfunction
function CreateSpawnWaveLoc takes integer unitid, integer waves, integer amount, location loc, real rmin, real rmax, real face, player owner, boolean collision, string eff returns SpawnSystem
return SpawnSystem.create(unitid, waves, amount, GetLocationX(loc), GetLocationY(loc), rmin, rmax, face, owner, collision, eff)
endfunction
function CreateSpawnWaveConstant takes integer unitid, integer waves, integer amount, real x, real y, real period, real face, player owner, boolean collision, string eff returns SpawnSystem
return SpawnSystem.create(unitid, waves, amount, x, y, period, period, face, owner, collision, eff)
endfunction
function CreateSpawnWaveConstantLoc takes integer unitid, integer waves, integer amount, location loc, real period, real face, player owner, boolean collision, string eff returns SpawnSystem
return SpawnSystem.create(unitid, waves, amount, GetLocationX(loc), GetLocationY(loc), period, period, face, owner, collision, eff)
endfunction
function CreateSpawnWaveEx takes integer unitid, integer waves, integer amount, real x, real y, real rmin, real rmax, real face, boolean collision, string eff returns SpawnSystem
return SpawnSystem.create(unitid, waves, amount, x, y, rmin, rmax, face, SPAWNPLAYER, collision, eff)
endfunction
function CreateSpawnWaveExCoord takes integer unitid, integer waves, integer amount, real rmin, real rmax, real face, boolean collision, string eff returns SpawnSystem
return SpawnSystem.create(unitid, waves, amount, SPAWNX, SPAWNY, rmin, rmax, face, SPAWNPLAYER, collision, eff)
endfunction
function CreateSpawnWaveExAll takes integer unitid returns SpawnSystem
return SpawnSystem.create(unitid, SPAWNWAVES, SPAWNAMOUNT, SPAWNX, SPAWNY, SPAWNINTERVAL, SPAWNINTERVAL, SPAWNFACE, SPAWNPLAYER, SPAWNCOLLISION, SPAWNEFFECT)
endfunction
endlibrary