Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local deltas = {
- vector2(-1, -1),
- vector2(-1, 0),
- vector2(-1, 1),
- vector2(0, -1),
- vector2(1, -1),
- vector2(1, 0),
- vector2(1, 1),
- vector2(0, 1),
- }
- local function getGridChunk(x)
- return math.floor((x + 8192) / 128)
- end
- local function getGridBase(x)
- return (x * 128) - 8192
- end
- local function toChannel(v)
- return (v.x << 8) | v.y
- end
- local targetList = {}
- local lastTargetList = {}
- Citizen.CreateThread(function()
- while true do
- Citizen.Wait(250)
- -- loop
- local coords = GetEntityCoords(PlayerPedId())
- local gz = vector2(getGridChunk(coords.x), getGridChunk(coords.y))
- local gridZone = toChannel(gz)
- NetworkSetVoiceChannel(gridZone)
- targetList = {}
- for _, d in ipairs(deltas) do
- local v = coords.xy + (d * 20) -- edge size
- targetList[toChannel(vector2(getGridChunk(v.x), getGridChunk(v.y)))] = true
- end
- -- super naive hash difference
- local different = false
- for k, _ in pairs(targetList) do
- if not lastTargetList[k] then
- different = true
- break
- end
- end
- if not different then
- for k, _ in pairs(lastTargetList) do
- if not targetList[k] then
- different = true
- break
- end
- end
- end
- if different then
- -- you might want to swap between two targets when changing
- MumbleClearVoiceTarget(2)
- for k, _ in pairs(targetList) do
- MumbleAddVoiceTargetChannel(2, k)
- end
- MumbleSetVoiceTarget(2)
- lastTargetList = targetList
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement