Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Voice = {
- Modes = {
- { range = 3 },
- {
- vehicle = true,
- range = 4,
- check = function(ped)
- return IsPedInAnyVehicle(ped)
- end,
- callback = function(ped, playerPed, distance)
- return IsPedInAnyVehicle(ped) and GetVehiclePedIsUsing(ped) == GetVehiclePedIsUsing(playerPed)
- end
- },
- { range = 10 },
- { range = 30 }
- },
- Listeners = {},
- Call = false,
- Mode = 3,
- Mute = false,
- Distance = 10.0,
- OnlyVehicle = false,
- Display = true
- }
- local function SendVoiceToPlayer(player, send)
- Citizen.InvokeNative(0x97DD4C5944CC2E6A, player, send)
- end
- local function DrawRct(x, y, width, height, r, g, b, a)
- DrawRect(x + width / 2, y + height / 2, width, height, r, g, b, a)
- end
- local function DrawText3D(x, y, z, canSee)
- local _, _x, _y = World3dToScreen2d(x,y,z)
- local px, py, pz = table.unpack(GetGameplayCamCoords())
- local distance = GetDistanceBetweenCoords(px, py, pz, x, y, z, 1)
- local scale = (1 / distance) * 20 * ((1 / GetGameplayCamFov()) * 100)
- local color = canSee and {0, 70, 200} or {255, 255, 255}
- SetDrawOrigin(x, y, z, 0)
- DrawRect(0.0, 0.02, 0.0003 * scale, 0.0375 * scale, color[1], color[2], color[3], 255)
- ClearDrawOrigin()
- end
- function Voice:Update(call)
- if call then
- if type(call) == 'number' then
- local player = GetPlayerFromServerId(call)
- if player then
- self.Call = call
- self.Listeners[call] = true
- SendVoiceToPlayer(player, true)
- end
- elseif self.Call then
- local player = GetPlayerFromServerId(self.Call)
- if player then
- SendVoiceToPlayer(player, false)
- end
- self.Listeners[self.Call] = false
- self.Call = false
- end
- end
- local ped = PlayerPedId()
- if self.OnlyVehicle and not self.Modes[self.Mode].check(ped) then
- self.Mode = 3
- self:OnChange()
- else
- TriggerEvent('instance:get', function(instance)
- local players = {}
- if instance.host then
- table.insert(instance.players, instance.host)
- for _, sid in ipairs(instance.players) do
- local player = GetPlayerFromServerId(sid)
- table.insert(players, {pid = player, ped = GetPlayerPed(player), sid = sid})
- end
- else
- for player = 0, 64 do
- if NetworkIsPlayerActive(player) then
- table.insert(players, {pid = player, ped = GetPlayerPed(player), sid = GetPlayerServerId(player)})
- end
- end
- end
- for _, data in ipairs(players) do
- if data.ped and self:CanListen(ped, data.ped) then
- if not self.Listeners[data.sid] then
- self.Listeners[data.sid] = true
- end
- SendVoiceToPlayer(data.pid, true)
- elseif self.Listeners[data.sid] and self.Call ~= data.sid then
- self.Listeners[data.sid] = false
- SendVoiceToPlayer(data.pid, false)
- end
- end
- end)
- end
- end
- function Voice:OnChange()
- local mode = self.Modes[self.Mode]
- if mode then
- self.Distance = mode.range
- self.OnlyVehicle = mode.vehicle or false
- self:Update(self.Call)
- end
- end
- function Voice:CanListen(ped, playerPed)
- local distance = GetDistanceBetweenCoords(GetPedBoneCoords(playerPed, 12844, 0.0, 0.0, 0.0), GetEntityCoords(ped))
- 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)
- end
- function setVoice()
- local nextMode = Voice.Mode + 1
- if not Voice.Modes[nextMode] then
- nextMode = 1
- end
- while Voice.Modes[nextMode] and Voice.Modes[nextMode].check and Voice.Modes[nextMode].callback and not Voice.Modes[nextMode].check(PlayerPedId()) do
- nextMode = nextMode + 1
- if not Voice.Modes[nextMode] then
- nextMode = 1
- end
- end
- Voice.Mode = nextMode
- Voice:OnChange()
- end
- AddEventHandler('esx_voice:setCall', function(target)
- Voice:Update(target)
- end)
- AddEventHandler('esx_voice:setMute', function(status)
- Voice.Mute = status
- end)
- AddEventHandler('esx_status:setDisplay', function(val)
- Voice.Display = tonumber(val) ~= 0
- end)
- Citizen.CreateThread(function()
- local shouldReset = false
- for i = 0, 64 do
- SendVoiceToPlayer(i, false)
- end
- NetworkSetTalkerProximity(-1000.0)
- while true do
- Citizen.Wait(300)
- local sendVoice = not Voice.Mute and (NetworkIsPlayerTalking(PlayerId()) or IsControlPressed(0, 249))
- if sendVoice then
- if not shouldReset then
- shouldReset = true
- end
- elseif not sendVoice and shouldReset then
- shouldReset = false
- for i = 0, 64 do
- SendVoiceToPlayer(i, false)
- end
- end
- Voice:Update(Voice.Call)
- end
- end)
- local isPaused = false
- Citizen.CreateThread(function()
- RequestStreamedTextureDict('mpleaderboard')
- while not HasStreamedTextureDictLoaded('mpleaderboard') do
- Citizen.Wait(100)
- end
- while true do
- Citizen.Wait(1)
- if IsPauseMenuActive() and not isPaused then
- isPaused = true
- TriggerEvent('esx_voice:setDisplay', 0.0)
- elseif not IsPauseMenuActive() and isPaused then
- isPaused = false
- TriggerEvent('esx_voice:setDisplay', 1)
- end
- local color = {255, 255, 255}
- if not isPaused then
- if NetworkIsPlayerTalking(PlayerId()) then
- color = {255, 0, 0}
- elseif IsControlPressed(0, 249) then
- color = {132, 0, 255}
- elseif (IsControlPressed(0, 21) and IsControlPressed(0, 166)) or (IsDisabledControlPressed(0, 21) and IsDisabledControlPressed(0, 166)) then
- local ped = PlayerPedId()
- 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)
- elseif IsControlJustPressed(0, 166) or IsDisabledControlJustPressed(0, 166) then
- setVoice()
- end
- end
- if Voice.Display then
- local size = 0.069
- if Voice.Mode == 1 then
- size = size / 4
- elseif Voice.Mode == 2 then
- size = size / 3
- elseif Voice.Mode == 3 then
- size = size / 2
- end
- DrawRct(0.085, 0.985, 0.0705, 0.0125, 0, 0, 0, 120)
- DrawRct(0.0865, 0.985, size, 0.01, color[1], color[2], color[3], 70)
- if Voice.Mode == 2 then
- DrawSprite('mpleaderboard', 'leaderboard_car_icon', 0.15, 0.991, 0.012, 0.022, 0.0, 255, 255, 255, 255)
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement