Anybody ever used it?
I'm trying to use CMD.TIMEWAIT (to build some missions) but it's like it does nothing.
CMD.TIMEWAIT
Moderator: Moderators
Re: CMD.TIMEWAIT
Ok, it appears it works when I issue the command directly.
However, what I'm trying to do, is to read and set CMD.TIMEWAIT in Lua, and it's there that I am having some issues.
It seems the CMD.TIMEWAIT I issue are transformed into simple CMD.WAIT with parameters={0 , 3.5873240686715e-043} and with coded set to 32.
And when I issue CMD.TIMEWAIT command with Lua, they appear to be ignored.
However, what I'm trying to do, is to read and set CMD.TIMEWAIT in Lua, and it's there that I am having some issues.
It seems the CMD.TIMEWAIT I issue are transformed into simple CMD.WAIT with parameters={0 , 3.5873240686715e-043} and with coded set to 32.
And when I issue CMD.TIMEWAIT command with Lua, they appear to be ignored.
Last edited by zwzsg on 04 Aug 2009, 20:34, edited 1 time in total.
Re: CMD.TIMEWAIT
Not entirely sure, but I recall something about TIMEWAIT / GATHERWAIT / DEATHWAIT being unsynced.
In other words, they would only work in LuaUI and not in a gadget, because their functionality is actually implemented in the UI side of Spring. (similar to the ctrl+move formation move, this also doesn't work from a gadget; I had to replicate the functionality in Lua to use it in my AI.)
So, are you trying to use it from LuaUI or from LuaRules / LuaGaia?
In other words, they would only work in LuaUI and not in a gadget, because their functionality is actually implemented in the UI side of Spring. (similar to the ctrl+move formation move, this also doesn't work from a gadget; I had to replicate the functionality in Lua to use it in my AI.)
So, are you trying to use it from LuaUI or from LuaRules / LuaGaia?
Re: CMD.TIMEWAIT
LuaRules. So I have to make my synced gadget to ask the unsynced part to issue that command? That's gonna be tricky since I'm trying to restore the whole queue at once.
Last edited by zwzsg on 04 Aug 2009, 20:37, edited 1 time in total.
Re: CMD.TIMEWAIT
Then that explains it.
Re: CMD.TIMEWAIT
Thanks Tobi. I would never have guessed CMD.TIMEWAIT is unsynced and CMD.WAIT is synced.
I recoded TimeWait as a custom command, and now it works.
I recoded TimeWait as a custom command, and now it works.
Code: Select all
function gadget:GetInfo()
return {
name = "Pseudo Orders",
desc = "Transfer, synced TimeWait, ..",
author = "zwzsg",
date = "August, 4th, 2009",
license = "Public domain",
layer = 17,
enabled = true
}
end
VFS.Include("LuaRules/Gadgets/new_cmd_id.lua",nil)
--[[
-- Looks like I didn't need those after all
local TmWtDscrptn = {
name="Time Wait",
type=CMDTYPE.NUMBER,
tooltip="Wait a given amoutn of seconds",
id=CMD_TIMEWAIT,
action="timewait",
cursor="wait", -- not sure
}
local TrnsfrDscrptn = {
name="Transfer",
type=CMDTYPE.NUMBER,
tooltip="Give unit to a team",
id=CMD_TRANSFER,
action="transfer",
cursor="Unload units",
}
]]--
if (gadgetHandler:IsSyncedCode()) then
--SYNCED
local WaitTimers={}
local Transfers={}
local Orders={}
function gadget:CommandFallback(u,ud,team,cmd,params,options,tag)
if cmd == CMD_TIMEWAIT then
if #params==1 and type(params[1])=="number" then
table.insert(WaitTimers,{Unit=u,Duration=params[1],EndAt=Spring.GetGameSeconds()+params[1]})
table.insert(Orders,{Unit=u,cmd=CMD.WAIT,params={},options={}})
else
Spring.Echo("Bad parameters to CMD_TIMEWAIT")
end
end
if cmd == CMD_TRANSFER then
if #params==1 and type(params[1])=="number" then
if Spring.GetTeamInfo(params[1]) then
table.insert(Transfers,{SourceUnit=u,DestinationTeam=params[1]})
else
Spring.Echo("Bad TeamID to CMD_TRANSFER")
end
else
Spring.Echo("Bad parameters to CMD_TRANSFER")
end
end
end
function gadget:GameFrame(f)
local gs=Spring.GetGameSeconds()
for ti=#WaitTimers,1,-1 do
if gs>WaitTimers[ti].EndAt then
Spring.GiveOrderToUnit(WaitTimers[ti].Unit,CMD.WAIT,{},{})
table.remove(WaitTimers,ti)
end
end
for _,o in ipairs(Orders) do
Spring.GiveOrderToUnit(o.Unit,o.cmd,o.params,o.options)
end
Orders={}
for _,trnsfr in ipairs(Transfers) do
Spring.TransferUnit(trnsfr.SourceUnit,trnsfr.DestinationTeam)
end
Transfers={}
end
function gadget:UnitDestroyed(u,ud,team)
for ti=#WaitTimers,1,-1 do
if u==WaitTimers[ti].Unit then
table.remove(WaitTimers,ti)
end
end
for ti=#Transfers,1,-1 do
if u==Transfers[ti].SourceUnit then
table.remove(Transfers,ti)
end
end
for oi=#Orders,1,-1 do
if u==Orders[oi].Unit then
table.remove(Orders,oi)
end
end
end
else
--UNSYNCED
--[[
-- Doesn't appear to be working
function gadget:Initialize()
Spring.SetCustomCommandDrawData(CMD_TIMEWAIT,"Time wait", {.5,.5,1,1})
Spring.SetCustomCommandDrawData(CMD_TRANSFER,"Resurrect", {.5,.5,1,1})
end
]]--
end
Re: CMD.TIMEWAIT
I was doing it bad, better:
Anybody knows how to get the little clock that is normally used for CMD.TIMEWAIT to show as icon in the queue?
Code: Select all
function gadget:GetInfo()
return {
name = "Pseudo Orders",
desc = "Transfer, synced TimeWait, queuable Repeat, ...",
author = "zwzsg",
date = "August, 4th, 2009",
license = "Public domain",
layer = 17,
enabled = true
}
end
VFS.Include("LuaRules/Gadgets/new_cmd_id.lua",nil)
--[[
-- Looks like I didn't need those after all
local TmWtDscrptn = {
name="Time Wait",
type=CMDTYPE.NUMBER,
tooltip="Wait a given amoutn of seconds",
id=CMD_TIMEWAIT,
action="timewait",
cursor="wait", -- not sure
}
local TrnsfrDscrptn = {
name="Transfer",
type=CMDTYPE.NUMBER,
tooltip="Give unit to a team",
id=CMD_TRANSFER,
action="transfer",
cursor="Unload units",
}
]]--
if (gadgetHandler:IsSyncedCode()) then
--SYNCED
local WaitTimers={}
local Transfers={}
local Orders={}
function gadget:CommandFallback(u,ud,team,cmd,params,options,tag) -- returns: Used, Finished
if cmd == CMD_TIMEWAIT then
if #params==1 and type(params[1])=="number" then
local gs=Spring.GetGameSeconds()
for wti,wt in ipairs(WaitTimers) do
if wt.unit==u and wt.tag==tag then
if gs>wt.ending then
table.remove(WaitTimers,wti)
return true,true
else
return true,false
end
end
end
table.insert(WaitTimers,{unit=u,duration=params[1],ending=gs+params[1],tag=tag})
return true,false
else
Spring.Echo("Bad parameters to CMD_TIMEWAIT")
end
end
if cmd == CMD_TRANSFER then
if #params==1 and type(params[1])=="number" then
if Spring.GetTeamInfo(params[1]) then
table.insert(Transfers,{SourceUnit=u,DestinationTeam=params[1]})
return true,(Spring.GetUnitTeam(u)==params[1])
else
Spring.Echo("Bad TeamID to CMD_TRANSFER")
end
else
Spring.Echo("Bad parameters to CMD_TRANSFER")
end
end
if cmd == CMD_REPEAT then
if #params==0 then
if Spring.GetUnitStates(u)["repeat"] then
return true, true
else
table.insert(Orders,{unit=u,cmd=CMD.REPEAT,params={1},options={}})
return true,false
end
else
Spring.Echo("Bad parameters to CMD_REPEAT")
end
end
end
function gadget:GameFrame(f)
for _,o in ipairs(Orders) do
Spring.GiveOrderToUnit(o.unit,o.cmd,o.params,o.options)
end
Orders={}
for _,trnsfr in ipairs(Transfers) do
Spring.TransferUnit(trnsfr.SourceUnit,trnsfr.DestinationTeam)
end
Transfers={}
end
function gadget:UnitDestroyed(u,ud,team)
for ti=#WaitTimers,1,-1 do
if u==WaitTimers[ti].unit then
table.remove(WaitTimers,ti)
end
end
for ti=#Transfers,1,-1 do
if u==Transfers[ti].SourceUnit then
table.remove(Transfers,ti)
end
end
for oi=#Orders,1,-1 do
if u==Orders[oi].unit then
table.remove(Orders,oi)
end
end
end
else
--UNSYNCED
--[[
-- Doesn't appear to be working
function gadget:Initialize()
Spring.SetCustomCommandDrawData(CMD_TIMEWAIT,"Wait", {.5,.5,1,1})
Spring.SetCustomCommandDrawData(CMD_TRANSFER,"Resurrect", {.5,.5,1,1})
end
]]--
end