so far I am failry certain that I understand almost nothing of what is envolved in praforming this process
but I have been looking at unit_mex_upgrade as a refrance and trying to make my own random button with what I see there
the following script is what I have created so far
Code: Select all
function gadget:GetInfo()
return {
name = "CUTests",
desc = "Gadget testing ground (only tests run here will do real scripts from what I learn here)",
author = "zwzsg (and then horribly ruined by Voidranaut)",
date = "not sure",
version = "1.0",
license = "Public Domain",
layer = 0,
enabled = true
}
end
local echo = Spring.Echo
local message_identifier = gadget:GetInfo().name..": "
local once = 1
local height = 0
local increase = 0
local x1 = 7510
local z1 = 2600
local x2 = 7010
local z2 = 2800
local FindUnitCmdDesc = Spring.FindUnitCmdDesc
local CMD_UPGRADEMEX = 38274
local Happy = {
id = CMD_HAPPY,
type = CMDTYPE.ICON_UNIT_OR_AREA,
name = 'Happy',
cursor = 'Attack',
action = 'upgrademex',
tooltip = 'Hammberger time',
hidden = false,
params = {}
}
if (gadgetHandler:IsSyncedCode()) then--SYNCED
function gadget:Initialize()
for _,u in ipairs(Spring.GetAllUnits()) do
local insertID =
FindUnitCmdDesc(u, CMD.CLOAK) or
FindUnitCmdDesc(u, CMD.ONOFF) or
FindUnitCmdDesc(u, CMD.TRAJECTORY) or
FindUnitCmdDesc(u, CMD.REPEAT) or
FindUnitCmdDesc(u, CMD.MOVE_STATE) or
FindUnitCmdDesc(u, CMD.FIRE_STATE) or
123456 -- back of the pack
local defID = Spring.GetUnitDefID(u)
local def = UnitDefs[ defID ]["metalCost"]
if( defID == 367 ) then
Spring.InsertUnitCmdDesc( u, insertID + 3, Happy)
end
end
end
else--UNSYNCED (its just ehre at the moment not realy beaing used)
function gadget:KeyPress(key) --key scope exists within the function
if( key == 121 ) then
for _,u in ipairs(Spring.GetAllUnits()) do
Spring.SendLuaRulesMsg(message_identifier..u.." was pressed")
Spring.Echo( u )
end
end
Spring.Echo("Key "..key.." pressed in unsynced")
Spring.SendLuaRulesMsg(message_identifier..key.." was pressed")
end
end
Question: am I missing something basic that is part of this process? or completely misinterpriting the function of the commands I am trying to use to insert the command?
any info would be helpful
thank you for your time
EDIT!!!!!***
ok sorry for this
I changed my inicializing code to this
Code: Select all
function gadget:GameFrame(n)
echo( n )
if( n == 200) then
for _,u in ipairs(Spring.GetAllUnits()) do
local insertID =
FindUnitCmdDesc(u, CMD.CLOAK) or
FindUnitCmdDesc(u, CMD.ONOFF) or
FindUnitCmdDesc(u, CMD.TRAJECTORY) or
FindUnitCmdDesc(u, CMD.REPEAT) or
FindUnitCmdDesc(u, CMD.MOVE_STATE) or
FindUnitCmdDesc(u, CMD.FIRE_STATE) or
123456 -- back of the pack
echo( insertID )
local defID = Spring.GetUnitDefID(u)
local def = UnitDefs[ defID ]["metalCost"]
if( defID == 367 ) then
Spring.InsertUnitCmdDesc( u, insertID + 3, Happy)
end
end
end
end
but that leave me with a new question
Question: can buttons only be added if they are in game frame?