Advertisement
miguelspastes

zues lines

Jan 30th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. local function distance3d(x1, y1, z1, x2, y2, z2)
  2. return math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1))
  3. end
  4.  
  5.  
  6.  
  7.  
  8.  
  9. local function lerp_pos(x1, y1, z1, x2, y2, z2, percentage)
  10. local x = (x2 - x1) * percentage + x1
  11. local y = (y2 - y1) * percentage + y1
  12. local z = (z2 - z1) * percentage + z1
  13. return x, y, z
  14. end
  15.  
  16. local function trace_line_skip_teammates( x1, y1, z1, x2, y2, z2, max_traces)
  17. local max_traces = max_traces or 10
  18. local fraction, entindex_hit = 0, -1
  19. local x_hit, y_hit, z_hit = x1, y1, z1
  20.  
  21. local i=1
  22. while (entindex_hit == -1 ) and 1 > fraction and max_traces >= i do
  23. fraction, entindex_hit = engine.TraceLine( x_hit, y_hit, z_hit, x2, y2, z2,3)
  24.  
  25. x_hit, y_hit, z_hit = lerp_pos(x_hit, y_hit, z_hit, x2, y2, z2, 1)
  26.  
  27. i = i + 1
  28. end
  29.  
  30. local traveled_total = distance3d(x1, y1, z1, x_hit, y_hit, z_hit)
  31. local total_distance = distance3d(x1, y1, z1, x2, y2, z2)
  32.  
  33. return traveled_total/total_distance, entindex_hit
  34. end
  35.  
  36. local function hsv_to_rgb(h, s, v, a)
  37. local r, g, b
  38.  
  39. local i = math.floor(h * 6);
  40. local f = h * 6 - i;
  41. local p = v * (1 - s);
  42. local q = v * (1 - f * s);
  43. local t = v * (1 - (1 - f) * s);
  44.  
  45. i = i % 6
  46.  
  47. if i == 0 then r, g, b = v, t, p
  48. elseif i == 1 then r, g, b = q, v, p
  49. elseif i == 2 then r, g, b = p, v, t
  50. elseif i == 3 then r, g, b = p, q, v
  51. elseif i == 4 then r, g, b = t, p, v
  52. elseif i == 5 then r, g, b = v, p, q
  53. end
  54.  
  55. return r * 255, g * 255, b * 255, a * 255
  56. end
  57.  
  58.  
  59.  
  60.  
  61. local weapon_name_prev = nil
  62. local last_switch = 0
  63. local accuracy = 2.5
  64.  
  65. local is_taser;
  66. local is_knife;
  67. local function on_item_equip(Event)
  68.  
  69. if (Event:GetName() ~= 'item_equip') then
  70. return;
  71. end
  72.  
  73. local local_player, userid, item, weptype = client.GetLocalPlayerIndex(), Event:GetInt('userid'), Event:GetString('item'), Event:GetInt('weptype');
  74.  
  75.  
  76. if (local_player == client.GetPlayerIndexByUserID(userid)) then
  77. if (item == "taser" ) then
  78. is_taser=true;
  79. is_knife=false;
  80. elseif (item=="knife")then
  81. is_knife=true;
  82. is_taser=false;
  83. else
  84. is_knife=false;
  85. is_taser=false;
  86. end
  87. end
  88. end
  89.  
  90.  
  91. client.AllowListener('item_equip');
  92. callbacks.Register("FireGameEvent", "on_item_equip", on_item_equip);
  93.  
  94.  
  95. local function on_paint()
  96.  
  97.  
  98. local local_player = entities.GetLocalPlayer();
  99. local curtime = globals.CurTime()
  100.  
  101.  
  102.  
  103. local ranges
  104. local ranges_opacities
  105. if is_taser then
  106. ranges = {183-16}
  107. ranges_opacities = {1}
  108. elseif is_knife then
  109. ranges = {32, 48}
  110. ranges_opacities = {1, 0.2}
  111. end
  112.  
  113. if ranges == nil then
  114. return
  115. end
  116. local Entity = entities.GetLocalPlayer();
  117. local Alive = Entity:IsAlive();
  118. if (Alive ~=true) then
  119. return
  120.  
  121. end
  122. local local_x, local_y, local_z = Entity:GetAbsOrigin()
  123. local vo_z = Entity:GetProp("localdata", "m_vecViewOffset[2]")-4
  124.  
  125. fade_multiplier = 1
  126. for i=1, #ranges do
  127. local range = ranges[i]
  128. local opacity_multiplier = ranges_opacities[i] * fade_multiplier
  129.  
  130. local previous_world_x, previous_world_y
  131.  
  132. for rot=0, 360, accuracy do
  133. local rot_temp = math.rad(rot)
  134. local temp_x, temp_y, temp_z = local_x + range * math.cos(rot_temp), local_y + range * math.sin(rot_temp), local_z
  135.  
  136. local fraction, entindex_hit = trace_line_skip_teammates( local_x, local_y, local_z, temp_x, temp_y, temp_z)
  137.  
  138. --local fraction_x, fraction_y = local_x+(temp_x-local_x)*fraction, local_y+(temp_y-local_y)*fraction
  139. local fraction_x, fraction_y = lerp_pos(local_x, local_y, local_z, temp_x, temp_y, temp_z, fraction)
  140. local world_x, world_y = client.WorldToScreen( fraction_x, fraction_y, temp_z+vo_z)
  141.  
  142. local hue_extra = globals.RealTime() % 8 / 8
  143. local r, g, b = hsv_to_rgb(rot/360+hue_extra, 1, 1, 255)
  144.  
  145. local fraction_multiplier = 1
  146. if fraction > 0.9 then
  147. fraction_multiplier = 0.6
  148. end
  149.  
  150. if world_x ~= nil and previous_world_x ~= nil then
  151. draw.Color( r, g, b, 255*opacity_multiplier*fraction_multiplier)
  152. draw.Line( world_x, world_y, previous_world_x, previous_world_y )
  153. end
  154. previous_world_x, previous_world_y = world_x, world_y
  155. end
  156. end
  157.  
  158. end
  159.  
  160.  
  161.  
  162.  
  163. callbacks.Register( "Draw", "on_paint", on_paint);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement