Prometheus
Everything is mutable; nothing is sacred
- Reaction score
- 589
This can be used for anything, though I don't think it would be good for a TD. Implementation instructions are in the SUPOT trigger.
Code
Code
JASS:
//==============================================================================
// SUPOT - Spawn Units at Point Over Time by kc102 AKA R34P3R - v6.6
//==============================================================================
//
// PURPOSE OF SUPOT:
// * Spawning units at a point with ease~
//
// PROS:
// * Makes spawning units for anything easy.
//
// CONS:
// * Limited to 8191 instances running at a time.
//
// FUNCTIONS:
// * SUPOT_Start(player PlayerToSpawnFor, integer UnitTypeID, integer NumberOfUnits, real TimePerSpawn, real Spawn Location X, real Spawn Location Y)
// Starts the spawning.
//
// * SUPOT_StartEx(player PlayerToSpawnFor, integer UnitTypeID, integer NumberOfUnits, real TimePerSpawn, location SpawnLocation)
// Starts the spawning using a location, meant for eGUI use.
//
// * SUPOT_Stop(integer Instance ID)
// Stops the spawning for that ID.
//
// * SUPOT_Pause(integer Instance ID)
// Pauses the spawning for that ID.
//
// * SUPOT_UnPause(integer Instance ID)
// Unpauses the spawning for that ID.
//
// * SUPOT_ChangeUnitID(integer Instance ID, integer newUnitID)
// Changes the unit-type spawned for that ID.
//
// * SUPOT_ChangeSpawnTime(integer Instance ID, real newSpawnTime)
// Changes the interval between spawning for that ID.
//
// * SUPOT_ChangePlayer(integer Instance ID, player newPlayer)
// Changes the player that the unit is spawned for, for that ID.
//
// * SUPOT_ChangeSpawnAmount(integer Instance ID, integer newSpawnAmount)
// Changes the number of units spawned per interval, for that ID.
//
// * SUPOT_ChangeLocation(integer Instance ID, real newX, real newY)
// Changes the location of the spawning, for that ID.
//
// * GetLastSpawned(integer Instance)
// This function returns a group with the units made
// in the last run of that SUPOT instance
//
// * GetLastInstance()
// This function is for eGUI mainly, but anyone can use it.
// Since each start returns an integer, this basically takes that integer
// and allows you to set it to a variable after starting SUPOT.
//
// * The start function returns an integer, so make sure to call it properly.
// To stop something, call the stop function with the integer you set to call
// the start function, same with the other functions.
//
// HALPS:
// * Report any bugs or odd happennings please.
// * Assigning a single integer to the function twice will result in
// you only having once instance of SUPOT on that integer.
//
// REQUIREMENTS:
// * NewGen v5 and above (there might be some problems with older NewGen's)
//
//
// HOW TO IMPORT:
// * Copy this code into your map.
//==============================================================================//
// Change Log //
// 1.0 - Release //
// 1.0 to 3.3 - Stuff //
// 4.0 - Major Code Overhaul, Self-Sufficient //
// 4.5 - Added modification functions, inproved code //
// 4.6 - Safeties added to mod functions //
// 4.7 - Added more safeties, fixed a few others //
// 4.8 - Added a pause function //
// 4.9 - Added function so the unit can do stuff //
// 4.10 - Fixed a pause function error //
// 5.0 - Made struct SUPOT open //
// 5.1 - Readme fix //
// 5.2 - Global supot variable is now private //
// 5.3 - All spawned units are now returned VIA group //
// 5.4 - Lst changed to Last <Blame Uberplayer> //
// 5.5 - Slight code changes //
// 5.6 - Major Code Fixes //
// 5.7 - Modifed Pause function, UnPause added //
// 5.75 - SUPOT Public //
// 5.8 - Major & Minor Code Fixes //
// 5.9 - Group Last is now an arrayed group //
// 5.10 - Code Improvements //
// 6.0 - Code Improvments //
// 6.1 - Major Flaw Overcome thanks to Artificial //
// 6.2 - Safety Improvments & Inlining //
// 6.3 - DoubleFree & Invalid X/Y values fixed //
// 6.4 - Improved for eGUI, code touchups //
// 6.5 - *glares at Sevion* eGUI improvment //
// 6.55 - Fixed extra space on 5.7 //
// 6.6 - Added in StartEx for location use and eGUI //
//==============================================================================//
//==============================================================================//
// ~<||§||Credits||§||>~ //
// Uberplayer //
// Flare //
// emjlr3 //
// Themis //
// Dusk //
// --Artificial-- //
// Gwypaas //
// Romek //
// Sevion //
//==============================================================================//
library SUPOT initializer Init
struct supot
integer sid = 0
integer num = 0
player p = null
real x
real y
real interval = 0
real ticker = 0
boolean paused = false
method onDestroy takes nothing returns nothing
set .interval = 0
set .x = 0
set .y = 0
set .p = null
set .num = 0
set .sid = 0
endmethod
endstruct
globals
private constant real TIMER_INT = 0.25
private integer N = 0
private timer T = CreateTimer()
private group array Last
public supot array spawn
private real MINX
private real MAXX
private real MINY
private real MAXY
integer bj_LastCreatedInstance
endglobals
function GetLastSpawned takes integer instance returns group
if Last[instance] != null then
return Last[instance]
endif
debug call BJDebugMsg(I2S(instance) + " has no units running on that instance.")
return null
endfunction
private function DoSpawn takes nothing returns nothing
local supot a
local unit u
local integer i = N
local integer j = 0
loop
exitwhen i == 0
set a = spawn<i>
if a == 0 then
else
if not a.paused == true then
set a.ticker = a.ticker + TIMER_INT
if a.ticker >= a.interval then
set a.ticker = a.ticker - a.interval
call GroupClear(Last<i>)
loop
exitwhen j == a.num
set u = CreateUnit(a.p, a.sid, a.x, a.y, bj_UNIT_FACING)
call GroupAddUnit(Last<i>,u)
debug call BJDebugMsg("Unit has been created!")
set u = null
set j = j + 1
endloop
set j = 0
endif
endif
if a.num == 0 and a.interval != 0 then
call a.destroy()
call DestroyGroup(Last<i>)
endif
endif
set i = i - 1
endloop
set u = null
set j = 0
endfunction
public function Stop takes integer instance returns nothing
set supot(instance).num = 0
debug call BJDebugMsg("The instance number " + I2S(instance) + " of SUPOT has been stopped!")
endfunction
public function Pause takes integer instance returns nothing
set supot(instance).paused = true
endfunction
public function UnPause takes integer instance returns nothing
set supot(instance).paused = false
endfunction
public function ChangeUnitID takes integer instance, integer newUnitID returns nothing
if newUnitID == 0 then
debug call BJDebugMsg("No Spawn ID!")
return
endif
set supot(instance).sid = newUnitID
debug call BJDebugMsg("A different unit is now being spawned for SUPOT instance number " + I2S(instance))
endfunction
public function ChangeSpawnTime takes integer instance, real newSpawnTime returns nothing
if newSpawnTime <= 0 then
debug call BJDebugMsg("Invalid Spawn Interval!")
return
endif
set supot(instance).interval = newSpawnTime
debug call BJDebugMsg("Spawn time has been changed for SUPOT instance number " + I2S(instance))
endfunction
public function ChangePlayer takes integer instance, player newPlayer returns nothing
if newPlayer == null then
debug call BJDebugMsg("Player Not Found!")
return
endif
set supot(instance).p = newPlayer
debug call BJDebugMsg("Units are now being spawned for a different player under SUPOT instance number " + I2S(instance))
endfunction
public function ChangeSpawnAmount takes integer instance, integer newNumber returns nothing
if newNumber <= 0 then
debug call BJDebugMsg("Incorrect spawn number specified!")
return
endif
set supot(instance).num = newNumber
debug call BJDebugMsg("A different number of units are being spawned for SUPOT instance number " + I2S(instance))
endfunction
public function ChangeLocation takes integer instance, real newX, real newY returns nothing
if newX > MAXX or newX < MINX then
debug call BJDebugMsg("Impossible Spawn Location X Given!")
return
elseif newY > MAXY or newY < MINY then
debug call BJDebugMsg("Unusable Spawn Location Y Given!")
return
endif
set supot(instance).x = newX
set supot(instance).y = newY
debug call BJDebugMsg("The spawn location has been changed for SUPOT instance number " + I2S(instance))
endfunction
public function GetLastInstance takes nothing returns integer
return bj_LastCreatedInstance
//For eGUI users, so they can modify the function.
endfunction
public function Start takes player p, integer uid, integer number, real interval, real x, real y returns integer
local supot a
if uid == 0 then
debug call BJDebugMsg("No Spawn ID!")
return 0
elseif number <= 0 then
debug call BJDebugMsg("Invalid Spawn Amount Specified!")
return 0
elseif interval <= 0 then
debug call BJDebugMsg("Invalid Spawn Time Interval Recieved!")
return 0
elseif x > MAXX or x < MINX then
debug call BJDebugMsg("Impossible Spawn Location X Given!")
return 0
elseif y > MAXY or y < MINY then
debug call BJDebugMsg("Unusable Spawn Location Y Given!")
return 0
elseif p == null then
debug call BJDebugMsg("Spawn Player Not Found!")
return 0
endif
set a = supot.create()
set a.sid = uid
set a.p = p
set a.num = number
set a.interval = interval
set a.x = x
set a.y = y
debug call BJDebugMsg(R2S(MINX) + R2S(MAXX) + R2S(MINY) + R2S(MAXY))
if N == 0 then
call TimerStart(T, TIMER_INT, true, function DoSpawn)
endif
set N = N + 1
debug call BJDebugMsg("A spawn has started under instance id "+I2S(N)+"!")
if spawn[N].num != 0 then
set N = 1
loop
exitwhen spawn[N].num == 0
set N = N+1
endloop
endif
set spawn[N] = a
if Last[N] == null then
set Last[N] = CreateGroup()
endif
set bj_LastCreatedInstance = integer(a)
return integer(a)
endfunction
public function StartEx takes player p, integer uid, integer number, real interval, location l returns integer
return Start(p,uid,number,interval,GetLocationX(l),GetLocationY(l))
endfunction
private function Init takes nothing returns nothing
//Damned bj_mapInitialPlayableArea...
set MINX = GetRectMinX(bj_mapInitialPlayableArea)
set MAXX = GetRectMaxX(bj_mapInitialPlayableArea)
set MINY = GetRectMinY(bj_mapInitialPlayableArea)
set MAXY = GetRectMaxY(bj_mapInitialPlayableArea)
endfunction
endlibrary</i></i></i></i>