Guest User

Mex_Defense

a guest
Sep 25th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.62 KB | None | 0 0
  1. function widget:GetInfo()
  2.   return {
  3.     name      = "Mex Defense (v1.0)",
  4.     desc      = "automates constructors to build basic defenses next to every mex built",
  5.     author    = "AutoWar",
  6.     date      = "2015",
  7.     license   = "GNU GPL, v2 or later",
  8.     layer     = 9999,
  9.     enabled   = true
  10.   }
  11. end
  12.  
  13. -----------------------------------------------------------------
  14.  
  15. local spGetUnitNearestEnemy = Spring.GetUnitNearestEnemy
  16. local spGetAllUnits         = Spring.GetAllUnits    --( ) -> nil | unitTable = { [1] = number unitID, ... }
  17. local spMarkerAddPoint      = Spring.MarkerAddPoint
  18. local spEcho                = Spring.Echo
  19. local spInsertUnitCmdDesc   = Spring.InsertUnitCmdDesc
  20. local spGetUnitAllyTeam     = Spring.GetUnitAllyTeam
  21. local spValidUnitID         = Spring.ValidUnitID
  22. local spGetUnitPosition     = Spring.GetUnitPosition
  23. local spGetUnitDefID        = Spring.GetUnitDefID
  24. local spGiveOrderToUnit     = Spring.GiveOrderToUnit
  25. local spGetUnitStates       = Spring.GetUnitStates
  26. local spGiveOrderToUnitArray= Spring.GiveOrderToUnitArray
  27. local spGetUnitIsDead       = Spring.GetUnitIsDead
  28. local spValidUnitID         = Spring.ValidUnitID
  29. local spGetTeamUnits        = Spring.GetTeamUnits  --( number teamID ) -> nil | unitTable = { [1] = number unitID, etc... }
  30. local spGetMyTeamID         = Spring.GetMyTeamID
  31. local spGetMyAllyTeamID     = Spring.GetMyAllyTeamID
  32. local spIsUnitIcon          = Spring.IsUnitIcon
  33. local myAllyID = Spring.GetMyAllyTeamID()
  34. local myTeamID = Spring.GetMyTeamID()
  35. local CMD_ATTACK = CMD.ATTACK
  36. local CMD_MOVE = CMD.MOVE
  37. local CMD_UNIT_SET_TARGET = 34923
  38. local spGetAllyTeamList         = Spring.GetAllyTeamList    --( ) -> { [1] = number allyTeamID, etc... }
  39. local spGetTeamList             = Spring.GetTeamList        --( [number allyTeamID = -1] ) -> nil | { [1] = number teamID, etc... }
  40. local spGetUnitTeam             = Spring.GetUnitTeam        --( number unitID ) -> nil | number teamID
  41. local CMD_LOAD_UNITS            = CMD.LOAD_UNITS            -- expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)
  42. local spGetUnitTransporter      = Spring.GetUnitTransporter --( number unitID ) -> nil | number unitID
  43. local spGetUnitIsTransporting   = Spring.GetUnitIsTransporting --( number unitID ) -> nil | { [1] = number unitID, etc... }
  44. local spGetUnitHealth           = Spring.GetUnitHealth      --( number unitID ) -> nil | number health, number maxHealth, number paralyzeDamage, number captureProgress, number buildProgress
  45. local spGetUnitIsStunned        = Spring.GetUnitIsStunned   --( number unitID ) -> nil | boolean stunned_or_inbuild, boolean stunned, boolean inbuild
  46. local spGetUnitRulesParam       = Spring.GetUnitRulesParam  --( number unitID, number index | string ruleName ) -> nil | number value | string value
  47. local CMD_OPT_SHIFT             = CMD.OPT_SHIFT             --If the unit is working down a shift queue, add it seemless into it
  48. local CMD_INSERT                = CMD.INSERT
  49. local spGetCommandQueue         = Spring.GetCommandQueue    --( number unitID, number count = 0 ) -> nil | number commandQueueSize,  ( number unitID [, number count = -1] ) -> nil | table commandQueueTable = {[1] = {("id"=number),("params"={ [1]=number, ...}),("options"={"coded"=number,"alt"=boolean,"ctrl"=boolean,"shift"=boolean,"right"=boolean,"internal"=boolean,"meta"=boolean}}), ...}
  50. local spGetSelectedUnits        = Spring.GetSelectedUnits   --( ) -> { [1] = unitID, ... }
  51. local spGetGroundHeight         = Spring.GetGroundHeight    --(x,z)
  52.  
  53. -----------------------------------------------------------------
  54.  
  55.  
  56.  
  57. -----------------------------------------------------------------
  58.  
  59. local function Distance(x1,z1,x2,z2)
  60.     return math.sqrt((x1-x2)^2 + (z1-z2)^2)
  61. end
  62.  
  63. local function GetUnitName(unitID)
  64.     if spValidUnitID(unitID)==true and spGetUnitDefID(unitID) then
  65.         return UnitDefs[spGetUnitDefID(unitID)].name
  66.     end
  67. end
  68.  
  69. -----------------------------------------------------------------
  70.  
  71. function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
  72.     if unitDefID==UnitDefNames["cormex"].id then
  73.         local x,y,z = spGetUnitPosition (unitID)
  74.         --Spring.GiveOrderToUnit(builderID, -UnitDefNames["corllt"].id, {x+50,0,z}, {"shift"})
  75.         spGiveOrderToUnit(builderID, CMD.INSERT, {1, -UnitDefNames["corllt"].id, CMD.OPT_SHIFT, x+50,0,z}, {"alt"})
  76.         spGiveOrderToUnit(builderID, CMD.INSERT, {1, -UnitDefNames["corrad"].id, CMD.OPT_SHIFT, x-50,0,z}, {"alt"})
  77.         spGiveOrderToUnit(builderID, CMD.INSERT, {1, -UnitDefNames["armwin"].id, CMD.OPT_SHIFT, x-100,0,z}, {"alt"})
  78.         if spGetGroundHeight(x,z)<=0 then
  79.         spGiveOrderToUnit(builderID, CMD.INSERT, {1, -UnitDefNames["turrettorp"].id, CMD.OPT_SHIFT, x+100,0,z}, {"alt"})
  80.         end
  81.     end
  82. end
  83.  
  84.  
  85.  
  86. --[[
  87.  
  88. Mex Defense
  89.  
  90. automates the constructor to build an LLT , radar, wind gen, and on sea an urchin, next to every mex built
  91.  
  92. ]]
Advertisement
Add Comment
Please, Sign In to add comment