Guest User

Untitled

a guest
Jul 22nd, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. local CMD_QUEUE_TERRAMARKER = 39802
  2.  
  3. -- order of arguments is different than other command funcs for some silly reason, and wrong in the wiki
  4. -- also options are passed as a bitfield instead of table
  5. function widget:UnitCommand(unitID, unitDefID, teamID, cmdId, cmdOptions, cmdParams)
  6. if cmdId == CMD_QUEUE_TERRAMARKER then
  7. local oldParams = {}
  8. for i = 1, #cmdParams - 1, 1 do
  9. oldParams[i] = cmdParams[i]
  10. end
  11. local pos = - 1 -- this is the end of the queue and -should- be behind the terra-build order. however, sometimes it isn't
  12. Spring.GiveOrderToUnit(unitID, CMD.INSERT,{pos, cmdParams[#cmdParams], cmdOptions, unpack(oldParams)}, CMD.OPT_ALT)
  13.  
  14. end
  15.  
  16. end
  17.  
  18.  
  19. function widget:CommandNotify(cmdId, cmdParams, cmdOptions)
  20.  
  21. if currentTerraformSelectedIndex > 1 then
  22. if cmdId < 0 then
  23. local unitDefId = -cmdId
  24.  
  25. if unitDefId == 37 or unitDefId == 275 then
  26.  
  27. local commandPos = {}
  28. commandPos.x = cmdParams[1]
  29. commandPos.y = cmdParams[2]
  30. commandPos.z = cmdParams[3]
  31.  
  32. local terraformHowMuch = 0 + currentTerraformSelectedValue
  33.  
  34. local unitWidth = 10
  35. local unitHeight = 10
  36.  
  37. local rect = GetTerraRectByParams(commandPos.x, commandPos.z, unitWidth, unitHeight, commandPos.y + terraformHowMuch, 0, 0)
  38.  
  39. local selectedUnits = Spring.GetSelectedUnits()
  40. local myTeamId = Spring.GetMyTeamID()
  41. local volumeSelection = 0
  42. local terraformParams = GetTerraParameters(1, rect, selectedUnits, myTeamId, volumeSelection)
  43.  
  44. Spring.GiveOrderToUnit(selectedUnits[1], CMD_TERRAFORM_INTERNAL, terraformParams, {"shift"})
  45.  
  46. local newParams = {}
  47. for i = 1, #cmdParams, 1 do
  48. newParams[i] = cmdParams[i]
  49. end
  50. newParams[#cmdParams+1] = cmdId
  51. Spring.GiveOrderToUnit(selectedUnits[1], CMD_QUEUE_TERRAMARKER, newParams, cmdOptions)
  52.  
  53. return true
  54. end
  55. end
  56. end
  57. return false
  58. end
Advertisement
Add Comment
Please, Sign In to add comment