Anyway, here's my code so far, I really would like some help on figuring out how to do the CommandCheck() function:
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: cmd_ferry.lua
-- brief: Adds a command to create a ferry point with a transport.
-- author: Brian "Mastastealth" Franco.
--
-- Copyright (C) 2007.
-- Licensed under the terms of the Creative Commons Attribution-Noncommercial 2.5 Colombia License.
-- In other words, do what you want and give me credit please. :P
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "Ferry",
desc = "Adds '/luaui ferry' to create a ferry point with a transport",
author = "mastastealth",
date = "Jun 16, 2008",
license = "Creative Commons",
layer = 0,
enabled = false -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:Initialize()
widgetHandler:AddAction("ferry", FerryUnits)
end
function CommandCheck()
local transport = Spring.GetSelectedUnits()
transport = transport[1]
transportcommands = Spring.GetUnitCommands(transport)
local SpeedX,SpeedY,SpeedZ = Spring.GetUnitVelocity(transport)
while table.getn(transportcommands) < 1 and SpeedX > 0 or SpeedY > 0 or SpeedZ > 0 do
return true
end
return true
end
function FerryUnits()
local transport = Spring.GetSelectedUnits()
transport = transport[1]
local CurrentX, CurrentY, CurrentZ = Spring.GetUnitPosition(transport)
Spring.GiveOrderToUnit(transport,
CMD.WAIT,{},{}
);
Spring.Echo("Set Unload Point. Use Shift to create waypoints, then hit W when you're done.");
CommandCheck();
--THE FOLLOWING WILL BE REPLACED to insert a repeat and load
--at the start of the command queue, replace the final move command
--to an Unload Command, and add a move back to loading point
--at the end!!
-- Spring.GiveOrderArrayToUnitArray(Spring.GetSelectedUnits(),
-- { --Start Command List
-- { --Let's repeat the following...
-- CMD.INSERT,{-1,CMD.REPEAT,CMD.OPT_SHIFT,1},{"alt"}
-- },
-- { --Load 'em up!
-- CMD.INSERT,{-1,CMD.LOAD_UNITS,CMD.OPT_SHIFT,CurrentX,CurrentY,CurrentZ,200},{"alt"}
-- },
-- { --Unload
-- CMD.INSERT,{-1,CMD.UNLOAD_UNIT,CMD.OPT_SHIFT,CurrentX+800,CurrentY+100,CurrentZ+800},{"alt"}
-- },
-- { --Move back to loading area
-- CMD.INSERT,{-1,CMD.MOVE,CMD.OPT_SHIFT,CurrentX,CurrentY,CurrentZ},{"alt"}
-- },
-- }
-- );
return true
end