Advertisement
warpdragon

Tank LUA

Nov 26th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. local Tank = class({})
  2.  
  3. function Spawn (entityKeyValues) --luacheck: ignore Spawn
  4. local Tank = Tank()
  5. Tank:Init(thisEntity)
  6. end
  7.  
  8. function Tank:Init(entity)
  9. -- thisEntity
  10. self.entity = entity
  11. self.lastAction = 0
  12.  
  13. self.slam = self.entity:FindAbilityByName("tank_ground_slam")
  14. self.quake = self.entity:FindAbilityByName("tank_earthquake")
  15. self.opposingTeam = self.entity:GetOpposingTeamNumber()
  16. self.phase = 1
  17.  
  18. local actName = string.sub(self.entity:GetUnitName(), -4)
  19. if actName == "act2" then
  20. self.slam:SetLevel(2)
  21. self.quake:SetLevel(2)
  22. elseif actName == "act3" then
  23. self.slam:SetLevel(3)
  24. self.quake:SetLevel(3)
  25. end
  26. Timers:CreateTimer(1, function()
  27. AddFOWViewer(self.opposingTeam,self.entity:GetAbsOrigin(),400.0,1.5,true)
  28. return self:Think()
  29. end)
  30. end
  31.  
  32. function Tank:Think()
  33. if self.entity:IsNull() or not self.entity:IsAlive() then
  34. return
  35. end
  36. if self.slam:IsFullyCastable() and self.lastAction + 5 < GameRules:GetGameTime() then
  37. self:Slam()
  38. end
  39. if self.quake:IsFullyCastable() and self.lastAction + 5 < GameRules:GetGameTime() then
  40. self:Quake()
  41. end
  42. return 1
  43. end
  44.  
  45. function Tank:Slam()
  46. local target = self:NearestEnemyHeroInRange( self.entity:GetBaseDayTimeVisionRange() )
  47. if target then
  48. ExecuteOrderFromTable({
  49. UnitIndex = self.entity:entindex(),
  50. OrderType = DOTA_UNIT_ORDER_CAST_POSITION,
  51. Position = target:GetAbsOrigin(),
  52. AbilityIndex = self.slam:entindex()
  53. })
  54. end
  55. self.lastAction = GameRules:GetGameTime()
  56. return self.slam:GetCastPoint() + 0.1
  57. end
  58.  
  59. function Tank:Quake()
  60. local target = self:NearestEnemyHeroInRange( self.entity:GetBaseDayTimeVisionRange() )
  61. if target then
  62. ExecuteOrderFromTable({
  63. UnitIndex = self.entity:entindex(),
  64. OrderType = DOTA_UNIT_ORDER_CAST_POSITION,
  65. Position = target:GetAbsOrigin(),
  66. AbilityIndex = self.quake:entindex()
  67. })
  68. end
  69. self.lastAction = GameRules:GetGameTime()
  70. return self.quake:GetCastPoint() + 0.1
  71. end
  72.  
  73. function Tank:NearestEnemyHeroInRange( range )
  74. local flags = DOTA_UNIT_TARGET_FLAG_FOW_VISIBLE + DOTA_UNIT_TARGET_FLAG_NO_INVIS
  75. local enemies = FindUnitsInRadius( self.entity:GetTeamNumber(), self.entity:GetAbsOrigin(), nil, range, DOTA_UNIT_TARGET_TEAM_ENEMY, DOTA_UNIT_TARGET_HERO + DOTA_UNIT_TARGET_BASIC, flags, 0, false )
  76.  
  77. local minRange = range
  78. local target = nil
  79.  
  80. for _,enemy in pairs(enemies) do
  81. local distanceToEnemy = (self.entity:GetAbsOrigin() - enemy:GetAbsOrigin()):Length2D()
  82. if enemy:IsAlive() and distanceToEnemy < minRange then
  83. minRange = distanceToEnemy
  84. target = enemy
  85. end
  86. end
  87. return target
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement