Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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. local function getGridChunk(x)
  13. return math.floor((x + 8192) / 128)
  14. end
  15.  
  16. local function getGridBase(x)
  17. return (x * 128) - 8192
  18. end
  19.  
  20. local function toChannel(v)
  21. return (v.x << 8) | v.y
  22. end
  23.  
  24. local targetList = {}
  25. local lastTargetList = {}
  26.  
  27. Citizen.CreateThread(function()
  28. while true do
  29. Citizen.Wait(250)
  30. -- loop
  31.  
  32. local coords = GetEntityCoords(PlayerPedId())
  33.  
  34. local gz = vector2(getGridChunk(coords.x), getGridChunk(coords.y))
  35.  
  36. local gridZone = toChannel(gz)
  37. NetworkSetVoiceChannel(gridZone)
  38.  
  39. targetList = {}
  40.  
  41. for _, d in ipairs(deltas) do
  42. local v = coords.xy + (d * 20) -- edge size
  43.  
  44. targetList[toChannel(vector2(getGridChunk(v.x), getGridChunk(v.y)))] = true
  45. end
  46.  
  47. -- super naive hash difference
  48. local different = false
  49.  
  50. for k, _ in pairs(targetList) do
  51. if not lastTargetList[k] then
  52. different = true
  53. break
  54. end
  55. end
  56.  
  57. if not different then
  58. for k, _ in pairs(lastTargetList) do
  59. if not targetList[k] then
  60. different = true
  61. break
  62. end
  63. end
  64. end
  65.  
  66. if different then
  67. -- you might want to swap between two targets when changing
  68. MumbleClearVoiceTarget(2)
  69.  
  70. for k, _ in pairs(targetList) do
  71. MumbleAddVoiceTargetChannel(2, k)
  72. end
  73.  
  74. MumbleSetVoiceTarget(2)
  75.  
  76. lastTargetList = targetList
  77. end
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement