Advertisement
Guest User

Fivem - Mumble splitting

a guest
May 1st, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. local deltas = {
  2.     vector2(-1, -1),
  3.     vector2(-1, 0),
  4.     vector2(-1, 1),
  5.     vector2(0, -1),
  6.     vector2(1, -1),
  7.     vector2(1, 0),
  8.     vector2(1, 1),
  9.     vector2(0, 1),
  10. }
  11.  
  12.  
  13. local targetList = {}
  14. local lastTargetList = {}
  15.  
  16.  
  17. local function getGridChunk(x)
  18.     return math.floor((x + 8192) / 256)
  19. end
  20.  
  21. local function getGridBase(x)
  22.     return (x * 256) - 8192
  23. end
  24.  
  25. local function toChannel(v)
  26.     return (v.x << 8) | v.y
  27. end
  28.  
  29. local function DoVoiceSystem()
  30.     local coords = GetEntityCoords(PlayerPedId())
  31.  
  32.     local gz = vector2(getGridChunk(coords.x), getGridChunk(coords.y))
  33.  
  34.     local gridZone = toChannel(gz)
  35.  
  36.     NetworkSetVoiceChannel(gridZone)
  37.  
  38.     targetList = {}
  39.  
  40.     for _, d in ipairs(deltas) do
  41.         local v = coords.xy + (d * 20) -- edge size
  42.    
  43.         targetList[toChannel(vector2(getGridChunk(v.x), getGridChunk(v.y)))] = true
  44.     end
  45.  
  46.     MumbleClearVoiceTarget(2)
  47.     for k, _ in pairs(targetList) do
  48.         MumbleAddVoiceTargetChannel(2, k)
  49.     end
  50.     MumbleSetVoiceTarget(2)
  51.  
  52.     lastTargetList = targetList
  53. end
  54.  
  55. -- Loop
  56. Citizen.CreateThread(function()
  57.     Citizen.Wait(500)
  58.  
  59.     while true do
  60.         DoVoiceSystem()
  61.         Citizen.Wait(250)
  62.     end
  63. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement