Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gadget:GetInfo()
- return {
- name = "Buttons",
- desc = "Sets icons for buttons",
- author = "Smoth",
- date = "july, 2009",
- license = "public domain",
- layer = -5,
- enabled = true -- loaded by default?
- }
- end
- if (gadgetHandler:IsSyncedCode()) then
- local cmdbuttonDefs = {}
- local cmdID
- if VFS.FileExists("LuaRules/Configs/cmdbuttons.lua") then
- cmdbuttonDefs = VFS.Include("LuaRules/Configs/cmdbuttons.lua")
- else
- error("missing file: LuaRules/Configs/cmdbuttons.lua")
- end
- function somethingelse(u, ud, team)
- for CMDBTN,CMDBTNID in pairs(cmdbuttonDefs) do
- cmdID = Spring.FindUnitCmdDesc(u, CMD[CMDBTN] )
- if ( cmdID and cmdbuttonDefs[CMDBTN].texture ) then
- Spring.EditUnitCmdDesc(u, cmdID, {onlyTexture=cmdbuttonDefs[CMDBTN].onlyTexture or false, texture = cmdbuttonDefs[CMDBTN].texture,} )
- end
- if ( cmdID and CMDBTN == "MOVE_STATE" ) then
- --Spring.Echo("movestate",Spring.GetUnitStates(u)["movestate"])
- if ( Spring.GetUnitStates(u)["movestate"] == 1 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_maneuver.png", } )
- elseif ( Spring.GetUnitStates(u)["movestate"] == 2) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_roam.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_holdposition.png",} )
- end
- end -- end move state handler
- if ( cmdID and CMDBTN == "FIRE_STATE" ) then
- --Spring.Echo("firestate",Spring.GetUnitStates(u)["firestate"])
- if ( Spring.GetUnitStates(u)["firestate"] == 1 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_returnfire.png", } )
- elseif ( Spring.GetUnitStates(u)["firestate"] == 2) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_fireatwill.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_holdfire.png",} )
- end
- end -- end fire state handler
- if ( cmdID and CMDBTN == "AUTOREPAIRLEVEL" ) then
- if ( Spring.GetUnitStates(u)["autorepairlevel"] == 0 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage0.png", } )
- elseif ( Spring.GetUnitStates(u)["autorepairlevel"] == 0.30000001192093) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage30.png", } )
- elseif ( Spring.GetUnitStates(u)["autorepairlevel"] == 0.5) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage50.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage80.png",} )
- end
- end
- if ( cmdID and CMDBTN == "TRAJECTORY" ) then
- --Spring.Echo("trajectory",Spring.GetUnitStates(u)["trajectory"])
- if ( Spring.GetUnitStates(u)["trajectory"] == 1 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/high_trajectory.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/low_trajectory.png", } )
- end
- end -- end fire state handler
- if ( cmdID and CMDBTN == "DGUN" and ud == UnitDefNames.juagg.id ) then
- Spring.EditUnitCmdDesc(u, cmdID, {name="Barrage", tooltip="FIRE ALL GUNS", texture="bitmaps/ui/abilities/barrage.png",} )
- end
- end
- end -- end unit finished
- function gadget:AllowCommand(u, ud, team, cmd, param, opts)
- if cmd == CMD.REPEAT then
- cmdID = Spring.FindUnitCmdDesc(u, CMD.REPEAT )
- if (cmdID ) then
- if ( Spring.GetUnitStates(u)["repeat"] == true ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_repeatoff.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_repeaton.png",} )
- end
- end
- return CMD.REPEAT
- end -- end repeat handler
- if cmd == CMD.ONOFF then
- cmdID = Spring.FindUnitCmdDesc(u, CMD.ONOFF )
- if (cmdID ) then
- if Spring.GetUnitStates(u)["active"] == true then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_off.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_on.png",} )
- end
- end
- return CMD.ONOFF
- end -- end on/off handler
- if cmd == CMD.MOVE_STATE then
- cmdID = Spring.FindUnitCmdDesc(u, CMD.MOVE_STATE )
- if (cmdID ) then
- if ( param[1] == 1 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_maneuver.png", } )
- elseif ( param[1] == 2) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_roam.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_holdposition.png",} )
- end
- end
- return CMD.MOVE_STATE
- end -- end move state handler
- if cmd == CMD.FIRE_STATE then
- cmdID = Spring.FindUnitCmdDesc(u, CMD.FIRE_STATE )
- if (cmdID ) then
- if ( param[1] == 1 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_returnfire.png", } )
- elseif ( param[1] == 2) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_fireatwill.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_holdfire.png",} )
- end
- end
- return CMD.FIRE_STATE
- end -- end fire state handler
- if cmd == CMD.TRAJECTORY then
- cmdID = Spring.FindUnitCmdDesc(u, CMD.TRAJECTORY )
- if (cmdID ) then
- if ( param[1] == 1 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/high_trajectory.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/low_trajectory.png", } )
- end
- end
- return CMD.TRAJECTORY
- end -- end fire state handler
- if cmd == CMD.AUTOREPAIRLEVEL then
- cmdID = Spring.FindUnitCmdDesc(u, CMD.AUTOREPAIRLEVEL )
- --Spring.Echo(Spring.GetUnitStates(u)["autorepairlevel"])
- if (cmdID ) then
- if ( Spring.GetUnitStates(u)["autorepairlevel"] == 0 ) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage30.png", } )
- elseif ( Spring.GetUnitStates(u)["autorepairlevel"] == 0.30000001192093) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage50.png", } )
- elseif ( Spring.GetUnitStates(u)["autorepairlevel"] == 0.5) then
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage80.png", } )
- else
- Spring.EditUnitCmdDesc(u, cmdID, {texture="bitmaps/ui/buttons/cmd_guage0.png",} )
- end
- end
- return CMD.AUTOREPAIRLEVEL
- end -- end autorepairlevel handler
- return true
- end -- end allow command
- function gadget:UnitGiven(u, ud, team)
- somethingelse(u,ud,team)
- end
- function gadget:UnitCreated(u, ud, team)
- somethingelse(u,ud,team)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment