here is the new code:
Code: Select all
function gadget:GetInfo()
return {
name = "bla",
desc = "blabla",
author = "blablabla",
date = "bla",
license = "bla",
layer = 0,
enabled = true
}
end
local CMD_MOVETO=30002
if (gadgetHandler:IsSyncedCode()) then
--SYNCED
local metalplat={}
local movetoCmd={
name="moveto",
tooltip="movesunitto",
action="move",
id=CMD_MOVETO,
type=CMDTYPE.ICON , --CMDTYPE.ICON_MAP,
cursor="Move",
}
function gadget:AllowCommand(u, ud, team, cmd, param, opt)
if cmd == CMD_MOVETO then
Spring.GiveOrderToUnit(u,CMD.MOVE,metalplat[1].pos,0);
--return false
end
return true
end
function gadget:UnitCreated(u, ud, team)
if UnitDefs[ud].customParams.canharvest=="1" then
Spring.Echo("harvestunit created");
Spring.GiveOrderToUnit(u,CMD.INSERT,{-1,CMD_MOVETO},{"alt"});
--Spring.GiveOrderToUnit(u,ud,team,CMD_MOVETO,0);
end
end
function gadget:UnitFinished(u,ud,team)
if ud == RUSK31 then
Spring.Echo("harvestunit finished");
Spring.GiveOrderToUnit(u,CMD.MOVETO);
end
end
function gadget.Initialize()
local i = 1
for _,a in ipairs(Spring.GetAllFeatures()) do
if Spring.GetFeatureDefID(a) == metal then
local x,y,z=Spring.GetFeaturePosition(a)
metalplat[i]={pos={x,y,z}}
i=i+1
end
end
if i==1 then
Spring.Echo("removed")
gadgetHandler:RemoveGadget()
end
end
else
--UNSYNCED
end