Kain2030

Auto Carry Plugin - Lucian Edition - v1.05d Beta

Aug 22nd, 2013
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.45 KB | None | 0 0
  1. --[[
  2.  
  3.         Auto Carry Plugin - Lucian Edition
  4.         Author: Kain
  5.         Version: 1.05d Beta
  6.         Copyright 2013
  7.  
  8.         Dependency: Sida's Auto Carry: Revamped
  9.  
  10.         How to install:
  11.             Make sure you already have AutoCarry installed.
  12.             Name the script EXACTLY "SidasAutoCarryPlugin - Lucian.lua" without the quotes.
  13.             Place the plugin in BoL/Scripts/Common folder.
  14.        
  15.         Version History:
  16.             Version: 1.05 Pre-Release:
  17.                 Fixing issues with Ultimate ending early.
  18.             Version: 1.04 Beta Pre-Release: http://pastebin.com/ayEX5Bfq
  19.                 Culling Lockon added. Considered experimental, but seems to be working pretty well.
  20.             Version: 1.02 Beta Pre-Release: http://pastebin.com/tXxr95g9
  21.             Version: 1.0 Alpha: http://pastebin.com/xWbRz89K
  22. --]]
  23.  
  24. if myHero.charName ~= "Lucian" then return end
  25.  
  26. local Target
  27.  
  28. -- Prediction
  29.  
  30. -- Confirm ranges on release.
  31. local QRange = 550
  32. local QMaxRange = 1100
  33. local WRange = 1000
  34. local ERange = 425
  35. local RRange = 1400
  36.  
  37. local QSpeed = 19.346
  38. local WSpeed = 1.009
  39. local ESpeed = 3.867
  40. local RSpeed = 1.3
  41.  
  42. local QWidth = 250
  43. local WWidth = 250
  44. local EWidth = 250
  45. local RWidth = 250
  46.  
  47. local QDelay = 405
  48. local WDelay = 256
  49. local EDelay = 1070
  50. local RDelay = 143
  51.  
  52. local RRefresh = 0.1
  53. local RDuration = 3.2 -- Old: 3.0 2.871 - 3.167
  54.  
  55. local RParticleProjectileName = "Lucian_R_mis.troy"
  56. local RParticleProjectileNameOld = "bowMaster_volley_mis.troy"
  57. local RParticle = "Lucian_R_tar.troy"
  58. local RParticleFiring = "Lucian_R_self.troy"
  59.  
  60. local PursuitMinMouseDiff = 500
  61.  
  62. local SkillQ = {spellKey = _Q, range = QRange, speed = QSpeed, delay = QDelay, width = QWidth, configName = "piercinglight", displayName = "Q (Piercing Light)", enabled = true, skillShot = true, minions = false, reset = false, reqTarget = true }
  63. local SkillW = {spellKey = _W, range = WRange, speed = WSpeed, delay = WDelay, width = WWidth, configName = "ardentblaze", displayName = "W (Ardent Blaze)", enabled = true, skillShot = true, minions = false, reset = false, reqTarget = false }
  64. local SkillE = {spellKey = _E, range = ERange, speed = ESpeed, delay = EDelay, width = EWidth, configName = "relentlesspursuit", displayName = "E (Relentless Pursuit)", enabled = true, skillShot = true, minions = false, reset = false, reqTarget = false }
  65. local SkillR = {spellKey = _R, range = RRange, speed = RSpeed, delay = RDelay, width = RWidth, configName = "theculling", displayName = "R (The Culling)", enabled = true, skillShot = true, minions = false, reset = false, reqTarget = true }
  66.  
  67. local KeyQ = string.byte("Q")
  68. local KeyW = string.byte("W")
  69. local KeyE = string.byte("E")
  70. local KeyR = string.byte("R")
  71.  
  72. local KeyTest = string.byte("U")
  73.  
  74. local DFGSlot, HXGSlot, BWCSlot, SheenSlot, TrinitySlot, LichBaneSlot = nil, nil, nil, nil, nil, nil
  75. local QReady, WReady, EReady, RReady, DFGReady, HXGReady, BWCReady, IReady = false, false, false, false, false, false, false, false
  76.  
  77. local ultCastTick = 0
  78. local ultCastTarget = nil
  79. local ultVectorX = nil
  80. local ultVectorZ = nil
  81.  
  82. local isUltFiring = false
  83. local lastUltMessage = 0
  84.  
  85. local debugMode = false
  86. local debugModeDisableNonR = false
  87.  
  88. function PluginOnLoad()
  89.     Menu()
  90.  
  91.     AutoCarry.SkillsCrosshair.range = QMaxRange
  92. end
  93.  
  94. function Menu()
  95. --  AutoCarry.PluginMenu:addParam("fullcombo", "Full Combo", SCRIPT_PARAM_ONKEYDOWN, false, string.byte("Z"))
  96.     AutoCarry.PluginMenu:addParam("Harass", "Harass", SCRIPT_PARAM_ONKEYDOWN, false, string.byte("A"))
  97.     AutoCarry.PluginMenu:addParam("AutoHarass", "Auto Harass", SCRIPT_PARAM_ONOFF, false)
  98.     AutoCarry.PluginMenu:addParam("UseE", "Pursuit in Combo", SCRIPT_PARAM_ONOFF, true)
  99.     AutoCarry.PluginMenu:addParam("Ultimate", "Use Ultimate with Combo", SCRIPT_PARAM_ONOFF, true)
  100.     AutoCarry.PluginMenu:addParam("Killsteal", "Killsteal (Disabled until BoL update)", SCRIPT_PARAM_ONOFF, true)
  101.     AutoCarry.PluginMenu:addParam("KillstealUlt", "Killsteal with Ult", SCRIPT_PARAM_ONOFF, false)
  102.     AutoCarry.PluginMenu:addParam("UltLockOn", "Use Ultimate Lock On (Beta)", SCRIPT_PARAM_ONOFF, true)
  103.     AutoCarry.PluginMenu:addParam("Draw", "Draw range circles", SCRIPT_PARAM_ONOFF, true)
  104. end
  105.  
  106. function PluginOnTick()
  107.     Target = AutoCarry.GetAttackTarget(true)
  108.  
  109.     SpellCheck()
  110.  
  111.     -- GetTickCount() % 5 == 0) and
  112.     if math.fmod(GetTickCount(), 25) and IsFiringUlt() then
  113.         CheckRPosition()
  114.     else
  115.         if (AutoCarry.MainMenu.AutoCarry or AutoCarry.MainMenu.MixedMode) then
  116.             Combo()
  117.         end
  118.  
  119.     --[[   
  120.         if AutoCarry.PluginMenu.fullcombo then
  121.             FullCombo()
  122.         end
  123.     --]]
  124.  
  125.         if AutoCarry.PluginMenu.Harass then
  126.             Harass()
  127.         end
  128.  
  129.         if AutoCarry.PluginMenu.Killsteal then
  130.             KillSteal()
  131.         end
  132.     end
  133. end
  134.  
  135. function PluginOnCreateObj(obj)
  136.     -- Nothing to do here.
  137.     if obj.name == RParticleFiring then
  138.         if debugMode then PrintChat("Ult Particle Started") end
  139.         isUltFiring = true
  140.         if debugMode then PrintChat("start: "..GetTickCount()) end
  141.     end
  142. end
  143.  
  144. function PluginOnDeleteObj(obj)
  145.     if obj.name == RParticleFiring then
  146.         if debugMode then PrintChat("Ult Particle Stopped") end
  147.         isUltFiring = false
  148.         UltFireStop()
  149.         if debugMode then PrintChat("stop: "..GetTickCount()) end
  150.     end
  151. end
  152.  
  153. function OnAttacked()
  154.     -- AA > Q > AA
  155.     if AutoCarry.PluginMenu.AutoHarass then CastQ() end
  156. end
  157.  
  158. --[[
  159. function CustomAttackEnemy(enemy)
  160.         if enemy.dead or not enemy.valid then return end
  161.         -- myHero:Attack(enemy)
  162.         -- AutoCarry.shotFired = true
  163. end
  164. --]]
  165.  
  166. --[[
  167. function PluginOnGainBuff(unit, buff)
  168.     if unit.name == myHero.name and buff.name == "Lightslinger" and Target ~= nil then
  169.         myHero:Attack(Target)
  170.     end
  171. end
  172. --]]
  173.  
  174. function SpellCheck()
  175.     DFGSlot, HXGSlot, BWCSlot, BRKSlot, SheenSlot, TrinitySlot, LichBaneSlot = GetInventorySlotItem(3128),
  176.     GetInventorySlotItem(3146), GetInventorySlotItem(3144), GetInventorySlotItem(3153), GetInventorySlotItem(3057),
  177.     GetInventorySlotItem(3078), GetInventorySlotItem(3100)
  178.  
  179.     QReady = (myHero:CanUseSpell(SkillQ.spellKey) == READY)
  180.     WReady = (myHero:CanUseSpell(SkillW.spellKey) == READY)
  181.     EReady = (myHero:CanUseSpell(SkillE.spellKey) == READY)
  182.     RReady = (myHero:CanUseSpell(SkillR.spellKey) == READY)
  183.  
  184.     DFGReady = (DFGSlot ~= nil and myHero:CanUseSpell(DFGSlot) == READY)
  185.     HXGReady = (HXGSlot ~= nil and myHero:CanUseSpell(HXGSlot) == READY)
  186.     BWCReady = (BWCSlot ~= nil and myHero:CanUseSpell(BWCSlot) == READY)
  187.     BRKReady = (BRKSlot ~= nil and myHero:CanUseSpell(BRKSlot) == READY)
  188.  
  189.     IReady = (ignite ~= nil and myHero:CanUseSpell(ignite) == READY)
  190. end
  191.  
  192. -- Handle SBTW Skill Shots
  193.  
  194. function Combo()
  195.     if not debugModeDisableNonR then
  196.         CastSlots()
  197.         if AutoCarry.PluginMenu.UseE then CastE() end
  198.         CastQ()
  199.         CastW()
  200.     end
  201.  
  202.     if AutoCarry.PluginMenu.Ultimate then
  203.         CastR()
  204.     end
  205. end
  206.  
  207. function FullCombo()
  208.     CastSlots()
  209.     CastE()
  210.     CastQ()
  211.     CastW()
  212.     if AutoCarry.PluginMenu.Ultimate then
  213.         CastR()
  214.     end
  215. end
  216.  
  217. function CastSlots()
  218.     if Target ~= nil then
  219.         if GetDistance(Target) <= QRange then
  220.             if DFGReady then CastSpell(DFGSlot, Target) end
  221.             if HXGReady then CastSpell(HXGSlot, Target) end
  222.             if BWCReady then CastSpell(BWCSlot, Target) end
  223.             if BRKReady then CastSpell(BRKSlot, Target) end
  224.         end
  225.     end
  226. end
  227.  
  228.  
  229. function Harass()
  230.     CastQ()
  231. end
  232.  
  233. function CastQ(enemy)
  234.     -- Q (Piercing Light)
  235.     if not enemy then enemy = Target end
  236.  
  237.     if enemy ~= nil and QReady and ValidTarget(enemy, QRange) then
  238.         if debugMode then PrintChat("Cast Q") end
  239.         CastSpell(SkillQ.spellKey, enemy)
  240.     end
  241. end
  242.  
  243. function CastW(enemy)
  244.     -- W (Ardent Blaze)
  245.     if not enemy then enemy = Target end
  246.  
  247.     if enemy ~= nil and WReady and ValidTarget(enemy, WRange) then
  248.         if debugMode then PrintChat("Cast W") end
  249.         AutoCarry.CastSkillshot(SkillW, enemy)
  250.     end
  251. end
  252.  
  253. function CastE()
  254.     -- E (Relentless Pursuit)
  255.     if debugMode then
  256.         -- PrintChat("Mouse Distance: "..GetDistance(mousePos))
  257.     end
  258.  
  259.     if EReady then
  260.         -- if ( math.abs(mousePos.x - myHero.x) > PursuitMinMouseDiff or math.abs(mousePos.z - myHero.z) > PursuitMinMouseDiff) then
  261.         if ((GetDistance(mousePos) > PursuitMinMouseDiff) and isEnemyInRange(SkillE.range + SkillR.range)) then
  262.             if debugMode then PrintChat("Cast E") end
  263.             CastSpell(SkillE.spellKey, mousePos.x, mousePos.z)
  264.         end
  265.     end
  266. end
  267.  
  268. function CastR(enemy)
  269.     if not enemy then enemy = Target end
  270.     -- R (The Culling)
  271.     if enemy ~= nil and RReady and ValidTarget(enemy, RRange) then
  272.         if not IsFiringUlt() then
  273.             if debugMode then PrintChat("Cast R") end
  274.             if not isUltFiring then
  275.                 AutoCarry.CastSkillshot(SkillR, enemy)
  276.                 if AutoCarry.PluginMenu.UltLockOn and GetTickCount() > (lastUltMessage + 2000) then
  277.                     lastUltMessage = GetTickCount()
  278.                     PrintFloatText(myHero, 10, "Ultimate Locked On!")
  279.                 end
  280.             end
  281.  
  282.             ultCastTarget = enemy
  283.             ultCastTick = GetTickCount()
  284.  
  285.             -- Vector from target -> myHero
  286.             if ultVectorX == nil and ultVectorZ == nil then
  287.                 if debugMode and false then PrintChat("update x,z") end
  288.                 ultVectorX,y,ultVectorZ = (Vector(myHero) - Vector(ultCastTarget)):normalized():unpack()
  289.             end
  290.         end
  291.  
  292.         CheckRPosition()
  293.     end
  294. end
  295.  
  296. function CheckRPosition()
  297.     if (ultCastTick > 0) then
  298.         if debugMode and IsFiringUlt() then burp = "true" else burp = "false" end
  299.         if debugMode and false then PrintChat("Tick: "..GetTickCount()..", ultCastTick: "..ultCastTick..", RDuration: "..(ultCastTick + (RDuration * 1000))..", IsFiringUlt: "..burp) end
  300.     end
  301.  
  302.     if AutoCarry.PluginMenu.UltLockOn and IsFiringUlt() then
  303.         MoveMyHeroToRPosition()
  304.     end
  305. end
  306.  
  307. function MoveMyHeroToRPosition()
  308.     -- Please don't steal this function!
  309.     local tpR = VIP_USER and TargetPredictionVIP(RRange, RSpeed*1000, RRefresh, RWidth) or TargetPrediction(RRange, RSpeed, RRefresh*1000, RWidth)
  310.  
  311.     local target = nil
  312.     if ultCastTarget ~= nil then
  313.         target = ultCastTarget
  314.     else
  315.         target = Target
  316.     end
  317.  
  318.     local predR = tpR:GetPrediction(target)
  319.  
  320.     if not predR then return end
  321.  
  322.     local RRangeBuffered = RRange * .98 -- Allow a bit of slippage for targets running away.
  323.     local posX = predR.x + (ultVectorX * RRangeBuffered)
  324.     local posZ = predR.z + (ultVectorZ * RRangeBuffered)
  325.  
  326.     -- Thank you, Pythagoras
  327.     -- local distanceBetweenPoints = math.sqrt((predR.x - posX)^2 + (predR.z - posZ)^2)
  328.     -- local distanceBetweenPoints = GetDistance(Point(posX, posZ), predR)
  329.     -- local posXRanged = (posX + (posX - predR.x)) / distanceBetweenPoints * RRangeBuffered
  330.     -- local posZRanged = (posZ + (posZ - predR.z)) / distanceBetweenPoints * RRangeBuffered
  331.  
  332.     local predRPath = LineSegment(Point(predR.x, predR.z), Point(posX, posZ))
  333.  
  334.     local closestPoint = nil
  335.     if predRPath ~= nil then
  336.         closestPoint = Point(myHero.x, myHero.z):closestPoint(predRPath)
  337.     else
  338.         if debugMode then PrintChat("predRPath is nil") end
  339.     end
  340.  
  341.     if debugMode and closestPoint ~= nil then
  342.         --  PrintChat("moveto: "..posX..", "..posZ.."... targetat: "..ultCastTarget.x..", "..ultCastTarget.z..", ultVectorX: "..ultVectorX..", ultVectorZ: "..ultVectorZ..", RDuration: "..RDuration)
  343.         --  PrintChat("posXRanged: "..posXRanged..", posZRanged: "..posZRanged..", closestPoint: "..closestPoint.x..", "..closestPoint.y)
  344.         PrintChat("moveto: "..closestPoint.x..", "..closestPoint.y.."; targetat: "..predR.x..", "..predR.z..", ultVectorX: "..ultVectorX..", ultVectorZ: "..ultVectorZ)
  345.     end
  346.  
  347.     if debugMode then
  348.         PrintChat("distance: method 1: "..GetDistance(closestPoint, predR)..", method 2: "..GetDistance(Point(posX, posZ), predR))
  349.     end
  350.  
  351.     if predRPath ~= nil and closestPoint ~= nil and not IsWall(D3DXVECTOR3(closestPoint.x, myHero.y, closestPoint.y)) and GetDistance(closestPoint, predR) > ERange then
  352.         -- Closest Point Method
  353.         if debugMode then PrintChat("Move: Method 1") end
  354.         myHero:MoveTo(closestPoint.x, closestPoint.y)
  355.     elseif predR ~= nil and posX ~= nil and posZ ~= nil and not IsWall(D3DXVECTOR3(posX, myHero.y, posZ))
  356.         -- and GetDistance(Point(posX, posZ), predR) > 500
  357.         and GetDistance(Point(posX, posZ), predR) < RRange and GetDistance(Point(posX, posZ), predR) > 100 then
  358.         -- Full Vector Method
  359.         if debugMode then PrintChat("Move: Method 2") end
  360.         if (GetTickCount() > (lastUltMessage + 2000)) then
  361.             -- lastUltMessage = GetTickCount()
  362.             -- PrintFloatText(myHero, 10, "Ultimate Manual Mode!")
  363.         end
  364.         myHero:MoveTo(posX, posZ)
  365. --  elseif not IsWall(D3DXVECTOR3(posXRanged, myHero.y, posZRanged)) then
  366. --      -- Last Ditch Method
  367. --      if debugMode then PrintChat("Move: Method 3") end
  368. --      myHero:MoveTo(posXRanged, posZRanged)
  369.     else
  370.         -- Fallback to User Aiming
  371.         if debugMode then PrintChat("Move: Wall") end
  372.         myHero:MoveTo(mousePos.x, mousePos.z)
  373.     end
  374.     -- myHero:MoveTo(posXRanged, posZRanged)
  375. end
  376.  
  377. function getDistanceBetweenPoints(pointA, pointB)
  378.     -- Thank you, Pythagoras
  379.     local distanceBetweenPoints = math.sqrt((predR.x - posX)^2 + (predR.z - posZ)^2)
  380. end
  381.  
  382. function IsFiringUlt()
  383.     local tickCount = GetTickCount()
  384.  
  385.     -- if (ultCastTick > 0) and (tickCount >= ultCastTick) and (tickCount <= (ultCastTick + (RDuration * 1000))) and not RReady and ultCastTarget ~= nil and not ultCastTarget.dead then
  386.     if (ultCastTick > 0) and (tickCount >= ultCastTick) and isUltFiring and ultCastTarget ~= nil and not ultCastTarget.dead then
  387.         AutoCarry.CanMove = false
  388.         return true
  389.     else
  390.         UltFireStop()
  391.         return false
  392.     end
  393. end
  394.  
  395. function UltFireStop()
  396.     ultCastTick = 0
  397.     ultVectorX = nil
  398.     ultVectorZ = nil
  399.     AutoCarry.CanMove = true
  400. end
  401.  
  402. function isEnemyInRange(range)
  403.     for _, enemy in pairs(AutoCarry.EnemyTable) do
  404.         if ValidTarget(enemy, range) and not enemy.dead then
  405.             return true
  406.         end
  407.     end
  408.  
  409.     return false
  410. end
  411.  
  412. function KillSteal()
  413.     -- Will try to perform a killsteam using any spell.
  414.     if not AutoCarry.PluginMenu.Killsteal then return end
  415.     -- Killsteal disabled until Bol update for Lucian
  416. --[[
  417.     for _, enemy in pairs(AutoCarry.EnemyTable) do
  418.         if enemy and not enemy.dead then
  419.             local qDmg = getDmg("Q", enemy, myHero)
  420.             local wDmg = getDmg("W", enemy, myHero)
  421.             local rDmg = getDmg("R", enemy, myHero)
  422.  
  423.  
  424.             local rDmg = getDmg("R", enemy, myHero)
  425.  
  426.             if QReady and ValidTarget(enemy, QRange) and (enemy.health + 20) < qDmg then
  427.                 if debugMode then PrintChat("Cast Q KS") end
  428.                 CastQ(enemy)
  429.             elseif WReady and ValidTarget(enemy, WRange) and (enemy.health + 20) < wDmg then
  430.                 if debugMode then PrintChat("Cast W KS") end
  431.                 CastW(enemy)
  432.             elseif AutoCarry.PluginMenu.KillstealUlt and RReady and ValidTarget(enemy, RRange) and (enemy.health + 20) < rDmg then
  433.                 if debugMode then PrintChat("Cast R KS") end
  434.                 CastR(enemy)
  435.             end
  436.  
  437.         end
  438.     end
  439. --]]
  440. end
  441.  
  442. function PluginOnWndMsg(msg,key)
  443.     Target = AutoCarry.GetAttackTarget()
  444.     if Target ~= nil then
  445.         -- if msg == KEY_DOWN and key == KeyQ then CastQ() end
  446.         if msg == KEY_DOWN and key == KeyW then CastW() end
  447.         if msg == KEY_DOWN and key == KeyE then CastE() end
  448.         if msg == KEY_DOWN and key == KeyR then CastR() end
  449.         if msg == KEY_DOWN and key == KeyTest and debugMode then
  450.             if ultVectorX == nil and ultVectorZ == nil then
  451.                 ultCastTarget = Target
  452.                 ultVectorX,y,ultVectorZ = (Vector(myHero) - Vector(ultCastTarget)):normalized():unpack()
  453.             end
  454.             MoveMyHeroToRPosition()
  455.         end
  456.        
  457.         if msg == KEY_UP and key == KeyTest and debugMode then
  458.             ultVectorX = nil
  459.             ultVectorZ = nil
  460.         end
  461.     end
  462. end
  463.  
  464. -- Drawing
  465.  
  466. function PluginOnDraw()
  467.     if debugMode and false then
  468.         if RReady and CanCast(_R) then
  469.             PrintFloatText(myHero, 10, "R IS Ready!")
  470.         else
  471.             PrintFloatText(myHero, 10, "R NOT Ready!")
  472.         end
  473.     end
  474.  
  475.     if AutoCarry.PluginMenu.Draw then
  476.         DrawCircle(myHero.x, myHero.y, myHero.z, AutoCarry.SkillsCrosshair.range, 0x808080) -- Gray
  477.  
  478.         if myHero:CanUseSpell(SkillQ.spellKey) then
  479.             DrawCircle(myHero.x, myHero.y, myHero.z, QRange, 0x0099CC) -- Blue
  480.         end
  481.        
  482.         if myHero:CanUseSpell(SkillW.spellKey) then
  483.             DrawCircle(myHero.x, myHero.y, myHero.z, WRange, 0xFFFF00) -- Yellow
  484.         end
  485.        
  486.         if myHero:CanUseSpell(SkillE.spellKey) then
  487.             DrawCircle(myHero.x, myHero.y, myHero.z, ERange, 0x00FF00) -- Green
  488.         end
  489.  
  490.         if myHero:CanUseSpell(SkillR.spellKey) then
  491.             DrawCircle(myHero.x, myHero.y, myHero.z, RRange, 0xFF0000) -- Red
  492.         end
  493.  
  494.         Target = AutoCarry.GetAttackTarget()
  495.         if Target ~= nil then
  496.             for j=0, 10 do
  497.                 DrawCircle(Target.x, Target.y, Target.z, 40 + j*1.5, 0x00FF00) -- Green
  498.             end
  499.         end
  500.     end
  501. end
  502.  
  503. --[[
  504. class 'ColorARGB' -- {
  505.  
  506.     function ColorARGB:__init(red, green, blue, alpha)
  507.         self.R = red or 255
  508.         self.G = green or 255
  509.         self.B = blue or 255
  510.         self.A = alpha or 255
  511.     end
  512.  
  513.     function ColorARGB.FromArgb(red, green, blue, alpha)
  514.         return Color(red,green,blue, alpha)
  515.     end
  516.  
  517.     function ColorARGB:ToARGB()
  518.         return ARGB(self.A, self.R, self.G, self.B)
  519.     end
  520.  
  521.     ColorARGB.Red = ColorARGB(255, 0, 0, 255)
  522.     ColorARGB.Yellow = ColorARGB(255, 255, 0, 255)
  523.     ColorARGB.Green = ColorARGB(0, 255, 0, 255)
  524.     ColorARGB.Aqua = ColorARGB(0, 255, 255, 255)
  525.     ColorARGB.Blue = ColorARGB(0, 0, 255, 255)
  526.     ColorARGB.Fuchsia = ColorARGB(255, 0, 255, 255)
  527.     ColorARGB.Black = ColorARGB(0, 0, 0, 255)
  528.     ColorARGB.White = ColorARGB(255, 255, 255, 255)
  529. -- }
  530.  
  531. --Notification class
  532. class 'Message' -- {
  533.  
  534.     Message.instance = ""
  535.  
  536.     function Message:__init()
  537.         self.notifys = {}
  538.  
  539.         AddDrawCallback(function(obj) self:OnDraw() end)
  540.     end
  541.  
  542.     function Message.Instance()
  543.         if Message.instance == "" then Message.instance = Message() end return Message.instance
  544.     end
  545.  
  546.     function Message.AddMessage(text, color, target)
  547.         return Message.Instance():PAddMessage(text, color, target)
  548.     end
  549.  
  550.     function Message:PAddMessage(text, color, target)
  551.         local x = 0
  552.         local y = 200
  553.         local tempName = "Screen"
  554.         local tempcolor = color or ColorARGB.Red
  555.  
  556.         if target then  
  557.             tempName = target.networkID
  558.         end
  559.  
  560.         self.notifys[tempName] = { text = text, color = tempcolor, duration = GetGameTimer() + 2, object = target}
  561.     end
  562.  
  563.     function Message:OnDraw()
  564.         for i, notify in pairs(self.notifys) do
  565.             if notify.duration < GetGameTimer() then notify = nil
  566.             else
  567.                 notify.color.A = math.floor((255/2)*(notify.duration - GetGameTimer()))
  568.  
  569.                 if i == "Screen" then  
  570.                     local x = 0
  571.                     local y = 200
  572.                     local gameSettings = GetGameSettings()
  573.                     if gameSettings and gameSettings.General then
  574.                         if gameSettings.General.Width then x = gameSettings.General.Width/2 end
  575.                         if gameSettings.General.Height then y = gameSettings.General.Height/4 - 100 end
  576.                     end  
  577.                     --PrintChat(tostring(notify.color))
  578.                     local p = GetTextArea(notify.text, 40).x
  579.                     self:DrawTextWithBorder(notify.text, 40, x - p/2, y, notify.color:ToARGB(), ARGB(notify.color.A, 0, 0, 0))
  580.                 else    
  581.                     local pos = WorldToScreen(D3DXVECTOR3(notify.object.x, notify.object.y, notify.object.z))
  582.                     local x = pos.x
  583.                     local y = pos.y - 25
  584.                     local p = GetTextArea(notify.text, 40).x
  585.  
  586.                     self:DrawTextWithBorder(notify.text, 30, x- p/2, y, notify.color:ToARGB(), ARGB(notify.color.A, 0, 0, 0))
  587.                 end
  588.             end
  589.         end
  590.     end
  591.  
  592.     function Message:DrawTextWithBorder(textToDraw, textSize, x, y, textColor, backgroundColor)
  593.         DrawText(textToDraw, textSize, x + 1, y, backgroundColor)
  594.         DrawText(textToDraw, textSize, x - 1, y, backgroundColor)
  595.         DrawText(textToDraw, textSize, x, y - 1, backgroundColor)
  596.         DrawText(textToDraw, textSize, x, y + 1, backgroundColor)
  597.         DrawText(textToDraw, textSize, x , y, textColor)
  598.     end
  599. -- }
  600. --]]
Advertisement
Add Comment
Please, Sign In to add comment