Advertisement
Guest User

Techies Fatal Errors

a guest
Sep 13th, 2015
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.34 KB | None | 0 0
  1. local myHero = 0
  2. local me = 0
  3. local heroes = {}
  4. local bombs = {}
  5. local numTotalBombs = 0
  6. local bombsforkill = {}
  7. local canKill = false
  8. local testunit = 0
  9.  
  10. local _plugin = nil
  11.  
  12. function OnGameStarted()
  13.     Game.WriteText("|CFF8989DE" .. _plugin:GetName() .. " " .. _plugin:GetVersion() .. "|R has been successfully loaded.", FRAME.MESSAGE, 10)
  14.     me = Jass.GetLocalPlayer()
  15. end
  16.  
  17. function OnEnterLoading()
  18.     table.clear(heroes)
  19.     table.clear(bombs)
  20.     table.clear(bombsforkill)
  21. end
  22.  
  23. function OnGameTick()
  24.  
  25.     -- Don't run bot if game is paused
  26.     if (Game.IsInGame(false) ~= true) then
  27.         return
  28.     end
  29.    
  30.     -- Don't run if no hero or not techies
  31.     if myHero == 0 then return end
  32.    
  33.   --  local iUnitTypeID = Jass.GetUnitTypeId(myHero)
  34.  
  35.   --  if iUnitTypeID == 1211117643 then -- Hero is techies
  36.     --  FixBombTable()
  37.     CheckBombs()
  38.     if canKill == true then
  39.         canKill = false
  40.         --Detonate()
  41.     end
  42.  --   else
  43. --      return
  44.   --  end
  45.  
  46.    
  47. end
  48.  
  49. function FixBombTable()
  50.     local tempbombs = {}
  51.    
  52.     table.clear(tempbombs)
  53.    
  54.     for i in pairs(bombs) do   
  55.         if Jass.UnitAlive(bombs[i]) == true then
  56.             table.insert(tempbombs, bombs[i])
  57.         end
  58.     end
  59.  
  60.    
  61.     table.clear(bombs)
  62.     bombs = tempbombs
  63. end
  64.  
  65. function FixHeroTable()
  66.     local tempheroes = {}
  67.    
  68.     table.clear(tempheroes)
  69.    
  70.     for i in pairs(heroes) do
  71.         if Jass.UnitAlive(heroes[i]) == true then
  72.             table.insert(tempheroes, heroes[i])
  73.         end
  74.     end
  75.  
  76.    
  77.     table.clear(heroes)
  78.     heroes = tempheroes
  79. end
  80.  
  81. function GetIssuedOrderId_Post(ability)
  82.     if ability == 852556 then
  83.         if table.contains(bombs, Jass.GetOrderedUnit()) == true then
  84.             FixBombTable()
  85.         end
  86.     end
  87.    
  88.     return nil
  89. end
  90.  
  91.  
  92. function GetSummonedUnit_Post(unit)
  93.     local unit_type
  94.  
  95.     if Jass.GetOwningPlayer(unit) == me then   
  96.         unit_type = Jass.UnitId2String(Jass.GetUnitTypeId(unit))
  97.         --Game.WriteText("|CFF8989DE Added unit type:" .. unit_type .. "", FRAME.MESSAGE, 5)
  98.        
  99.         if unit_type == "Custom_o018" or unit_type == "Custom_o002" or unit_type == "Custom_o00B" or unit_type == "Custom_o01B"  then
  100.             if not table.contains(bombs, unit) then
  101.                 table.insert(bombs, unit)
  102.                 --FixBombTable()
  103.                 Game.WriteText("|CFF8989DE Added remote mine to table", FRAME.MESSAGE, 5)
  104.             end
  105.         end
  106.     end
  107.    
  108.    
  109.     return nil
  110. end
  111.  
  112.  
  113.  
  114. function SetUnitX_Pre(unit, newX)
  115.     local hType = Jass.ConvertUnitType(0) -- Hero
  116.     local bIsHero = Jass.IsUnitType(unit, hType)
  117.    
  118.     if bIsHero == false then return nil end
  119.    
  120.     local owningPlayer = Jass.GetOwningPlayer(unit)
  121.  
  122.     if owningPlayer == me  then
  123.         myHero = unit
  124.         Game.WriteText("|CFF8989DE Found my hero", FRAME.MESSAGE, 5)
  125.     else
  126.        if not table.contains(heroes, unit) then
  127.             table.insert(heroes, unit)
  128.             Game.WriteText("|CFF8989DE Added hero to table", FRAME.MESSAGE, 1)
  129.        end
  130.     end
  131.    
  132.     return nil
  133. end
  134.  
  135.  
  136.  
  137. function CheckBombs()
  138.     local heroX = 0
  139.     local heroY = 0
  140.     local bombX = 0
  141.     local bombY = 0
  142.     local unitName = ""
  143.     local unitLife = 0
  144.     local bombDmg = 0
  145.     local dx = 0
  146.     local dy = 0
  147.     local count = 0
  148.    
  149.     FixBombTable()
  150.    
  151.     numTotalBombs = 0
  152.     for _ in pairs(bombs) do numTotalBombs = numTotalBombs + 1 end
  153.    
  154.     if numTotalBombs == 0 then
  155.         return
  156.     end
  157.    
  158.     FixHeroTable()
  159.    
  160.     for k in pairs(heroes) do
  161.         if Jass.IsUnitAlly(heroes[k], me) == true or Jass.UnitAlive(heroes[k]) == false or Jass.IsUnitVisible(heroes[k], me) == false then goto continue end
  162.        
  163.         unitName = Jass.GetUnitName(heroes[k])
  164.         unitLife = Jass.GetUnitState(heroes[k], 0)
  165.        
  166.         heroX = Jass.GetUnitX(heroes[k])
  167.         heroY = Jass.GetUnitY(heroes[k])
  168.        
  169.         bombDmg = 0
  170.         canKill = false
  171.         table.clear(bombsforkill)
  172.    
  173.         for j in pairs(bombs) do
  174.    
  175.             bombX = Jass.GetUnitX(bombs[j])
  176.             bombY = Jass.GetUnitY(bombs[j])
  177.             dx = heroX - bombX
  178.             dy = heroY - bombY
  179.  
  180.             --Game.WriteText("|CFF8989DE Checking square root now", FRAME.MESSAGE, 1)
  181.        
  182.             if math.sqrt((dx * dx) + (dy * dy)) <= 400 then
  183.                    if not table.contains(bombsforkill, bombs[j]) then
  184.                         table.insert(bombsforkill, bombs[j])
  185.                         bombDmg = bombDmg + 225
  186.                         if bombDmg >= unitLife then
  187.                             canKill = true
  188.                             Game.WriteText("|CFF8989DE Hero: " .. unitName .. " with HP: " .. unitLife .. " can be killed by mines with " .. bombDmg .. " damage!", FRAME.MESSAGE, 2)
  189.                          
  190.                             return
  191.                         end
  192.                    end
  193.                               --  table.remove(bombs, j)
  194.                 --Game.WriteText("|CFF8989DE Hero: " .. unitName .. " is within range of mine!", FRAME.MESSAGE, 1)
  195.             end
  196.         end
  197.         ::continue::
  198.     end
  199.  
  200.     --table.clear(bombsforkill)
  201.    
  202. end
  203.  
  204. function Detonate()
  205.     Jass.ClearSelection()
  206.  
  207.     for i in pairs (bombsforkill) do
  208.         Sleep(20)
  209.         Jass.SelectUnit(bombsforkill[i], true)
  210.         Sleep(20)
  211.         --Game.WriteText("|CFF8989DE JUST DETONATED BOMB " .. i .. "", FRAME.MESSAGE, 5)
  212.     end
  213.        
  214.     Sleep(20)
  215.     Jass.IssueImmediateOrderById(bombsforkill[1], 852556)
  216.        
  217.     table.clear(bombsforkill)
  218.     Jass.ClearSelection()
  219.     Sleep(50)
  220.     Jass.SelectUnit(myHero, true)
  221.     Sleep(20)
  222. end
  223.  
  224.  
  225. function table.contains(table, element)
  226.     for _, value in pairs(table) do
  227.         if value == element then
  228.             return true
  229.         end
  230.     end
  231.     return false
  232. end
  233.  
  234. function table.clear(table)
  235.     for k in pairs (table) do
  236.         table[k] = nil
  237.     end
  238. end
  239.  
  240. function Initialize(plugin)
  241.     plugin:SetName("Techie Helper")
  242.     plugin:SetVersion("1.0")
  243.     plugin:SetAuthor("seadoo14")
  244.     plugin:SetDescription("Lua Engine Sample Plugin")
  245.    
  246.     plugin:RegisterGameEvent(EVENT.GAME_STARTED, "OnGameStarted")
  247.     plugin:RegisterGameEvent(EVENT.ENTER_LOADING, "OnEnterLoading")
  248.     plugin:RegisterGameEvent(EVENT.GAME_TICK, "OnGameTick")
  249.     plugin:RegisterNativeHook("SetUnitX", "SetUnitX_Pre", "")
  250.     plugin:RegisterNativeHook("GetSummonedUnit", "", "GetSummonedUnit_Post")
  251.     plugin:RegisterNativeHook("GetIssuedOrderId", "", "GetIssuedOrderId_Post")
  252.  
  253.     _plugin = plugin -- We are storing this for later use
  254. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement