Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local myHero = 0
- local me = 0
- local heroes = {}
- local bombs = {}
- local numTotalBombs = 0
- local bombsforkill = {}
- local canKill = false
- local testunit = 0
- local _plugin = nil
- function OnGameStarted()
- Game.WriteText("|CFF8989DE" .. _plugin:GetName() .. " " .. _plugin:GetVersion() .. "|R has been successfully loaded.", FRAME.MESSAGE, 10)
- me = Jass.GetLocalPlayer()
- end
- function OnEnterLoading()
- table.clear(heroes)
- table.clear(bombs)
- table.clear(bombsforkill)
- end
- function OnGameTick()
- -- Don't run bot if game is paused
- if (Game.IsInGame(false) ~= true) then
- return
- end
- -- Don't run if no hero or not techies
- if myHero == 0 then return end
- -- local iUnitTypeID = Jass.GetUnitTypeId(myHero)
- -- if iUnitTypeID == 1211117643 then -- Hero is techies
- -- FixBombTable()
- CheckBombs()
- if canKill == true then
- canKill = false
- --Detonate()
- end
- -- else
- -- return
- -- end
- end
- function FixBombTable()
- local tempbombs = {}
- table.clear(tempbombs)
- for i in pairs(bombs) do
- if Jass.UnitAlive(bombs[i]) == true then
- table.insert(tempbombs, bombs[i])
- end
- end
- table.clear(bombs)
- bombs = tempbombs
- end
- function FixHeroTable()
- local tempheroes = {}
- table.clear(tempheroes)
- for i in pairs(heroes) do
- if Jass.UnitAlive(heroes[i]) == true then
- table.insert(tempheroes, heroes[i])
- end
- end
- table.clear(heroes)
- heroes = tempheroes
- end
- function GetIssuedOrderId_Post(ability)
- if ability == 852556 then
- if table.contains(bombs, Jass.GetOrderedUnit()) == true then
- FixBombTable()
- end
- end
- return nil
- end
- function GetSummonedUnit_Post(unit)
- local unit_type
- if Jass.GetOwningPlayer(unit) == me then
- unit_type = Jass.UnitId2String(Jass.GetUnitTypeId(unit))
- --Game.WriteText("|CFF8989DE Added unit type:" .. unit_type .. "", FRAME.MESSAGE, 5)
- if unit_type == "Custom_o018" or unit_type == "Custom_o002" or unit_type == "Custom_o00B" or unit_type == "Custom_o01B" then
- if not table.contains(bombs, unit) then
- table.insert(bombs, unit)
- --FixBombTable()
- Game.WriteText("|CFF8989DE Added remote mine to table", FRAME.MESSAGE, 5)
- end
- end
- end
- return nil
- end
- function SetUnitX_Pre(unit, newX)
- local hType = Jass.ConvertUnitType(0) -- Hero
- local bIsHero = Jass.IsUnitType(unit, hType)
- if bIsHero == false then return nil end
- local owningPlayer = Jass.GetOwningPlayer(unit)
- if owningPlayer == me then
- myHero = unit
- Game.WriteText("|CFF8989DE Found my hero", FRAME.MESSAGE, 5)
- else
- if not table.contains(heroes, unit) then
- table.insert(heroes, unit)
- Game.WriteText("|CFF8989DE Added hero to table", FRAME.MESSAGE, 1)
- end
- end
- return nil
- end
- function CheckBombs()
- local heroX = 0
- local heroY = 0
- local bombX = 0
- local bombY = 0
- local unitName = ""
- local unitLife = 0
- local bombDmg = 0
- local dx = 0
- local dy = 0
- local count = 0
- FixBombTable()
- numTotalBombs = 0
- for _ in pairs(bombs) do numTotalBombs = numTotalBombs + 1 end
- if numTotalBombs == 0 then
- return
- end
- FixHeroTable()
- for k in pairs(heroes) do
- if Jass.IsUnitAlly(heroes[k], me) == true or Jass.UnitAlive(heroes[k]) == false or Jass.IsUnitVisible(heroes[k], me) == false then goto continue end
- unitName = Jass.GetUnitName(heroes[k])
- unitLife = Jass.GetUnitState(heroes[k], 0)
- heroX = Jass.GetUnitX(heroes[k])
- heroY = Jass.GetUnitY(heroes[k])
- bombDmg = 0
- canKill = false
- table.clear(bombsforkill)
- for j in pairs(bombs) do
- bombX = Jass.GetUnitX(bombs[j])
- bombY = Jass.GetUnitY(bombs[j])
- dx = heroX - bombX
- dy = heroY - bombY
- --Game.WriteText("|CFF8989DE Checking square root now", FRAME.MESSAGE, 1)
- if math.sqrt((dx * dx) + (dy * dy)) <= 400 then
- if not table.contains(bombsforkill, bombs[j]) then
- table.insert(bombsforkill, bombs[j])
- bombDmg = bombDmg + 225
- if bombDmg >= unitLife then
- canKill = true
- Game.WriteText("|CFF8989DE Hero: " .. unitName .. " with HP: " .. unitLife .. " can be killed by mines with " .. bombDmg .. " damage!", FRAME.MESSAGE, 2)
- return
- end
- end
- -- table.remove(bombs, j)
- --Game.WriteText("|CFF8989DE Hero: " .. unitName .. " is within range of mine!", FRAME.MESSAGE, 1)
- end
- end
- ::continue::
- end
- --table.clear(bombsforkill)
- end
- function Detonate()
- Jass.ClearSelection()
- for i in pairs (bombsforkill) do
- Sleep(20)
- Jass.SelectUnit(bombsforkill[i], true)
- Sleep(20)
- --Game.WriteText("|CFF8989DE JUST DETONATED BOMB " .. i .. "", FRAME.MESSAGE, 5)
- end
- Sleep(20)
- Jass.IssueImmediateOrderById(bombsforkill[1], 852556)
- table.clear(bombsforkill)
- Jass.ClearSelection()
- Sleep(50)
- Jass.SelectUnit(myHero, true)
- Sleep(20)
- end
- function table.contains(table, element)
- for _, value in pairs(table) do
- if value == element then
- return true
- end
- end
- return false
- end
- function table.clear(table)
- for k in pairs (table) do
- table[k] = nil
- end
- end
- function Initialize(plugin)
- plugin:SetName("Techie Helper")
- plugin:SetVersion("1.0")
- plugin:SetAuthor("seadoo14")
- plugin:SetDescription("Lua Engine Sample Plugin")
- plugin:RegisterGameEvent(EVENT.GAME_STARTED, "OnGameStarted")
- plugin:RegisterGameEvent(EVENT.ENTER_LOADING, "OnEnterLoading")
- plugin:RegisterGameEvent(EVENT.GAME_TICK, "OnGameTick")
- plugin:RegisterNativeHook("SetUnitX", "SetUnitX_Pre", "")
- plugin:RegisterNativeHook("GetSummonedUnit", "", "GetSummonedUnit_Post")
- plugin:RegisterNativeHook("GetIssuedOrderId", "", "GetIssuedOrderId_Post")
- _plugin = plugin -- We are storing this for later use
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement