Advertisement
Guest User

Voip splitting system

a guest
Mar 29th, 2020
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. -- Voice splitting system
  2. -- Cookay and thank you Ferrum for the concept
  3.  
  4. -- CFG
  5. local timeBetweenCheck = 250
  6.  
  7. -- Variables
  8. local deltas =
  9. {
  10.     vector2(-1, -1),
  11.     vector2(-1, 0),
  12.     vector2(-1, 1),
  13.     vector2(0, -1),
  14.     vector2(1, -1),
  15.     vector2(1, 0),
  16.     vector2(1, 1),
  17.     vector2(0, 1),
  18. }
  19.  
  20. local cookayVoiceChannel = "NONE"
  21.  
  22. local targetList = {}
  23. local lastTargetList = {}
  24.  
  25. -- Functions
  26. local function ShowDebugText(text)  
  27.     ClearPrints()
  28.  
  29.     -- when drawing
  30.     BeginTextCommandDisplayText('COOKAYDEBUGMUMBLE')
  31.     AddTextComponentSubstringPlayerName(text)
  32.     EndTextCommandDisplayText(0.0, 0.9)
  33. end
  34.  
  35. local function getGridChunk(x)
  36.     return math.floor((x + 8192) / 128)
  37. end
  38.  
  39. local function getGridBase(x)
  40.     return (x * 128) - 8192
  41. end
  42.  
  43. local function toChannel(v)
  44.     return (v.x << 8) | v.y
  45. end
  46.  
  47. local function DoVoiceSystem()
  48.     local coords = GetEntityCoords(PlayerPedId())
  49.  
  50.     local gz = vector2(getGridChunk(coords.x), getGridChunk(coords.y))
  51.  
  52.     local gridZone = toChannel(gz)
  53.     if gridZone == 1 then print("------------ Set voice channel to : " .. gridZone .. " ---------------------") end
  54.     cookayVoiceChannel = gridZone
  55.     NetworkSetVoiceChannel(gridZone)
  56.  
  57.     targetList = {}
  58.  
  59.     for _, d in ipairs(deltas) do
  60.         local v = coords.xy + (d * 20) -- edge size
  61.    
  62.         targetList[toChannel(vector2(getGridChunk(v.x), getGridChunk(v.y)))] = true
  63.     end
  64.  
  65.     -- super naive hash difference
  66.     local different = false
  67.  
  68.     for k, _ in pairs(targetList) do
  69.         if not lastTargetList[k] then
  70.             different = true
  71.             break
  72.         end
  73.     end
  74.  
  75.     if not different then
  76.         for k, _ in pairs(lastTargetList) do
  77.             if not targetList[k] then
  78.                 different = true
  79.                 break
  80.             end
  81.         end
  82.     end
  83.  
  84.     if different then
  85.         -- you might want to swap between two targets when changing
  86.         MumbleClearVoiceTarget(2)
  87.    
  88.         for k, _ in pairs(targetList) do
  89.             MumbleAddVoiceTargetChannel(2, k)
  90.         end
  91.    
  92.         MumbleSetVoiceTarget(2)
  93.  
  94.         lastTargetList = targetList
  95.     end
  96. end
  97.  
  98. -- Loop
  99. Citizen.CreateThread(function()
  100.     Citizen.Wait(500)
  101.  
  102.     while true do
  103.         DoVoiceSystem()
  104.         Citizen.Wait(250)
  105.     end
  106. end)
  107.  
  108. Citizen.CreateThread(function()
  109.     Citizen.Wait(1000)
  110.  
  111.     AddTextEntry('COOKAYDEBUGMUMBLE', "<p align='center'><font size='30'>~r~Debug : ~w~~a~</font></p>")
  112.  
  113.     while true do
  114.         ShowDebugText(cookayVoiceChannel)
  115.         Citizen.Wait(0)
  116.     end
  117. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement