Guest User

locatecmd.lua

a guest
Apr 13th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 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, 2013",
  7. license = "GNU GPL, v3.0 or later",
  8. layer = 0,
  9. enabled = true -- loaded by default?
  10. }
  11. end
  12.  
  13. if (not gadgetHandler:IsSyncedCode()) then return end
  14.  
  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:CommandFallback(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag)
  59.       if cmdID == CMD_STRT_LOC then --is beloved our custom command?
  60.       if LOCATOR[unitDefID] then   --is it a unit that should care about our custom command?        
  61.          local x = cmdParams[1]
  62.          local y = cmdParams[2]
  63.          local z = cmdParams[3]
  64.          
  65.          Spring.Echo("commandfallback is called.")
  66.          Spring.GiveOrderToUnit(unitID, CMD.MOVE , {x,y,z }, {}) --92 for map being tested
  67.          --tells the locator to move to coords x,y,z
  68.          end
  69.          
  70.          local locatorPosX, LocatorPosY, LocatorPosZ = Spring.GetUnitPosition(unitID)
  71.          local metalx = 500
  72.          local metaly = 500
  73.          local metalz = 500
  74.         --unitID ==
  75.        
  76.         if locatorList[unitID] == unitID then
  77.         Spring.Echo("The locator is told to distance check for mineral deposits.")
  78.         if metalx - 50 >= locatorPosX
  79.         then
  80.         if metalx + 50 >= locatorPosX
  81.         then
  82.         if metalz - 50 >= locatorPosZ
  83.         then
  84.         if metalz + 50 >= locatorPosZ
  85.          then
  86.          local metalx = cmdParams[1]
  87.          local metaly = cmdParams[2]
  88.          local metalz = cmdParams[3]
  89.          Spring.GiveOrderToUnit(unitID, CMD.MOVE , {metalx,metaly,metalz }, {})
  90.          end
  91.          end
  92.          end
  93.          end
  94.          end
  95.      
  96.        
  97. end
  98. end
  99.  
  100.  
  101.  
  102. function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
  103.   locatorList[unitID] = nil
  104. end
Advertisement
Add Comment
Please, Sign In to add comment