Guest User

Untitled

a guest
Jun 26th, 2013
2,849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.87 KB | None | 0 0
  1. --[[
  2. Veigar's Super FunHouse! 3.7c~ by llama
  3.  
  4.  
  5.                 Required Libraries:
  6.                 comboLib
  7. ]]
  8.  
  9.  
  10. if myHero.charName ~= "Veigar" then return end
  11. function OnLoad()
  12.     player = myHero
  13.  
  14.     --HotKeys
  15.  
  16.     EHK = string.byte("E") --HK for "E" by default. Auto stun up to 2 targets.
  17.     cageTeamHK = string.byte("G") -- hk for "G" by default. Cage enemy team in event horizon.
  18.     spaceHK = 32 --hk for "spacebar" by default.
  19.     fullComboHK = string.byte("X")
  20.     autoQMinionHK = 118 --hk for "F7"
  21.  
  22.     --Options
  23.     comboTimeout = 3000
  24.  
  25.     eCircleColor = 0xB820C3 -- purple by default
  26.     wCircleColor = 0xEA3737 -- orange by default
  27.     qCircleColor = 0x19A712 --green by default
  28.  
  29.     circleRadius = 100 --radius of circle drawn
  30.     circleThickness = 10 --Higher means more vibrant circle. More cpu usage.
  31.  
  32.     --Skill attributes
  33.     qrange = 650
  34.  
  35.     wrange = 890
  36.     wradius = 230 --maximum radius of W
  37.  
  38.     eradius = 350 -- event horizon's radius has bounds from 300 to 400
  39.     erange = 600
  40.     ecastspeed = 340 --(ms) calculated from tick values before and after cast of even horizon
  41.  
  42.     --code
  43.  
  44.     --require"comboLib-Before Edit"
  45.     require"comboLib"
  46.     stealTarget = nil
  47.     comboArray = {}
  48.     oldname = "default"
  49.     timeoutTick = 0
  50.     requiresW = false
  51.     eTarget = nil
  52.  
  53.     VeigarConfig = scriptConfig("Veigar Combo", "veigarcombo")
  54.     VeigarConfig:addParam("spacebarActive", "Combo", SCRIPT_PARAM_ONKEYDOWN, false, spaceHK)
  55.     VeigarConfig:addParam("useStunWithSpace", "Use Stun with Combo", SCRIPT_PARAM_ONOFF, true)
  56.     VeigarConfig:addParam("fullCombo", "Full Combo", SCRIPT_PARAM_ONKEYDOWN, false, fullComboHK)
  57.     VeigarConfig:addParam("eCastActive", "E+W", SCRIPT_PARAM_ONKEYDOWN, false, EHK)
  58.     VeigarConfig:addParam("cageTeamActive", "Cage Team", SCRIPT_PARAM_ONKEYDOWN, false, cageTeamHK)
  59.     VeigarConfig:addParam("autoQMinions", "Toggle Auto-Q Minion (F7)", SCRIPT_PARAM_ONKEYTOGGLE, false, autoQMinionHK)
  60.     VeigarConfig:addParam("stealOption", "Steal on Killable", SCRIPT_PARAM_ONOFF, false)
  61.     VeigarConfig:addParam("stunWithStealOption", "Use Stun with Steal", SCRIPT_PARAM_ONOFF, true)
  62.     VeigarConfig:addParam("drawKillable", "Draw Killable", SCRIPT_PARAM_ONOFF, true)
  63.     VeigarConfig:addParam("drawQRange", "Draw Q Range", SCRIPT_PARAM_ONOFF, true)
  64.     VeigarConfig:addParam("drawWRange", "Draw W Range", SCRIPT_PARAM_ONOFF, true)
  65.     VeigarConfig:addParam("drawERange", "Draw E Range", SCRIPT_PARAM_ONOFF, true)
  66.     VeigarConfig:permaShow("autoQMinions")
  67.     VeigarConfig:permaShow("stealOption")
  68.  
  69.     ts = TargetSelector(TARGET_LOW_HP, erange + eradius, DAMAGE_MAGIC)
  70.     ts.name = "Veigar"
  71.  
  72.     VeigarConfig:addTS(ts)
  73.  
  74.     if VIP_USER then
  75.         tp = TargetPredictionVIP(erange + eradius, math.huge, ecastspeed / 1000)
  76.    else
  77.         tp = TargetPrediction(erange + eradius, math.huge, ecastspeed)
  78.     end
  79.  
  80.     function customE()
  81.         if myHero:CanUseSpell(_E) == READY then return true else return false end
  82.     end
  83.  
  84.  
  85.     fullCombo = { _Q, _W, _R }
  86.     --combo 1 is the stun combo
  87.     comboLib:newSkill("Q", (wrange + wradius), 1)
  88.     comboLib:newSkill("DFG", (wrange + wradius), 1)
  89.     comboLib:newSkill("HXG", (wrange + wradius), 1)
  90.     comboLib:newSkill("BWC", (wrange + wradius), 1)
  91.     comboLib:newSkill("RUINEDKING", (wrange + wradius), 1)
  92.     comboLib:newSkill("TIAMAT", (wrange + wradius), 1)
  93.     comboLib:newSkill("HYDRA", (wrange + wradius), 1)
  94.     comboLib:newSkill("W", (wrange + wradius), 1, customE, true)
  95.     comboLib:newSkill("R", (wrange + wradius), 1)
  96.     comboLib:newSkill("ignite", (wrange + wradius), 1)
  97.     --global combo 3 for draw killable with stun
  98.  
  99.     comboLib:newSkill("Q", 30000, 3)
  100.     comboLib:newSkill("W", 30000, 3, customE, true)
  101.     comboLib:newSkill("DFG", 30000, 3)
  102.     comboLib:newSkill("BWC", 30000, 3)
  103.     comboLib:newSkill("RUINEDKING", 30000, 3)
  104.     comboLib:newSkill("TIAMAT", 30000, 3)
  105.     comboLib:newSkill("HYDRA", 30000, 3)
  106.     comboLib:newSkill("HXG", 30000, 3)
  107.     comboLib:newSkill("R", 30000, 3)
  108.     comboLib:newSkill("ignite", 30000, 3)
  109.     --global combo for draw killable without stun
  110.  
  111.     enemyMinions = minionManager(MINION_ENEMY, qrange, player, MINION_SORT_HEALTH_ASC)
  112.     PrintChat(" >>Veigar's Super FunHouse Loaded!")
  113. end
  114.  
  115. function GetDistanceTo(target1, target2)
  116.     local dis
  117.     if target2 ~= nil and target1 ~= nil then
  118.         dis = math.sqrt((target2.x - target1.x) ^ 2 + (target2.z - target1.z) ^ 2)
  119.     end
  120.     return dis
  121. end
  122.  
  123. function targetvalid(target)
  124.     return target ~= nil and target.team ~= player.team and target.visible and not target.dead and GetDistanceTo(player, target) <= (erange + eradius)
  125. end
  126.  
  127. function targetsinradius(target1, target2)
  128.     local dis, dis1, dis2, predicted1, predicted2
  129.     if VIP_USER then
  130.         predicted1 = tp:GetPrediction(target1)
  131.         predicted2 = tp:GetPrediction(target2)
  132.     else
  133.         predicted1 = GetPredictionPos(target1,ecastspeed + GetLatency()/2)
  134.         predicted2 = GetPredictionPos(target2,ecastspeed + GetLatency()/2)
  135.     end
  136.  
  137.     if predicted1 and predicted2 then
  138.         dis = math.sqrt((predicted2.x - predicted1.x) ^ 2 + (predicted2.z - predicted1.z) ^ 2) --find the distance between the two targets
  139.  
  140.         dis1 = math.sqrt((predicted1.x - player.x) ^ 2 + (predicted1.z - player.z) ^ 2) --distance from player to predicted target 1
  141.         dis2 = math.sqrt((predicted2.x - player.x) ^ 2 + (predicted2.z - player.z) ^ 2) --distance from player to predicted target 2
  142.     end
  143.  
  144.     return dis ~= nil and dis <= (eradius * 2) and dis1 <= (eradius + erange) and dis2 <= (eradius + erange)
  145. end
  146.  
  147. function calcdoublestun(target1, target2)
  148.  
  149.     local CircX, CircZ, predicted1, predicted2
  150.  
  151.     if VIP_USER then
  152.         predicted1 = tp:GetPrediction(target1)
  153.         predicted2 = tp:GetPrediction(target2)
  154.     else
  155.         predicted1 = GetPredictionPos(target1,ecastspeed + GetLatency()/2)
  156.         predicted2 = GetPredictionPos(target2,ecastspeed + GetLatency()/2)
  157.     end
  158.  
  159.     if predicted1 and predicted2 then
  160.  
  161.         local h1 = predicted1.x
  162.         local k1 = predicted1.z
  163.         local h2 = predicted2.x
  164.         local k2 = predicted2.z
  165.  
  166.         local u = (h1) ^ 2 + (h2) ^ 2 - 2 * (h1) * (h2) - (k1) ^ 2 + (k2) ^ 2
  167.         local w = k1 - k2
  168.         local v = h2 - h1
  169.  
  170.         local a = 4 * (w ^ 2 + v ^ 2)
  171.         local b = 4 * (u * w - 2 * ((v) ^ 2) * (k1))
  172.         local c = (u) ^ 2 - 4 * ((v ^ 2)) * (eradius ^ 2 - k1 ^ 2)
  173.  
  174.         local Z1 = ((-b) + math.sqrt((b) ^ 2 - 4 * a * c)) / (2 * a) --Z coord for first solution
  175.         local Z2 = ((-b) - math.sqrt((b) ^ 2 - 4 * a * c)) / (2 * a) --Z coord for second solution
  176.  
  177.         local d = (Z1 - k1) ^ 2 - (eradius) ^ 2
  178.         local e = (Z1 - k2) ^ 2 - (eradius) ^ 2
  179.  
  180.         local X1 = ((h2) ^ 2 - (h1) ^ 2 - d + e) / (2 * v) -- X Coord for first solution
  181.  
  182.         local p = (Z2 - k1) ^ 2 - (eradius) ^ 2
  183.         local q = (Z2 - k2) ^ 2 - (eradius) ^ 2
  184.  
  185.         local X2 = ((h2) ^ 2 - (h1) ^ 2 - p + q) / (2 * v) --X Coord for second solution
  186.  
  187.  
  188.         --determine if these 2 points are within range, and which is closest
  189.  
  190.         local dis1 = math.sqrt((X1 - player.x) ^ 2 + (Z1 - player.z) ^ 2)
  191.         local dis2 = math.sqrt((X2 - player.x) ^ 2 + (Z2 - player.z) ^ 2)
  192.  
  193.         if dis1 <= (eradius + erange) and dis1 <= dis2 then
  194.             CircX = X1
  195.             CircZ = Z1
  196.         end
  197.         if dis2 <= (eradius + erange) and dis2 < dis1 then
  198.             CircX = X2
  199.             CircZ = Z2
  200.         end
  201.     end
  202.     return CircX, CircZ
  203. end
  204.  
  205. function calcsinglestun()
  206.     if (ts.target ~= nil) and player:CanUseSpell(SPELL_3) == READY then
  207.         local predicted
  208.        if VIP_USER then
  209.             predicted = tp:GetPrediction(ts.target)
  210.         else
  211.             predicted = GetPredictionPos(ts.target,ecastspeed + GetLatency()/2)
  212.  
  213.        end
  214.  
  215.         if predicted then
  216.             local CircX, CircZ
  217.             local dis = math.sqrt((player.x - predicted.x) ^ 2 + (player.z - predicted.z) ^ 2)
  218.             CircX = predicted.x + eradius * ((player.x - predicted.x) / dis)
  219.             CircZ = predicted.z + eradius * ((player.z - predicted.z) / dis)
  220.             return CircX, CircZ
  221.         end
  222.     end
  223. end
  224.  
  225. function OnWndMsg(msg, wParam)
  226.     if msg == KEY_DOWN then
  227.         if wParam == autoQMinionHK then
  228.             if VeigarConfig.autoQMinions == true then
  229.                 PrintChat("Auto-Q Minions Enabled")
  230.             elseif VeigarConfig.autoQMinions == false then
  231.                 PrintChat("Auto-Q Minions Disabled")
  232.             end
  233.         end
  234.     end
  235. end
  236.  
  237. function castESpellOnTarget(object)
  238.  
  239.     if player:CanUseSpell(_E) then
  240.  
  241.         local target1 = object
  242.         local CircX, CircZ, returnTarget
  243.         local players = heroManager.iCount
  244.         for j = 1, players, 1 do
  245.  
  246.             local target2 = heroManager:getHero(j)
  247.             if targetvalid(target1) and targetvalid(target2) and target1.name ~= target2.name then --make sure both targets are valid enemies and in spell range
  248.                 if targetsinradius(target1, target2) and CircX == nil and CircZ == nil then --true if a double stun is possible
  249.  
  250.                     CircX, CircZ = calcdoublestun(target1, target2) --calculates coords for stun
  251.                     if CircX and CircZ then
  252.                         break
  253.                     end
  254.                 end
  255.             end
  256.         end
  257.  
  258.         if CircX == nil or CircZ == nil then --true if double stun coords were not found
  259.             if targetvalid(object) then
  260.                 CircX, CircZ = calcsinglestun() --calculate stun coords for a single target
  261.             end
  262.         end
  263.         if CircX and CircZ then --true if any coords were found
  264.             CastSpell(SPELL_3, CircX, CircZ)
  265.         end
  266.     end
  267. end
  268.  
  269. function useStunCombo(object)
  270.     local spellPos
  271.     if player:CanUseSpell(_E) == READY and not object.dead then
  272.         castESpellOnTarget(object)
  273.     end
  274.  
  275.     if player:CanUseSpell(_W) == READY and not object.dead then
  276.         if object and targetvalid(object) then
  277.             if object.canMove == false then
  278.                 spellPos = FindGroupCenterNearTarget(object, wradius, wrange)
  279.                 if spellPos then
  280.                     CastSpell(_W, spellPos.center.x, spellPos.center.z)
  281.                 else
  282.                     CastSpell(_W, object)
  283.                 end
  284.             end
  285.         end
  286.     end
  287. end
  288.  
  289. function hasW(array)
  290.  
  291.     local test
  292.     for i = 1, #array, 1 do
  293.         if array[i].skill == _W then
  294.             test = true
  295.         else
  296.             test = test or false
  297.         end
  298.     end
  299.      return test
  300. end
  301.  
  302. function performcombo(target, stealflag)
  303.  
  304.     local eComboFlag = false
  305.     if oldname ~= target.name or GetTickCount() > timeoutTick then --find NEW combo if target has changed(dead, out of range) or if all skills in previous combo were used.
  306.         comboArray = comboLib:findBestCombo(target, 1) --find combo
  307.         if comboArray == nil or #comboArray == 0 then --combo not found for target in range
  308.             requiresW = false
  309.             if stealflag == true then
  310.                 stealTarget = nil
  311.             end
  312.         elseif comboArray and #comboArray > 0 then --combo without stun worked!
  313.             requiresW = hasW(comboArray)
  314.             oldname = target.name
  315.             timeoutTick = GetTickCount() + comboTimeout
  316.         end
  317.     end
  318.     if comboArray and #comboArray > 0 then
  319.  
  320.         if requiresW and player:CanUseSpell(_W) == READY and ((VeigarConfig.spacebarActive and VeigarConfig.useStunWithSpace) or (VeigarConfig.stealOption and VeigarConfig.spacebarActive == false and VeigarConfig.stunWithStealOption)) then
  321.             useStunCombo(target)
  322.         else
  323.             eComboFlag = true --E+W has been used
  324.         end
  325.  
  326.         if eComboFlag == true then
  327.             for i = 1, #comboArray, 1 do
  328.                 if player:CanUseSpell(comboArray[i].skill) == READY and comboArray[i].name ~= "W" then
  329.                     CastSpell(comboArray[i].skill, target)
  330.                 end
  331.             end
  332.         end
  333.     else
  334.         if VeigarConfig.spacebarActive and not VeigarConfig.fullCombo and player:CanUseSpell(_Q) == READY then
  335.             CastSpell(_Q, target)
  336.         end
  337.         if VeigarConfig.fullCombo and VeigarConfig.spacebarActive == false then
  338.             for i = 1, #fullCombo, 1 do
  339.                 if player:CanUseSpell(_W) == READY then
  340.                     useStunCombo(target)
  341.                 else
  342.                     eComboFlag = true
  343.                 end
  344.                 if eComboFlag == true then
  345.                     for i = 1, #fullCombo, 1 do
  346.                         if player:CanUseSpell(fullCombo[i]) == READY and fullCombo[i] ~= _W then
  347.                             CastSpell(fullCombo[i], target)
  348.                         end
  349.                     end
  350.                 end
  351.             end
  352.         end
  353.     end
  354.     if stealflag == true and not targetvalid(target) then
  355.         stealTarget = nil
  356.     end
  357. end
  358.  
  359. function autoCastQ()
  360.  
  361.     for i = 1, #enemyMinions.objects do
  362.         local targetMinion = enemyMinions.objects[i]
  363.  
  364.         if ValidTarget(targetMinion, qrange) and string.find(targetMinion.name, "Minion_") then
  365.             if targetMinion.health < player:CalcMagicDamage(targetMinion, 45 * (player:GetSpellData(_Q).level - 1) + 80 + (.6 * player.ap)) then
  366.                 CastSpell(_Q, targetMinion)
  367.             end
  368.         end
  369.     end
  370. end
  371.  
  372. function OnDraw()
  373.     local players, drawtarget
  374.     local requiresW = false
  375.     local drawComboArray
  376.  
  377.     if not player.dead then
  378.  
  379.         if VeigarConfig.drawQRange == true then
  380.             DrawCircle(player.x, player.y, player.z, qrange, qCircleColor)
  381.         end
  382.         if VeigarConfig.drawWRange == true then
  383.             DrawCircle(player.x, player.y, player.z, wrange, wCircleColor)
  384.         end
  385.         if VeigarConfig.drawERange == true then
  386.             DrawCircle(player.x, player.y, player.z, erange + eradius, eCircleColor)
  387.         end
  388.  
  389.         if VeigarConfig.drawKillable == true then
  390.             players = heroManager.iCount
  391.             for i = 1, players, 1 do
  392.                 drawtarget = heroManager:getHero(i)
  393.                 if drawtarget ~= nil then
  394.                     if drawtarget.team ~= player.team and drawtarget.visible and not drawtarget.dead then
  395.  
  396.                         drawComboArray = comboLib:findBestCombo(drawtarget, 3)
  397.                         requiresW =  drawComboArray and hasW(drawComboArray)
  398.  
  399.                         if drawComboArray and #drawComboArray > 0 then
  400.                             for j = 0, circleThickness do
  401.                                 DrawCircle(drawtarget.x, drawtarget.y, drawtarget.z, circleRadius + j * 1.5, 0xFFFF0000)
  402.                             end
  403.                             if requiresW == true then
  404.                                 DrawCircle(drawtarget.x, drawtarget.y, drawtarget.z, 150, 0x00FFFF00)
  405.                             end
  406.                         end
  407.                     end
  408.                 end
  409.             end
  410.         end
  411.     end
  412. end
  413.  
  414. function OnTick()
  415.  
  416.     local players = heroManager.iCount
  417.     ts:update()
  418.  
  419.     enemyMinions:update()
  420.     --lp:tick()
  421.     if VeigarConfig.eCastActive == true and not player.dead and VeigarConfig.spacebarActive == false and VeigarConfig.cageTeamActive == false then
  422.         if eTarget then
  423.             if not targetvalid(eTarget) then
  424.                 eTarget = nil
  425.             end
  426.         end
  427.         if eTarget == nil then
  428.             if ts.target then
  429.                 eTarget = ts.target
  430.             else
  431.                 for i = 1, heroManager.iCount, 1 do
  432.                     local testTarget = heroManager:getHero(i)
  433.                     if targetvalid(testTarget) then
  434.                         eTarget = testTarget
  435.                     end
  436.                 end
  437.             end
  438.         end
  439.  
  440.         if eTarget then
  441.             useStunCombo(eTarget)
  442.         end
  443.     end
  444.  
  445.  
  446.     if (VeigarConfig.spacebarActive == true or VeigarConfig.fullCombo == true) and targetvalid(ts.target) and ts.target.bMagicImunebMagicImune ~= true and ts.target.bInvulnerable ~= true and not player.dead and VeigarConfig.eCastActive == false and VeigarConfig.cageTeamActive == false then
  447.         performcombo(ts.target, false)
  448.     end
  449.  
  450.  
  451.     if VeigarConfig.stealOption == true and not player.dead and VeigarConfig.spacebarActive == false and VeigarConfig.eCastActive == false and VeigarConfig.cageTeamActive == false then
  452.         if stealTarget == nil then
  453.             for i = 1, players, 1 do
  454.                 local testTarget = heroManager:getHero(i)
  455.                 if targetvalid(testTarget) and testTarget.bMagicImunebMagicImune ~= true and testTarget.bInvulnerable ~= true then
  456.                     stealTarget = testTarget
  457.                     performcombo(stealTarget, true)
  458.                 end
  459.             end
  460.         else
  461.             performcombo(stealTarget, true)
  462.         end
  463.     end
  464.  
  465.  
  466.     if VeigarConfig.cageTeamActive == true and ts.target ~= nil and not player.dead then
  467.         local spellPos = FindGroupCenterFromNearestEnemies(eradius, erange)
  468.         if spellPos ~= nil then
  469.  
  470.             CastSpell(SPELL_3, spellPos.center.x, spellPos.center.z)
  471.         end
  472.     end
  473.  
  474.  
  475.     if VeigarConfig.autoQMinions == true and not player.dead then
  476.         autoCastQ()
  477.     end
  478. end
  479.  
  480. class'Circle'
  481. function Circle:__init(center, radius)
  482.     assert((VectorType(center) or center == nil) and (type(radius) == "number" or radius == nil), "Circle: wrong argument types (expected <Vector> or nil, <number> or nil)")
  483.     self.center = Vector(center) or Vector()
  484.     self.radius = radius or 0
  485. end
  486.  
  487. function Circle:Contains(v)
  488.     assert(VectorType(v), "Contains: wrong argument types (expected <Vector>)")
  489.     return math.close(self.center:dist(v), self.radius)
  490. end
  491.  
  492. function Circle:__tostring()
  493.     return "{center: " .. tostring(self.center) .. ", radius: " .. tostring(self.radius) .. "}"
  494. end
Advertisement
Add Comment
Please, Sign In to add comment