UnitSpawnerGadget
Posted: 19 Sep 2013, 15:19
Would be more efficient if there was a way for the gadget only to be called upon table change.. but meh..
Post Scriptum: Working Gadget now. Thanks go to JK
This allows for unit to be spawned (with slight delay) from any function in unitscript..
Code: Select all
function gadget:GetInfo()
return {
name = "UnitSpawner",
desc = "Works around",
author = "jk",
date = "3rd of May 2010",
license = "Free",
layer = 0,
version = 1,
enabled = true
}
end
--GG.UnitsToSpawn:PushCreateUnit(name,x,y,z,dir,teamID)
if (not gadgetHandler:IsSyncedCode()) then
return
end
local function PushCreateUnit(self, ...)
self[#self+1] = {...}
end
if GG.UnitsToSpawn== nil then GG.UnitsToSpawn = { PushCreateUnit = PushCreateUnit } end
function gadget:GameFrame(frame)
if (frame % 10 == 0) and GG.UnitsToSpawn and GG.UnitsToSpawn[1] then
local cur = GG.UnitsToSpawn
GG.UnitsToSpawn = { PushCreateUnit = PushCreateUnit }
for i=1,#cur,1 do
Spring.CreateUnit(unpack(cur[i]))
end
end
end
This allows for unit to be spawned (with slight delay) from any function in unitscript..