SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- TargetSelector Class
  2.  
  3. --[[
  4. TargetSelector Class :
  5. Methods:
  6. ts = TargetSelector(mode, range, damageType (opt), targetSelected (opt), enemyTeam (opt))
  7.  
  8. Goblal Functions :
  9. TS_Print(enemyTeam (opt))           -> print Priority (global)
  10.  
  11. TS_SetFocus()           -> set priority to the selected champion (you need to use PRIORITY modes to use it) (global)
  12. TS_SetFocus(id)         -> set priority to the championID (you need to use PRIORITY modes to use it) (global)
  13. TS_SetFocus(charName, enemyTeam (opt))  -> set priority to the champion charName (you need to use PRIORITY modes to use it) (global)
  14. TS_SetFocus(hero)       -> set priority to the hero object (you need to use PRIORITY modes to use it) (global)
  15.  
  16. TS_SetHeroPriority(priority, target, enemyTeam (opt))                   -> set the priority to target
  17. TS_SetPriority(target1, target2, target3, target4, target5)     -> set priority in order to enemy targets
  18. TS_SetPriorityA(target1, target2, target3, target4, target5)    -> set priority in order to ally targets
  19.  
  20. TS_GetPriority(target, enemyTeam)       -> return the current priority, and the max allowed
  21.  
  22. TargetSelector__OnSendChat(msg)             -- to add to OnSendChat(msg) function if you want the chat command
  23.  
  24. Functions :
  25. ts:update()                                             -- update the instance target
  26. ts:SetDamages(magicDmgBase, physicalDmgBase, trueDmg)  
  27.  
  28. ts:SetPrediction()                          -- prediction off
  29. ts:SetPrediction(delay)                     -- predict movement for champs (need Prediction__OnTick())
  30. ts:SetMinionCollision()                     -- minion colission off
  31. ts:SetMinionCollision(spellWidth)           -- avoid champ if minion between player
  32. ts:SetConditional()                         -- erase external function use
  33. ts:SetConditional(func)                     -- set external function that return true/false to allow filter -- function(hero, index (opt))
  34. ts:SetProjectileSpeed(pSpeed)               -- set projectile speed (need Prediction__OnTick())
  35.  
  36. Members:
  37. ts.mode                     -> TARGET_LOW_HP, TARGET_MOST_AP, TARGET_MOST_AD, TARGET_PRIORITY, TARGET_NEAR_MOUSE, TARGET_LOW_HP_PRIORITY, TARGET_LESS_CAST, TARGET_LESS_CAST_PRIORITY
  38. ts.range                    -> number > 0
  39. ts.targetSelected       -> true/false
  40. ts.target                   -> return the target (object or nil)
  41. ts.index        -> index of target (if hero)
  42. ts.nextPosition -> nextPosition predicted
  43. ts.nextHealth       -> nextHealth predicted
  44.  
  45. Usage :
  46. variable = TargetSelector(mode, range, damageType (opt), targetSelected (opt), enemyTeam (opt))
  47. targetSelected is set to true if not filled
  48. Damages are set as default to magic 100 if none is set
  49. enemyTeam is false if ally, nil or true if enemy
  50.  
  51. when you want to update, call variable:update()
  52.  
  53. Values you can change on instance :
  54. variable.mode -> TARGET_LOW_HP, TARGET_MOST_AP, TARGET_PRIORITY, TARGET_NEAR_MOUSE, TARGET_LOW_HP_PRIORITY, TARGET_LESS_CAST, TARGET_LESS_CAST_PRIORITY
  55. variable.range -> number > 0
  56. variable.targetSelected -> true/false (if you clicked on a champ)
  57.  
  58.  
  59. ex :
  60. function OnLoad()
  61.     ts = TargetSelector(TARGET_LESS_CAST, 600, DAMAGE_MAGIC, true)
  62. end
  63.  
  64. function OnTick()
  65.     ts:update()
  66.     if ts.target ~= nil then
  67.         PrintChat(ts.target.charName)
  68.         ts:SetDamages((player.ap * 10), 0, 0)
  69.     end
  70. end
  71.  
  72. function OnSendChat(msg)
  73.     TargetSelector__OnSendChat(msg)
  74. end
  75.  
  76. ]]
  77.  
  78. -- Class related constants
  79. TARGET_LOW_HP = 1
  80. TARGET_MOST_AP = 2
  81. TARGET_MOST_AD = 3
  82. TARGET_LESS_CAST = 4
  83. TARGET_NEAR_MOUSE = 5
  84. TARGET_PRIORITY = 6
  85. TARGET_LOW_HP_PRIORITY = 7
  86. TARGET_LESS_CAST_PRIORITY = 8
  87. DAMAGE_MAGIC = 1
  88. DAMAGE_PHYSICAL = 2
  89.  
  90. -- Class related global
  91. _gameHeros, _gameAllyCount, _gameEnemyCount = {}, 0, 0
  92. _TargetSelector__texted = {"LowHP", "MostAP", "MostAD", "LessCast", "NearMouse", "Priority", "LowHPPriority", "LessCastPriority"}
  93.  
  94. -- Class related function
  95. function _gameHeros__init()
  96.     if #_gameHeros == 0 then
  97.         _gameAllyCount, _gameEnemyCount = 0, 0
  98.         for i = 1, heroManager.iCount do
  99.             local hero = heroManager:getHero(i)
  100.             if hero ~= nil then
  101.                 if hero.team == player.team then
  102.                     _gameAllyCount = _gameAllyCount + 1
  103.                     table.insert(_gameHeros, {hero = hero, index = i, tIndex = _gameAllyCount, ignore = false, priority = 1, enemy = false})
  104.                 else
  105.                     _gameEnemyCount = _gameEnemyCount + 1
  106.                     table.insert(_gameHeros, {hero = hero, index = i, tIndex = _gameEnemyCount, ignore = false, priority = 1, enemy = true})
  107.                 end
  108.             end
  109.         end
  110.     end
  111. end
  112.  
  113. function _gameHeros__extended(target, assertText)
  114.     local assertText = assertText or ""
  115.     if type(target) == "number" then
  116.         return _gameHeros[target]
  117.     elseif target ~= nil then
  118.         assert(type(target.networkID) == "number", assertText..": wrong argument types (<charName> or <heroIndex> or <hero> expected)")
  119.         for index,_gameHero in ipairs(_gameHeros) do
  120.             if _gameHero.hero.networkID == target.networkID then
  121.                 return _gameHero
  122.             end
  123.         end
  124.     end
  125. end
  126.  
  127. function _gameHeros__hero(target, assertText, enemyTeam)
  128.     local assertText = assertText or ""
  129.     enemyTeam = (enemyTeam ~= false)
  130.     if type(target) == "string" then
  131.         for index,_gameHero in ipairs(_gameHeros) do
  132.             if _gameHero.hero.charName == target and (_gameHero.hero.team ~= player.team) == enemyTeam then
  133.                 return _gameHero.hero
  134.             end
  135.         end
  136.     elseif type(target) == "number" then
  137.         return heroManager:getHero(target)
  138.     elseif target == nil then
  139.         return GetTarget()
  140.     else
  141.         assert(type(target.networkID) == "number", assertText..": wrong argument types (<charName> or <heroIndex> or <hero> or nil expected)")
  142.         return target
  143.     end
  144. end
  145.  
  146. function _gameHeros__index(target, assertText, enemyTeam)
  147.     local assertText = assertText or ""
  148.     local enemyTeam = (enemyTeam ~= false)
  149.     if type(target) == "string" then
  150.         for index,_gameHero in ipairs(_gameHeros) do
  151.             if _gameHero.hero.charName == target and (_gameHero.hero.team ~= player.team) == enemyTeam then
  152.                 return _gameHero.index
  153.             end
  154.         end
  155.     elseif type(target) == "number" then
  156.         return target
  157.     else
  158.         assert(type(target.networkID) == "number", assertText..": wrong argument types (<charName> or <heroIndex> or <hero> or nil expected)")
  159.         return _gameHeros__index(target.charName, assertText, (target.team ~= player.team))
  160.     end
  161. end
  162.  
  163. function TS_Print(enemyTeam)
  164.     local enemyTeam = (enemyTeam ~= false)
  165.     for i, target in ipairs(_gameHeros) do
  166.         if target.hero ~= nil and target.enemy == enemyTeam then
  167.             PrintChat("[TS] "..(enemyTeam and "Enemy " or "Ally ")..target.tIndex.." ("..target.index..") : " .. target.hero.charName .. " Mode=" .. (target.ignore and "ignore" or "target") .." Priority=" .. target.priority)
  168.         end
  169.     end
  170. end
  171.  
  172. function TS_SetFocus(target, enemyTeam)
  173.     local enemyTeam = (enemyTeam ~= false)
  174.     local selected = _gameHeros__hero(target, "TS_SetFocus")
  175.     if selected ~= nil and selected.type == "obj_AI_Hero" and (selected.team ~= player.team) == enemyTeam then
  176.         for index,_gameHero in ipairs(_gameHeros) do
  177.             if _gameHero.enemy == enemyTeam then
  178.                 if _gameHero.hero.networkID == selected.networkID then
  179.                     _gameHero.priority = 1
  180.                     PrintChat("[TS] Focusing " .. _gameHero.hero.charName)
  181.                 else
  182.                     _gameHero.priority = (enemyTeam and _gameEnemyCount or _gameAllyCount)
  183.                 end
  184.             end
  185.         end
  186.     end
  187. end
  188.  
  189. function TS_SetHeroPriority(priority, target, enemyTeam)
  190.     local enemyTeam = (enemyTeam ~= false)
  191.     local heroCount = (enemyTeam and _gameEnemyCount or _gameAllyCount)
  192.     assert(type(priority) == "number" and priority >= 0 and priority <= heroCount, "TS_SetHeroPriority: wrong argument types (<number> 1 to "..heroCount.." expected)")
  193.     local selected = _gameHeros__index(target, "TS_SetHeroPriority: wrong argument types (<charName> or <heroIndex> or <hero> or nil expected)", enemyTeam)
  194.     if selected ~= nil then
  195.         local oldPriority = _gameHeros[selected].priority
  196.         if oldPriority == nil or oldPriority == priority then return end
  197.         for index,_gameHero in ipairs(_gameHeros) do
  198.             if _gameHero.enemy == enemyTeam then
  199.                 if index == selected then
  200.                     _gameHero.priority = priority
  201.                     --PrintChat("[TS] "..(enemyTeam and "Enemy " or "Ally ").._gameHero.tIndex.." (".._gameHero.index..") : " .. _gameHero.hero.charName .. " Mode=" .. (_gameHero.ignore and "ignore" or "target") .." Priority=" .. _gameHero.priority)
  202.                 end
  203.             end
  204.         end
  205.     end
  206. end
  207.  
  208. function TS_SetPriority(target1, target2, target3, target4, target5)
  209.     assert((target5 ~= nil and _gameEnemyCount == 5) or (target4 ~= nil and _gameEnemyCount < 5) or (target3 ~= nil and _gameEnemyCount == 3) or (target2 ~= nil and _gameEnemyCount == 2) or (target1 ~= nil and _gameEnemyCount == 1), "TS_SetPriority: wrong argument types (".._gameEnemyCount.." <target> expected)")
  210.     TS_SetHeroPriority(1, target1)
  211.     TS_SetHeroPriority(2, target2)
  212.     TS_SetHeroPriority(3, target3)
  213.     TS_SetHeroPriority(4, target4)
  214.     TS_SetHeroPriority(5, target5)
  215. end
  216.  
  217. function TS_SetPriorityA(target1, target2, target3, target4, target5)
  218.     assert((target5 ~= nil and _gameAllyCount == 5) or (target4 ~= nil and _gameAllyCount < 5) or (target3 ~= nil and _gameAllyCount == 3) or (target2 ~= nil and _gameAllyCount == 2) or (target1 ~= nil and _gameAllyCount == 1), "TS_SetPriorityA: wrong argument types (".._gameAllyCount.." <target> expected)")
  219.     TS_SetHeroPriority(1, target1, false)
  220.     TS_SetHeroPriority(2, target2, false)
  221.     TS_SetHeroPriority(3, target3, false)
  222.     TS_SetHeroPriority(4, target4, false)
  223.     TS_SetHeroPriority(5, target5, false)
  224. end
  225.  
  226. function TS_GetPriority(target, enemyTeam)
  227.     local enemyTeam = (enemyTeam ~= false)
  228.     local index = _gameHeros__index(target, "TS_GetPriority", enemyTeam)
  229.     return (index and _gameHeros[index].priority or nil), (enemyTeam and _gameEnemyCount or _gameAllyCount)
  230. end
  231.  
  232. function TS_Ignore(target, enemyTeam)
  233.     local enemyTeam = (enemyTeam ~= false)
  234.     local selected = _gameHeros__hero(target, "TS_Ignore")
  235.     if selected ~= nil and selected.type == "obj_AI_Hero" and (selected.team ~= player.team) == enemyTeam then
  236.         for index,_gameHero in ipairs(_gameHeros) do
  237.             if _gameHero.hero.networkID == selected.networkID and _gameHero.enemy == enemyTeam then
  238.                 _gameHero.ignore = not _gameHero.ignore
  239.                 --PrintChat("[TS] "..(_gameHero.ignore and "Ignoring " or "Re-targetting ").._gameHero.hero.charName)
  240.                 break
  241.             end
  242.         end
  243.     end
  244. end
  245.  
  246. function _TS_Draw_Init()
  247.     if not _TS_Draw then
  248.         if not WINDOW_H or not WINDOW_W then PrintChat("WINDOW value not good, please reload") end
  249.         _TS_Draw = {y1 = 0, heigth = 0, fontSize = WINDOW_H and math.round(WINDOW_H / 54) or 14, width = WINDOW_W and math.round(WINDOW_W / 4.8) or 213, border = 2, background = 1413167931, textColor = 4290427578, redColor = 1422721024, greenColor = 1409321728, blueColor = 2684354716}
  250.         _TS_Draw.cellSize, _TS_Draw.midSize, _TS_Draw.row1, _TS_Draw.row2, _TS_Draw.row3, _TS_Draw.row4 = _TS_Draw.fontSize + _TS_Draw.border, _TS_Draw.fontSize / 2, _TS_Draw.width * 0.6, _TS_Draw.width * 0.7, _TS_Draw.width * 0.8, _TS_Draw.width * 0.9
  251.     end
  252. end
  253.  
  254. function TS__DrawMenu(x, y, enemyTeam)
  255.     assert(type(x) == "number" and type(y) == "number", "TS__DrawMenu: wrong argument types (<number>, <number> expected)")
  256.     _TS_Draw_Init()
  257.     local enemyTeam = (enemyTeam ~= false)
  258.     local y1 = y
  259.     for index,_gameHero in ipairs(_gameHeros) do
  260.         if _gameHero.enemy == enemyTeam then
  261.             DrawLine(x - _TS_Draw.border, y1 + _TS_Draw.midSize, x + _TS_Draw.row1 - _TS_Draw.border, y1 + _TS_Draw.midSize, _TS_Draw.cellSize, (_gameHero.ignore and _TS_Draw.redColor or _TS_Draw.background))
  262.             DrawText(_gameHero.hero.charName, _TS_Draw.fontSize, x, y1, _TS_Draw.textColor)
  263.             DrawLine(x + _TS_Draw.row1, y1 + _TS_Draw.midSize, x + _TS_Draw.row2 - _TS_Draw.border, y1 + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.background)
  264.             DrawText("   "..(_gameHero.ignore and "-" or tostring(_gameHero.priority)), _TS_Draw.fontSize, x + _TS_Draw.row1, y1, _TS_Draw.textColor)
  265.             DrawLine(x + _TS_Draw.row2, y1 + _TS_Draw.midSize, x + _TS_Draw.row3 - _TS_Draw.border, y1 + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.blueColor)
  266.             DrawText("   -", _TS_Draw.fontSize, x + _TS_Draw.row2, y1, _TS_Draw.textColor)
  267.             DrawLine(x + _TS_Draw.row3, y1 + _TS_Draw.midSize, x + _TS_Draw.row4 - _TS_Draw.border, y1 + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.blueColor)
  268.             DrawText("   +", _TS_Draw.fontSize, x + _TS_Draw.row3, y1, _TS_Draw.textColor)
  269.             DrawLine(x + _TS_Draw.row4, y1 + _TS_Draw.midSize, x + _TS_Draw.width, y1 + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.redColor)
  270.             DrawText("   X", _TS_Draw.fontSize, x + _TS_Draw.row4, y1, _TS_Draw.textColor)
  271.             y1 = y1 + _TS_Draw.cellSize
  272.         end
  273.     end
  274.     return y1
  275. end
  276.  
  277. function TS_ClickMenu(x, y, enemyTeam)
  278.     assert(type(x) == "number" and type(y) == "number", "TS__DrawMenu: wrong argument types (<number>, <number> expected)")
  279.     _TS_Draw_Init()
  280.     local enemyTeam = (enemyTeam ~= false)
  281.     local y1 = y
  282.     for index,_gameHero in ipairs(_gameHeros) do
  283.         if _gameHero.enemy == enemyTeam then
  284.             if CursorIsUnder(x + _TS_Draw.row2, y1, _TS_Draw.fontSize, _TS_Draw.fontSize) then
  285.                 TS_SetHeroPriority(math.max(1, _gameHero.priority - 1), index)
  286.             elseif CursorIsUnder(x + _TS_Draw.row3, y1, _TS_Draw.fontSize, _TS_Draw.fontSize) then
  287.                 TS_SetHeroPriority(math.min((enemyTeam and _gameEnemyCount or _gameAllyCount), _gameHero.priority + 1), index)
  288.             elseif CursorIsUnder(x + _TS_Draw.row4, y1, _TS_Draw.fontSize, _TS_Draw.fontSize) then TS_Ignore(index) end
  289.             y1 = y1 + _TS_Draw.cellSize
  290.         end
  291.     end
  292.     return y1
  293. end
  294.  
  295. function TargetSelector__OnSendChat(msg)
  296.     if msg:sub(1,3) ~= ".ts" then return end
  297.     BlockChat()
  298.     local args = {}
  299.     while string.find(msg," ") do
  300.         local index = string.find(msg," ")
  301.         table.insert(args, msg:sub(1,index-1))
  302.         msg = string.sub(msg,index+1)
  303.     end
  304.     table.insert(args, msg)
  305.     local cmd = args[1]:lower()
  306.     if cmd == ".tsprint" then
  307.         TS_Print()
  308.     elseif cmd == ".tsprinta" then
  309.         TS_Print(false)
  310.     elseif cmd == ".tsfocus" then
  311.         PrintChat(cmd.." - "..args[2])
  312.         TS_SetFocus(args[2])
  313.     elseif cmd == ".tsfocusa" then
  314.         TS_SetFocus(args[2], false)
  315.     elseif cmd == ".tspriorityhero" then
  316.         TS_SetHeroPriority(args[2], args[3])
  317.     elseif cmd == ".tspriorityheroa" then
  318.         TS_SetHeroPriority(args[2], args[3], false)
  319.     elseif cmd == ".tspriority" then
  320.         TS_SetPriority(args[2], args[3], args[4], args[5], args[6])
  321.     elseif cmd == ".tsprioritya" then
  322.         TS_SetPriorityA(args[2], args[3], args[4], args[5], args[6])
  323.     elseif cmd == ".tsignore" then
  324.         TS_Ignore(args[2])
  325.     elseif cmd == ".tsignorea" then
  326.         TS_Ignore(args[2], false)
  327.     end
  328. end
  329.  
  330. class 'TargetSelector'
  331. function TargetSelector:__init(mode, range, damageType, targetSelected, enemyTeam)
  332.     -- Init Global
  333.     assert(type(mode) == "number" and type(range) == "number", "TargetSelector: wrong argument types (<mode>, <number> expected)")
  334.     _gameHeros__init()
  335.     self.mode = mode
  336.     self.range = range
  337.     self._mDmgBase, self._pDmgBase, self._tDmg = 0, 0, 0
  338.     self._dmgType = damageType or DAMAGE_MAGIC
  339.     if self._dmgType == DAMAGE_MAGIC then self._mDmgBase = 100 else self._tDmg = player.totalDamage end
  340.     self.targetSelected = (targetSelected ~= false)
  341.     self.enemyTeam = (enemyTeam ~= false)
  342.     self.target = nil
  343.     self._conditional = nil
  344.     self._spellWidth = nil
  345.     self._pDelay = nil
  346. end
  347.  
  348. function TargetSelector:printMode()
  349.     PrintChat("[TS] Target mode: " .._TargetSelector__texted[self.mode])
  350. end
  351.  
  352. function TargetSelector:SetDamages(magicDmgBase, physicalDmgBase, trueDmg)
  353.     assert(magicDmgBase == nil or type(magicDmgBase) == "number", "SetDamages: wrong argument types (<number> or nil expected) for magicDmgBase")
  354.     assert(physicalDmgBase == nil or type(physicalDmgBase) == "number", "SetDamages: wrong argument types (<number> or nil expected) for physicalDmgBase")
  355.     assert(trueDmg == nil or type(trueDmg) == "number", "SetDamages: wrong argument types (<number> or nil expected) for trueDmg")
  356.     self._dmgType = 0
  357.     self._mDmgBase = magicDmgBase or 0
  358.     self._pDmgBase = physicalDmgBase or 0
  359.     self._tDmg = trueDmg or 0
  360. end
  361.  
  362. function TargetSelector:SetMinionCollision(spellWidth)
  363.     assert(spellWidth == nil or type(spellWidth) == "number", "SetMinionCollision: wrong argument types (<number> or nil expected)")
  364.     self._spellWidth = ((spellWidth ~= nil or spellWidth > 0) and spellWidth or nil)
  365. end
  366.  
  367. function TargetSelector:SetPrediction(delay)
  368.     assert(delay == nil or type(delay) == "number", "SetPrediction: wrong argument types (<number> or nil expected)")
  369.     _Prediction__OnLoad()
  370.     self._pDelay = ((delay ~= nil and delay > 0) and delay or nil)
  371. end
  372.  
  373. function TargetSelector:SetProjectileSpeed(pSpeed)
  374.     assert(delay == nil or type(delay) == "number", "SetProjectileSpeed: wrong argument types (<number> or nil expected)")
  375.     _Prediction__OnLoad()
  376.     self._pSpeed = ((pSpeed ~= nil and pSpeed > 0) and pSpeed or nil)
  377. end
  378.  
  379. function TargetSelector:SetConditional(func)
  380.     assert (func == nil or type(func) == "function", "SetConditional : wrong argument types (<function> or nil expected)")
  381.     self._conditional = func
  382. end
  383.  
  384. function TargetSelector:_targetSelectedByPlayer()
  385.     if self.targetSelected then
  386.         local currentTarget = GetTarget()
  387.         if ValidTarget(currentTarget, self.range, self.enemyTeam) and (currentTarget.type == "obj_AI_Hero" or currentTarget.type == "obj_AI_Minion") and (self._conditional == nil or self._conditional(currentTarget)) then
  388.             if self.target == nil or self.target.networkID ~= currentTarget.networkID then
  389.                 self.target = currentTarget
  390.                 self.index = _gameHeros__index(currentTarget, "_targetSelectedByPlayer")
  391.             end
  392.             local delay = 0
  393.             if self._pDelay ~= nil and self._pDelay > 0 then
  394.                 delay = delay + self._pDelay
  395.             end
  396.             if self._pSpeed ~= nil and self._pSpeed > 0 then
  397.                 delay = delay + (GetDistance(currentTarget) / self._pSpeed)
  398.             end
  399.             if self.index and delay > 0 then
  400.                 self.nextPosition = _PredictionPosition(self.index, delay)
  401.                 self.nextHealth = _PredictionHealth(self.index, delay)
  402.             else
  403.                 self.nextPosition = Vector(currentTarget)
  404.                 self.nextHealth = currentTarget.health
  405.             end
  406.             return true
  407.         end
  408.     end
  409.     return false
  410. end
  411.  
  412. function TargetSelector:update()
  413.     -- Resets the target if player died
  414.     if player.dead then
  415.         self.target = nil
  416.         return
  417.     end
  418.     -- Get current selected target (by player) if needed
  419.     if self:_targetSelectedByPlayer() then return end
  420.     local selected, index, value, nextPosition, nextHealth
  421.     local range = (self.mode == TARGET_NEAR_MOUSE and 2000 or self.range)
  422.     for i, _gameHero in ipairs(_gameHeros) do
  423.         local hero = _gameHero.hero
  424.         if ValidTarget(hero, range, self.enemyTeam) and not _gameHero.ignore and (self._conditional == nil or self._conditional(hero, i)) then
  425.             local minionCollision = false
  426.             local delay = 0
  427.             if self._pDelay ~= nil and self._pDelay > 0 then
  428.                 delay = delay + self._pDelay
  429.             end
  430.             if self._pSpeed ~= nil and self._pSpeed > 0 then
  431.                 delay = delay + (GetDistance(hero) / self._pSpeed)
  432.             end
  433.             if delay > 0 then
  434.                 nextPosition = _PredictionPosition(i, delay)
  435.                 nextHealth = _PredictionHealth(i, delay)
  436.             else
  437.                 nextPosition, nextHealth = Vector(hero), hero.health
  438.             end
  439.             if self._spellWidth then minionCollision = GetMinionCollision(player, nextPosition, self._spellWidth) end
  440.             if GetDistance(nextPosition) <= range and minionCollision == false then
  441.                 if self.mode == TARGET_LOW_HP or self.mode == TARGET_LOW_HP_PRIORITY or self.mode == TARGET_LESS_CAST or self.mode == TARGET_LESS_CAST_PRIORITY then
  442.                 -- Returns lowest effective HP target that is in range
  443.                 -- Or lowest cast to kill target that is in range
  444.                     if self._dmgType == DAMAGE_PHYSICAL then self._pDmgBase = player.totalDamage end
  445.                     local mDmg = (self._mDmgBase > 0 and player:CalcMagicDamage(hero, self._mDmgBase) or 0)
  446.                     local pDmg = (self._pDmgBase > 0 and player:CalcDamage(hero, self._pDmgBase) or 0)
  447.                     local totalDmg = mDmg + pDmg + self._tDmg
  448.                     -- priority mode
  449.                     if self.mode == TARGET_LOW_HP_PRIORITY or self.mode == TARGET_LESS_CAST_PRIORITY then
  450.                         totalDmg = totalDmg / _gameHero.priority
  451.                     end
  452.                     local heroValue
  453.                     if self.mode == TARGET_LOW_HP or self.mode == TARGET_LOW_HP_PRIORITY then
  454.                         heroValue = hero.health - totalDmg
  455.                     else
  456.                         heroValue = hero.health / totalDmg
  457.                     end
  458.                     if not selected or heroValue < value then selected, index, value = hero, i, heroValue end
  459.                 elseif self.mode == TARGET_MOST_AP then
  460.                 -- Returns target that has highest AP that is in range
  461.                     if not selected or hero.ap > selected.ap then selected, index = hero, i end
  462.                 elseif self.mode == TARGET_MOST_AD then
  463.                 -- Returns target that has highest AD that is in range
  464.                     if not selected or hero.totalDamage > selected.totalDamage then selected, index = hero, i end
  465.                 elseif self.mode == TARGET_PRIORITY then
  466.                 -- Returns target with highest priority # that is in range
  467.                     if not selected or _gameHero.priority < value then selected, index, value = hero, i, _gameHero.priority end
  468.                 elseif self.mode == TARGET_NEAR_MOUSE then
  469.                 -- Returns target that is the closest to the mouse cursor.
  470.                     local distance = GetDistance(mousePos, hero)
  471.                     if not selected or distance < value then selected, index, value = hero, i, distance end
  472.                 end
  473.             end
  474.         end
  475.     end
  476.     self.index = index
  477.     self.target = selected
  478.     self.nextPosition = nextPosition
  479.     self.nextHealth = nextHealth
  480. end
  481.  
  482. function TargetSelector:OnSendChat(msg, prefix)
  483.     assert(type(prefix) == "string" and prefix ~= "" and prefix:lower() ~= "ts", "TS OnSendChat: wrong argument types (<string> (not TS) expected for prefix)")
  484.     if msg:sub(1,1) ~= "." then return end
  485.     local prefix = prefix:lower()
  486.     local length = prefix:len() + 1
  487.     if msg:sub(1,length) ~= "."..prefix then return end
  488.     BlockChat()
  489.     local args = {}
  490.     while string.find(msg," ") do
  491.         local index = string.find(msg," ")
  492.         table.insert(args, msg:sub(1,index-1))
  493.         msg = msg:sub(index+1)
  494.     end
  495.     table.insert(args, msg)
  496.     local cmd = args[1]:lower()
  497.     if cmd == "."..prefix.."mode" then
  498.         assert(args[2] ~= nil, "TS OnSendChat: wrong argument types (LowHP, MostAP, MostAD, LessCast, NearMouse, Priority, LowHPPriority, LessCastPriority expected)")
  499.         local index = 0
  500.         for i, mode in ipairs({"LowHP", "MostAP", "MostAD", "LessCast", "NearMouse", "Priority", "LowHPPriority", "LessCastPriority"}) do
  501.             if mode:lower() == args[2]:lower() then
  502.                 index = i
  503.                 break
  504.             end
  505.         end
  506.         assert(index ~= 0, "TS OnSendChat: wrong argument types (LowHP, MostAP, MostAD, LessCast, NearMouse, Priority, LowHPPriority, LessCastPriority expected)")
  507.         self.mode = index
  508.         self:printMode()
  509.     end
  510. end
  511.  
  512. function TargetSelector:DrawMenu(x, y)
  513.     assert(type(x) == "number" and type(y) == "number", "ts:DrawMenu: wrong argument types (<number>, <number> expected)")
  514.     _TS_Draw_Init()
  515.     DrawLine(x - _TS_Draw.border, y + _TS_Draw.midSize, x + _TS_Draw.row3 - _TS_Draw.border, y + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.background)
  516.     DrawText((self.name or "ts").." Mode : ".._TargetSelector__texted[self.mode], _TS_Draw.fontSize, x, y, _TS_Draw.textColor)
  517.     DrawLine(x + _TS_Draw.row3, y + _TS_Draw.midSize, x + _TS_Draw.row4 - _TS_Draw.border, y + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.blueColor)
  518.     DrawText( "   <", _TS_Draw.fontSize, x + _TS_Draw.row3, y, _TS_Draw.textColor)
  519.     DrawLine(x + _TS_Draw.row4, y + _TS_Draw.midSize, x + _TS_Draw.width, y + _TS_Draw.midSize, _TS_Draw.cellSize, _TS_Draw.blueColor)
  520.     DrawText( "   >", _TS_Draw.fontSize, x + _TS_Draw.row4, y, _TS_Draw.textColor)
  521.     return y + _TS_Draw.cellSize
  522. end
  523.  
  524. function TargetSelector:ClickMenu(x, y)
  525.     assert(type(x) == "number" and type(y) == "number", "ts:ClickMenu: wrong argument types (<number>, <number>, <string> expected)")
  526.     _TS_Draw_Init()
  527.     if CursorIsUnder(x + _TS_Draw.row3, y, _TS_Draw.fontSize, _TS_Draw.fontSize) then
  528.         self.mode = (self.mode == 1 and #_TargetSelector__texted or self.mode - 1)
  529.     elseif CursorIsUnder(x + _TS_Draw.row4, y, _TS_Draw.fontSize, _TS_Draw.fontSize) then
  530.         self.mode = (self.mode == #_TargetSelector__texted and 1 or self.mode + 1)
  531.     end
  532.     return y + _TS_Draw.cellSize
  533. end
  534.  
  535. -- Prediction Functions
  536. --[[
  537. Globals Functions
  538. Prediction__OnTick()            -- OnTick()
  539. GetPredictionPos(iHero, delay)              -- return nextPosition in delay (ms) for iHero (index)
  540. GetPredictionPos(Hero, delay)               -- return nextPosition in delay (ms) for Hero
  541. GetPredictionPos(charName, delay, enemyTeam)        -- return nextPosition in delay (ms) for charName in enemyTeam (true/false, default true)
  542. GetPredictionHealth(iHero, delay)           -- return next Health in delay (ms) for iHero (index)
  543. GetPredictionHealth(Hero, delay)            -- return next Health in delay (ms) for Hero
  544. GetPredictionHealth(charName, delay, enemyTeam) -- return next Health in delay (ms) for charName in enemyTeam (true/false, default true)
  545.  
  546. ]]
  547. _Prediction = {init = true, delta = 1}
  548.  
  549. function _Prediction__OnLoad()
  550.     if _Prediction.init then
  551.         _gameHeros__init()
  552.         _Prediction.tick = GetTickCount()
  553.         for i, _gameHero in ipairs(_gameHeros) do
  554.             if _gameHero.hero ~= nil then
  555.                 _gameHero.pVector = Vector()
  556.                 _gameHero.lastPos = Vector(_gameHero.hero)
  557.                 _gameHero.pHealth = 0
  558.                 _gameHero.lastHealth = _gameHero.hero.health
  559.             end
  560.         end
  561.         _Prediction.init = nil
  562.     end
  563. end
  564.  
  565. function _PredictionPosition(iHero, delay)
  566.     local _gameHero = _gameHeros[iHero]
  567.     if _gameHero and VectorType(_gameHero.pVector) and VectorType(_gameHero.lastPos) then
  568.         local heroPosition = _gameHero.lastPos + (_gameHero.pVector * (_Prediction.delta * delay))
  569.         heroPosition.y = _gameHero.hero.y
  570.         return heroPosition
  571.     end
  572. end
  573.  
  574. function _PredictionHealth(iHero, delay)
  575.     local _gameHero = _gameHeros[iHero]
  576.     if _gameHero and _gameHero.pHealth ~= nil and _gameHero.lastHealth ~= nil then
  577.         return _gameHero.lastHealth + (_gameHero.pHealth * (_Prediction.delta * delay))
  578.     end
  579. end
  580.  
  581. function Prediction__OnTick()
  582.     _Prediction__OnLoad()
  583.     local tick = GetTickCount()
  584.     _Prediction.delta = 1 / (tick - _Prediction.tick)
  585.     _Prediction.tick = tick
  586.     for i, _gameHero in ipairs(_gameHeros) do
  587.         if _gameHero.hero ~= nil and _gameHero.hero.dead == false and _gameHero.hero.visible then
  588.             _gameHero.pVector = ( Vector(_gameHero.hero) - _gameHero.lastPos )
  589.             _gameHero.lastPos = Vector(_gameHero.hero)
  590.             _gameHero.pHealth = _gameHero.hero.health - _gameHero.lastHealth
  591.             _gameHero.lastHealth = _gameHero.hero.health
  592.         end
  593.     end
  594. end
  595.  
  596. function GetPredictionPos(target, delay, enemyTeam)
  597.     local enemyTeam = (enemyTeam ~= false)
  598.     local iHero = _gameHeros__index(target, "GetPredictionPos", enemyTeam)
  599.     return _PredictionPosition(iHero, delay)
  600. end
  601.  
  602. function GetPredictionHealth(target, delay, enemyTeam)
  603.     local enemyTeam = (enemyTeam ~= false)
  604.     local iHero = _gameHeros__index(target, "GetPredictionHealth", enemyTeam)
  605.     return _PredictionHealth(iHero, delay)
  606. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top