Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. local Voice = {
  2. Modes = {
  3. { range = 3 },
  4. {
  5. vehicle = true,
  6. range = 4,
  7. check = function(ped)
  8. return IsPedInAnyVehicle(ped)
  9. end,
  10. callback = function(ped, playerPed, distance)
  11. return IsPedInAnyVehicle(ped) and GetVehiclePedIsUsing(ped) == GetVehiclePedIsUsing(playerPed)
  12. end
  13. },
  14. { range = 10 },
  15. { range = 30 }
  16. },
  17.  
  18. Listeners = {},
  19. Call = false,
  20. Mode = 3,
  21. Mute = false,
  22.  
  23. Distance = 10.0,
  24. OnlyVehicle = false,
  25. Display = true
  26. }
  27.  
  28. local function SendVoiceToPlayer(player, send)
  29. Citizen.InvokeNative(0x97DD4C5944CC2E6A, player, send)
  30. end
  31.  
  32. local function DrawRct(x, y, width, height, r, g, b, a)
  33. DrawRect(x + width / 2, y + height / 2, width, height, r, g, b, a)
  34. end
  35.  
  36. local function DrawText3D(x, y, z, canSee)
  37. local _, _x, _y = World3dToScreen2d(x,y,z)
  38. local px, py, pz = table.unpack(GetGameplayCamCoords())
  39. local distance = GetDistanceBetweenCoords(px, py, pz, x, y, z, 1)
  40.  
  41. local scale = (1 / distance) * 20 * ((1 / GetGameplayCamFov()) * 100)
  42. local color = canSee and {0, 70, 200} or {255, 255, 255}
  43.  
  44. SetDrawOrigin(x, y, z, 0)
  45. DrawRect(0.0, 0.02, 0.0003 * scale, 0.0375 * scale, color[1], color[2], color[3], 255)
  46. ClearDrawOrigin()
  47. end
  48.  
  49. function Voice:Update(call)
  50. if call then
  51. if type(call) == 'number' then
  52. local player = GetPlayerFromServerId(call)
  53. if player then
  54. self.Call = call
  55. self.Listeners[call] = true
  56. SendVoiceToPlayer(player, true)
  57. end
  58. elseif self.Call then
  59. local player = GetPlayerFromServerId(self.Call)
  60. if player then
  61. SendVoiceToPlayer(player, false)
  62. end
  63.  
  64. self.Listeners[self.Call] = false
  65. self.Call = false
  66. end
  67. end
  68.  
  69. local ped = PlayerPedId()
  70. if self.OnlyVehicle and not self.Modes[self.Mode].check(ped) then
  71. self.Mode = 3
  72. self:OnChange()
  73. else
  74. TriggerEvent('instance:get', function(instance)
  75. local players = {}
  76. if instance.host then
  77. table.insert(instance.players, instance.host)
  78. for _, sid in ipairs(instance.players) do
  79. local player = GetPlayerFromServerId(sid)
  80. table.insert(players, {pid = player, ped = GetPlayerPed(player), sid = sid})
  81. end
  82. else
  83. for player = 0, 64 do
  84. if NetworkIsPlayerActive(player) then
  85. table.insert(players, {pid = player, ped = GetPlayerPed(player), sid = GetPlayerServerId(player)})
  86. end
  87. end
  88. end
  89.  
  90. for _, data in ipairs(players) do
  91. if data.ped and self:CanListen(ped, data.ped) then
  92. if not self.Listeners[data.sid] then
  93. self.Listeners[data.sid] = true
  94. end
  95.  
  96. SendVoiceToPlayer(data.pid, true)
  97. elseif self.Listeners[data.sid] and self.Call ~= data.sid then
  98. self.Listeners[data.sid] = false
  99. SendVoiceToPlayer(data.pid, false)
  100. end
  101. end
  102. end)
  103. end
  104. end
  105.  
  106. function Voice:OnChange()
  107. local mode = self.Modes[self.Mode]
  108. if mode then
  109. self.Distance = mode.range
  110. self.OnlyVehicle = mode.vehicle or false
  111.  
  112. self:Update(self.Call)
  113. end
  114. end
  115.  
  116. function Voice:CanListen(ped, playerPed)
  117. local distance = GetDistanceBetweenCoords(GetPedBoneCoords(playerPed, 12844, 0.0, 0.0, 0.0), GetEntityCoords(ped))
  118. return (self.OnlyVehicle and self.Modes[self.Mode].callback(ped, playerPed, distance)) or (not self.OnlyVehicle and (HasEntityClearLosToEntityInFront(ped, playerPed) or distance < (math.max(0, math.min(30, self.Distance)) * 0.66)) and distance < self.Distance)
  119. end
  120.  
  121. function setVoice()
  122. local nextMode = Voice.Mode + 1
  123. if not Voice.Modes[nextMode] then
  124. nextMode = 1
  125. end
  126.  
  127. while Voice.Modes[nextMode] and Voice.Modes[nextMode].check and Voice.Modes[nextMode].callback and not Voice.Modes[nextMode].check(PlayerPedId()) do
  128. nextMode = nextMode + 1
  129. if not Voice.Modes[nextMode] then
  130. nextMode = 1
  131. end
  132. end
  133.  
  134. Voice.Mode = nextMode
  135. Voice:OnChange()
  136. end
  137.  
  138. AddEventHandler('esx_voice:setCall', function(target)
  139. Voice:Update(target)
  140. end)
  141.  
  142. AddEventHandler('esx_voice:setMute', function(status)
  143. Voice.Mute = status
  144. end)
  145.  
  146. AddEventHandler('esx_status:setDisplay', function(val)
  147. Voice.Display = tonumber(val) ~= 0
  148. end)
  149.  
  150. Citizen.CreateThread(function()
  151. local shouldReset = false
  152. for i = 0, 64 do
  153. SendVoiceToPlayer(i, false)
  154. end
  155.  
  156. NetworkSetTalkerProximity(-1000.0)
  157. while true do
  158. Citizen.Wait(300)
  159.  
  160. local sendVoice = not Voice.Mute and (NetworkIsPlayerTalking(PlayerId()) or IsControlPressed(0, 249))
  161. if sendVoice then
  162. if not shouldReset then
  163. shouldReset = true
  164. end
  165. elseif not sendVoice and shouldReset then
  166. shouldReset = false
  167. for i = 0, 64 do
  168. SendVoiceToPlayer(i, false)
  169. end
  170. end
  171.  
  172. Voice:Update(Voice.Call)
  173. end
  174. end)
  175.  
  176. local isPaused = false
  177. Citizen.CreateThread(function()
  178. RequestStreamedTextureDict('mpleaderboard')
  179. while not HasStreamedTextureDictLoaded('mpleaderboard') do
  180. Citizen.Wait(100)
  181. end
  182.  
  183. while true do
  184. Citizen.Wait(1)
  185. if IsPauseMenuActive() and not isPaused then
  186. isPaused = true
  187. TriggerEvent('esx_voice:setDisplay', 0.0)
  188. elseif not IsPauseMenuActive() and isPaused then
  189. isPaused = false
  190. TriggerEvent('esx_voice:setDisplay', 1)
  191. end
  192.  
  193. local color = {255, 255, 255}
  194. if not isPaused then
  195. if NetworkIsPlayerTalking(PlayerId()) then
  196. color = {255, 0, 0}
  197. elseif IsControlPressed(0, 249) then
  198. color = {132, 0, 255}
  199. elseif (IsControlPressed(0, 21) and IsControlPressed(0, 166)) or (IsDisabledControlPressed(0, 21) and IsDisabledControlPressed(0, 166)) then
  200. local ped = PlayerPedId()
  201. DrawMarker(28, GetPedBoneCoords(ped, 12844, 0.0, 0.0, 0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Voice.Distance + 0.0, Voice.Distance + 0.0, Voice.Distance + 0.0, 20, 192, 255, 70, 0, 0, 2, 0, 0, 0, 0)
  202. elseif IsControlJustPressed(0, 166) or IsDisabledControlJustPressed(0, 166) then
  203. setVoice()
  204. end
  205. end
  206.  
  207. if Voice.Display then
  208. local size = 0.069
  209. if Voice.Mode == 1 then
  210. size = size / 4
  211. elseif Voice.Mode == 2 then
  212. size = size / 3
  213. elseif Voice.Mode == 3 then
  214. size = size / 2
  215. end
  216.  
  217. DrawRct(0.085, 0.985, 0.0705, 0.0125, 0, 0, 0, 120)
  218. DrawRct(0.0865, 0.985, size, 0.01, color[1], color[2], color[3], 70)
  219. if Voice.Mode == 2 then
  220. DrawSprite('mpleaderboard', 'leaderboard_car_icon', 0.15, 0.991, 0.012, 0.022, 0.0, 255, 255, 255, 255)
  221. end
  222. end
  223. end
  224. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement