Guest User

locatecmd.lua

a guest
Apr 6th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. function gadget:GetInfo()
  2. return {
  3. name = "locatecmd",
  4. desc = "Adds a command button for location initiation.",
  5. author = "Bilal Itani",
  6. date = "March 31, 2013",
  7. license = "GNU GPL, v3.0 or later",
  8. layer = 0,
  9. enabled = true -- loaded by default?
  10. }
  11. end
  12.  
  13.  
  14. if (gadgetHandler:IsSyncedCode()) then
  15. --SYNCED
  16.  
  17.  
  18. --local EditUnitCmdDesc = Spring.EditUnitCmdDesc
  19. --local FindUnitCmdDesc = Spring.FindUnitCmdDesc
  20. --local GiveOrderToUnit = Spring.GiveOrderToUnit
  21. --local SetUnitNeutral = Spring.SetUnitNeutral
  22. --local GetUnitMoveTypeData = Spring.GetUnitMoveTypeData
  23. --local SetGroundMoveTypeData = Spring.MoveCtrl.SetGroundMoveTypeData
  24. --local SetGunshipMoveTypeData = Spring.MoveCtrl.SetGunshipMoveTypeData
  25.  
  26. local LOCATOR = {
  27.   [UnitDefNames["locator"].id] = true,
  28. }
  29.  
  30. local locatorList = {}
  31.  
  32. local CMD_STRT_LOC = 34581
  33.  
  34. local locateCmd = {
  35.       id      = CMD_STRT_LOC,
  36.       name    = "Locate",
  37.       action  = "locate",
  38.       type    = CMDTYPE.ICON_MAP,
  39.       tooltip = "Commands the locator to locate.",
  40.       params  = { 'Stop', 'Locate',}
  41. }
  42. --Info for cmd
  43.  
  44.  
  45. function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID)  --identifies unitID, unitDefID, unitTeam, and builderID of each unit created. Can be used for specified units.
  46.   --callin for when locator is created
  47.   if LOCATOR[unitDefID] then
  48.   --makes callin locator specific
  49.  
  50.     Spring.InsertUnitCmdDesc(unitID, 500, locateCmd)
  51.     --actually creates the cmd; makes it visible in the locator's cmd buttons
  52.     else
  53.  
  54. end
  55.  
  56. end
  57.  
  58. function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
  59.   locatorList[unitID] = nil
  60. end
  61.  
  62.  
  63. function gadget:CommandFallback(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag)
  64.      --callin when clicking the cmd button, then clicking on the map
  65.      if LOCATOR[unitDefID] then
  66.  
  67.      Spring.Echo("commandfallback is working so far.")
  68.         --  function Spring.GetMouseState(a, b, c, d, e)
  69.             -- c = true
  70.        
  71.            
  72.          Spring.GiveOrderToUnit(unitID, CMD.MOVE , {x,92,z }, {}) --92 for map being tested
  73.          --tells the locator to move to coords x,y,z
  74.          end
  75.          
  76.    
  77. if (not gadgetHandler:IsSyncedCode()) then
  78. --UNSYNCED
  79.  x,z = Spring.GetMouseState(mousex, mousey)
  80.  --supposed to set cmd.move vars to where the cursor is clicked on the map
  81. end
  82. --I can't find any other way to put this part
  83. --of the commandfallback function into synced code
  84.  
  85.  
  86.  
  87.    
  88.            
  89.            
  90.        
  91.      
  92.   end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment