Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 12th, 2011  |  syntax: Lua  |  size: 1.56 KB  |  hits: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function gadget:GetInfo()
  2.         return {
  3.                 name      = "Weapon Command",
  4.                 desc      = "Weapon Toggle",
  5.                 author    = "Von66341",
  6.                 date      = "22/03/2011",
  7.                 license   = "",
  8.                 layer     = -5,
  9.                 enabled   = true  --  loaded by default?
  10.         }
  11. end
  12.  
  13. -- Constants
  14. local CMD_SPECIAL = 36525
  15.  
  16. local specialCmdDesc = {
  17.         id = CMD_SPECIAL,
  18.         type = CMDTYPE.ICON_MODE,
  19.         name = "Special Weapon On/Off",
  20.         --action = "Radar",
  21.         tooltip = "Special Weapon On/off",
  22.         params = {'0','Special Weapon Off','Special Weapon On'},
  23.         texture = "UI/buttons/cmd_special.png",
  24. }
  25.  
  26. if (gadgetHandler:IsSyncedCode()) then
  27. -- SYNCED
  28.  
  29. function gadget:Initialize()
  30.         gadgetHandler:RegisterCMDID(CMD_SPECIAL)
  31. end
  32.  
  33. function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
  34.         local ud = UnitDefs[unitDefID]
  35.         if ud.customParams.hasspecialbutton then
  36.                 Spring.InsertUnitCmdDesc(unitID, CMD_SPECIAL, specialCmdDesc)
  37.         end
  38. end
  39.  
  40. function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
  41.         if cmdID == CMD_SPECIAL then
  42.        
  43.         local specialCmdDescID = Spring.FindUnitCmdDesc(unitID, CMD_SPECIAL)
  44.         specialCmdDesc.params[1] = cmdParams[1]
  45.         Spring.EditUnitCmdDesc(unitID, specialCmdDescID, specialCmdDesc)
  46.         specialCmdDesc.params[1] = 1
  47.  
  48.         Spring.CallCOBScript(unitID, "Special",0)
  49.         --Spring.Echo("Success")
  50.         return false
  51.         end
  52.        
  53.         --Spring.CallCOBScript(unitID, "QueryWeapon1", 0, 0)
  54.         --Spring.CallCOBScript(unitID, "AimFromWeapon1", 0, 0)
  55.         --Spring.CallCOBScript(unitID, "AimWeapon1", 0, 0)
  56.         --Spring.CallCOBScript(unitID, "FireWeapon1", 0, 0)
  57.        
  58.         return true
  59.         end
  60. end