library DummyRecycler requires TimerUtils
//
//
//
// *Dummyrecycler v1.1b*
// by baassee
//
// *Requirments*
//
// TimerUtils by Vexorian
//
// *Credits*
//
// To Vexorian for TimerUtils
//1 watermelon_1234 for helping me alot with this!
//
// *Changelog*
//
// v1.0 Release
//
// v1.1 -Fixed debug infront of debug messages.
// -Added a check to check
// if the user have boundsentinel or not, if not, the system will
// create it's own kinda boundsentinel.
// -Added two more functions which are provided to help the GUI
// users even more. One is normal newdummy but takes location loc
// and the second is the same but with auto recycling.
//
// v1.1b -Now the recycle struct is private. Special thanks goes to watermelon_1234
// for helping me with this.
//
// *Standard information*
//
// This is just a standard dummy recycler with a limit of 8191 dummies.
// Always remember to recycle the dummies after you used them and
// NOT apply timed life to them or kill/remove them. Then the recycler
// will just continue to create units and that is not what this library
// is created for. It uses TimerUtils for a few functions, the auto
// recycling functions. All dummies are created for a player and not
// for player(15). If you want to do that, use NewDummy function and set
// the player to player(15).
//
// Please give proper credit to me for this library and vexorian for
// TimerUtils. Do not distrubate this to other maps without permission.
//
// *Functions provided by this library*
//
// function NewDummy takes player owner, real x, real y returns unit
// gets a new dummy from the system for owner, spawned at coord (x,y)
//
// function RecycleDummy takes unit u returns nothing
// recycles dummy u and moves it to STORAGE(X,Y) if MOVE == true
// Warning, you can't recycle units that isn't the dummy unittype
//
// function NewDummyEx takes unit caster returns unit
// gets a dummy created at the position of the triggering unit
//
// function NewDummyLoc takes player owner, location loc returns unit
// just like NewDummy but this takes a loc, easier for GUI users
// who don't want the dummy to be created at the casters coordinates
//
// function NewDummyAuto takes player owner, real x, real y, real time returns unit
// just like NewDummy function but this auto recycles the dummy after set time
//
// function NewDummyExAuto takes unit caster, real time returns unit
// just like NewDummyAuto but this is made from the NewDummyEx function.
//
// function NewDummyLocAuto takes player owner, location loc, real time returns unit
// just like NewDummyLoc but this have the auto recycle function
//
//
//
// *Exmaples*
//
// These below are just JASS examples, check the example category if you
// are a GUI user :D
//
//
// local unit u = NewDummy(Player(15), 0., 0.)
// call RecycleDummy(u)
// Creates a dummy for player(15) at coordinates (0,0)
//
// local unit u = NewDummyEx(GetTriggerUnit())
// call RecycleDummy(u)
// Creates a dummy for the owner of GetTriggerUnit() and on the same spot
//
// local real x = GetUnitX(GetTriggerUnit())
// local real y = GetUnitY(GetTriggerUnit())
// local unit u = NewDummyAuto(GetOwningPlayer(GetTriggerUnit()), x, y, 1.)
// Creates a dummy for the owner of GetTriggerUnit() and recycles it after 1 second.
//
// local unit u = NewDummyExAuto(GetTriggerUnit(), 5.)
// Creates a dumym for the owner of GetTriggerUnit() and recycles after 5 seconds.
//
// *How to import*
//
// Copy the dummy unit to your map or make your own dummy unit, preffered with
// a dummy model such as the xe dummy or others. Make sure the dummy have locust.
//
// If you don't have timerutils then copy the whole category to your map else
// you can just copy this trigger.
//
// Set up stuff as you want to such as store coordinates and remember to set the
// dummy rawcode.
//
// Credit baassee and you are good to go!
//
//
//
// *SETUP PART*
globals
//
// The counter variable, don't touch.
//
private integer N = 0
//
// The Rawcode of the dummy that will be used by this system.
// To get rawcodes, select the dummy inside the object editor
// and press ctrl + d and the raw code will show up instead
// of the name.
//
private constant integer RAWCODE = 'h006'
//
// A boolean to check if the dummies should be moved to the
// storage spot or just remain where they are.
//
private constant boolean MOVE = true
//
// If the boolean above is true, enter the x coordinate
// here.
//
private constant real STOREX = 0.
//
// If the boolean MOVE is true, enter the y
// coordinate here.
//
private constant real STOREY = 0.
//
// Dummy global that will be used. Don't touch.
//
private unit array DUMMY
//
// The setup continues below, just read the comments.
//
endglobals
//
// Here it checks if you have the library BoundSentinel,
// if you have, you won't need this protect stuff.
//
static if not LIBRARY_BoundSentinel then
globals
//
// Sets the reals of the map. You can change
// the region if you want to, but it shouldn't be
// necessary as you set the storage coordinates
// by yourself
//
private constant real MINX = GetRectMinX(bj_mapInitialPlayableArea)
private constant real MAXX = GetRectMaxX(bj_mapInitialPlayableArea)
private constant real MINY = GetRectMinY(bj_mapInitialPlayableArea)
private constant real MAXY = GetRectMaxY(bj_mapInitialPlayableArea)
endglobals
endif
//
// *END OF SETUP*
//
//
// *Recycle function below*
//
function RecycleDummy takes unit u returns nothing
// just to check the limit, I dont think someone that use this proper
// will reach this but to protect the users from themselves.
if N != 8191 then
if u != null and GetUnitTypeId(u) == RAWCODE then
// here I set the color to false cause it's not needed
// as they wont be used by any player until called again.
call SetUnitOwner(u, Player(15), false)
call PauseUnit(u, true)
set N = N + 1
set DUMMY[N] = u
if MOVE == true then
// checks for boundsentinel so I don't have to do my own check
// because I'll know it will be safe with boundsentinel
static if LIBRARY_BoundSentinel then
// moves units if you have boundsentinel
call SetUnitX(u, STOREX)
call SetUnitY(u, STOREY)
else // if you dont have boundsentinel, we do our own check
if (MINX <= STOREX) and (STOREX <= MAXX) and (MINY <= STOREY) and (STOREY <= MAXY) then
call SetUnitX(u, STOREX)
call SetUnitY(u, STOREY)
else
// announcing that the user have made it wrong and have to re-do it.
debug call BJDebugMsg("DUMMYRECYCLER - The map doesn't contain the coordinates you've set, please change them.")
endif
endif
endif
else
// just a debug message to show the user what he did wrong with recycling.
debug call BJDebugMsg("DUMMYRECYCLER - Tried to recycle a nulled unit or a not-dummy type unit.")
endif
else
// a announce that a user have used way to many dummies.
debug call BJDebugMsg("DUMMYRECYCLER - You've reached the max number of dummies, please use dummies properly.")
// doing as vexorian does, explode the unit
call ExplodeUnitBJ(u)
endif
endfunction
//
// A normal struct with timers that is used for the autorecycle functions.
// NOW a private struct, will look weird having it between the functions but it will
// only work that way. Special thanks to watermelon_1234 for helping me with this.
//
private struct recycler
unit u
static method start takes unit u, real time returns thistype
local thistype this = thistype.allocate()
local timer t = NewTimer()
set .u = u
call SetTimerData(t, this)
call TimerStart(t, time, false, function thistype.recycle)
return this
endmethod
static method recycle takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
call RecycleDummy(.u)
call ReleaseTimer(GetExpiredTimer())
call .destroy()
endmethod
endstruct
//
// The rest of the functions!
//
function NewDummy takes player owner, real x, real y returns unit
if N == 0 then
return CreateUnit(owner, RAWCODE, x, y, 0.)
endif
call PauseUnit(DUMMY[N], false)
// yeah I don't know why I set the color to true but someone might use it.
call SetUnitOwner(DUMMY[N], owner, true)
call SetUnitX(DUMMY[N], x)
call SetUnitY(DUMMY[N], y)
set N = N - 1
return DUMMY[N + 1]
endfunction
function NewDummyEx takes unit caster returns unit
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
if N == 0 then
return CreateUnit(GetOwningPlayer(caster), RAWCODE, x, y, 0.)
endif
call PauseUnit(DUMMY[N], false)
// yeah I don't know why I set the color to true but someone might use it.
call SetUnitOwner(DUMMY[N], GetOwningPlayer(caster), true)
call SetUnitX(DUMMY[N], x)
call SetUnitY(DUMMY[N], y)
set N = N - 1
return DUMMY[N + 1]
endfunction
function NewDummyLoc takes player owner, location loc returns unit
local real x = GetLocationX(loc)
local real y = GetLocationY(loc)
if N == 0 then
return CreateUnit(owner, RAWCODE, x, y, 0.)
endif
call PauseUnit(DUMMY[N], false)
call SetUnitOwner(DUMMY[N], owner, true)
call SetUnitX(DUMMY[N], x)
call SetUnitY(DUMMY[N], y)
set N = N - 1
return DUMMY[N + 1]
endfunction
function NewDummyAuto takes player owner, real x, real y, real time returns unit
local unit u
if N == 0 then
set u = CreateUnit(owner, RAWCODE, x, y, 0.)
call recycler.start(u, time)
return u
endif
call PauseUnit(DUMMY[N], false)
// yeah I don't know why I set the color to true but someone might use it.
call SetUnitOwner(DUMMY[N], owner, true)
call recycler.start(DUMMY[N], time)
call SetUnitX(DUMMY[N], x)
call SetUnitY(DUMMY[N], y)
set N = N - 1
return DUMMY[N + 1]
endfunction
function NewDummyExAuto takes unit caster, real time returns unit
local unit u
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
if N == 0 then
set u = CreateUnit(GetOwningPlayer(caster), RAWCODE, x, y, 0.)
call recycler.start(u, time)
return u
endif
call PauseUnit(DUMMY[N], false)
// yeah I don't know why I set the color to true but someone might use it.
call SetUnitOwner(DUMMY[N], GetOwningPlayer(caster), true)
call recycler.start(DUMMY[N], time)
call SetUnitX(DUMMY[N], x)
call SetUnitY(DUMMY[N], y)
set N = N - 1
return DUMMY[N + 1]
endfunction
function NewDummyLocAuto takes player owner, location loc, real time returns unit
local unit u
local real x = GetLocationX(loc)
local real y = GetLocationY(loc)
if N == 0 then
set u = CreateUnit(owner, RAWCODE, x, y, 0.)
call recycler.start(u, time)
return u
endif
call PauseUnit(DUMMY[N], false)
call SetUnitOwner(DUMMY[N], owner, true)
call recycler.start(DUMMY[N], time)
call SetUnitX(DUMMY[N], x)
call SetUnitY(DUMMY[N], y)
set N = N - 1
return DUMMY[N + 1]
endfunction
endlibrary