Guest User

Untitled

a guest
Oct 27th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. --[[
  2. @author Karer <[email protected]>
  3. @copyright 2011-2013 Lukasz Biegaj <[email protected]>
  4. @license Dual GPLv2/MIT
  5. @package MTA-XyzzyRP
  6. @link https://github.com/lpiob/MTA-XyzzyRP GitHub
  7. ]]--
  8.  
  9.  
  10.  
  11. local lastChange = 0
  12.  
  13. local laser = {}
  14.  
  15. local dots = {}
  16.  
  17. local laserData = {}
  18. laserData.r,laserData.g,laserData.b,laserData.a = 255,3,3,80
  19. laserData.width = 2
  20.  
  21.  
  22. function laserToggle ()
  23. local cTick = getTickCount ()
  24. if cTick - lastChange >= 1500 then
  25. lastChange = cTick
  26. if not getElementData (getLocalPlayer(),"laserchange") then return end
  27. local c = getElementData (getLocalPlayer(),"laser")
  28. if c then
  29. setElementData (getLocalPlayer(),"laser",false)
  30. elseif isPlayerWeaponValidForLaser (getLocalPlayer()) then
  31. setElementData (getLocalPlayer(),"laser",true)
  32. end
  33. end
  34. end
  35.  
  36. bindKey ("L","down",laserToggle)
  37.  
  38. addEventHandler( "onClientRender", getRootElement(),
  39. function()
  40. local players = getElementsByType("player",getRootElement(),true)
  41. for k,v in ipairs(players) do
  42. drawLaser(v)
  43. end
  44. end
  45. )
  46.  
  47. function drawLaser(player)
  48. if getElementData(player, "laser") then
  49. local targetself = getPedTarget(player)
  50. if targetself and targetself == player then
  51. targetself = true
  52. else
  53. targetself = false
  54. end
  55.  
  56. if getPedTask(player, "secondary", 0) == "TASK_SIMPLE_USE_GUN" and getPedControlState (player,"aim_weapon") and getPedAnimation (player) == false and isPlayerWeaponValidForLaser(player) == true and targetself == false then
  57. local x,y,z = getPedWeaponMuzzlePosition(player)
  58. if not x then
  59. outputDebugString("getPedWeaponMuzzlePosition failed")
  60. x,y,z = getPedTargetStart(player)
  61. end
  62. local x2,y2,z2 = getPedTargetEnd(player)
  63. if not x2 then
  64. --outputDebugString("getPedTargetEnd failed")
  65. return
  66. end
  67. local x3,y3,z3 = getPedTargetCollision(player)
  68. local r,g,b,a = laserData.r,laserData.g,laserData.b,laserData.a--GetLaserColor(player)
  69. if x3 then -- collision detected, draw til collision and add a dot
  70. dxDrawLine3D(x,y,z,x3,y3,z3, tocolor(r,g,b,a), laserData.width)
  71. drawLaserDot(player, x3,y3,z3)
  72. else -- no collision, draw til end of weapons range
  73. dxDrawLine3D(x,y,z,x2,y2,z2, tocolor(r,g,b,a), laserData.width)
  74. destroyLaserDot(player)
  75. end
  76. else
  77. destroyLaserDot(player) -- not aiming, remove dot, no laser
  78. end
  79. else
  80. destroyLaserDot(player)
  81. end
  82. end
  83.  
  84. function drawLaserDot (player, x,y,z)
  85. if not dots[player] then
  86. dots[player] = createMarker(x,y,z, "corona", .05, laserData.r, laserData.g, laserData.b, laserData.a)
  87. else
  88. setElementPosition(dots[player], x,y,z)
  89. end
  90. end
  91.  
  92. function destroyLaserDot(player)
  93. if dots[player] and isElement(dots[player]) then
  94. destroyElement(dots[player])
  95. dots[player] = nil
  96. end
  97. end
  98.  
  99. function isPlayerWeaponValidForLaser(player) -- returns false for unarmed and awkward weapons
  100. local weapon = getPedWeapon(player)
  101. return true
  102. end
Advertisement
Add Comment
Please, Sign In to add comment