[Release] Voice System with range preview

nice, thanks for replying!
I’ve got 2 questions…

  1. how do you change the circle color from green to something else (say blue for example)?
  2. Could you make it that when i press shift+h, it doesn’t only let me preview the range, but actually changing the range as well?

It does change the range when pressing & holding SHIFT H.
You change the color at the top where you see local r,g,b,a

sorry for the confusion, i meant to actually change the range, allowing the ped hear further/nearer

You literally stole my script…
At least give some credit…

Lol what? didn’t even know your script existed.
Besides that, our code doesn’t even look similar

yeah just change

local voice = {default = 5.0, shout = 12.0, whisper = 1.0, current = 0}

to your needs.

i tried and tested it… it doesn’t work tho…
Note: i have vmenu installed.

Isn’t there a built in voice system in vMenu?

there is… but there isn’t an easy way to change the voice chat range…
everytime when i wanna change the voice chat range… i need to go into the menu to do it

Oh lol. We can team up to make one good script.

Where i can download the script?

his github link is above the picture click the blue GitHub then download zip on github

this may sound stupid, but does this not have voice chat built into it ? when i speak in-game it shows i am speaking. but no one can hear me. do i have to use a trainer in order to have voice?

Idk why people are saying this script is stolen, I am the original creator of family RP style voice chat which is the script used on like every single fivem server in existence and I gave him permission to use my code so stop being little baby’s about everything lol

2 Likes

Guys why is everygood script removed from Github? there is just find file any github problems? maybe

Here ya goo!!! :kissing_heart:

voicechat-proximity.zip (1.9 KB)

What am I downloading?

__resource.lua
client.lua

local VoiceMode = {
	{ dist = 3, message = "Voice range set to 3 meters." },
	{ dist = 8, message = "Voice range set to 8 meters." },
	{ dist = 14, message = "Voice range set to 14 meters." },
	{ veh = true, dist = 4, func = function(ped) return IsPedInAnyVehicle(ped) end, message = "Voice range set to your vehicle." },
}

local Voice = {}
Voice.Listeners = {}
Voice.Mode = 2
Voice.distance = 8.0
Voice.onlyVehicle = false

local function SendVoiceToPlayer(intPlayer, boolSend)
	Citizen.InvokeNative(0x97DD4C5944CC2E6A, intPlayer, boolSend)
end

local function GetPlayers()
	local players = {}
	for i = 0, 64 do
		if NetworkIsPlayerActive(i) then
			players[#players + 1] = i
		end
	end
	return players
end

function Voice:UpdateVoices()
	local ped = GetPlayerPed(-1)
	local InVeh = IsPedInAnyVehicle(ped)

	if Voice.onlyVehicle and not InVeh then
		Voice.Mode = 1
		Voice:OnModeModified()
	end

	for k,v in pairs(GetPlayers()) do
		local otherPed, serverID = GetPlayerPed(v), GetPlayerServerId(v)
		if otherPed and Voice:CanPedBeListened(ped, otherPed) then
			if not Voice.Listeners[serverID] then
				Voice.Listeners[serverID] = true
			end
			SendVoiceToPlayer(v, true)
		elseif Voice.Listeners[serverID] then
			Voice.Listeners[serverID] = false
			SendVoiceToPlayer(v, false)
		end
	end

	if Voice.onlyVehicle and not InVeh then
		Voice.Mode = 1
		Voice:OnModeModified()
	end
end

local function ShowAboveRadarMessage(message)
	SetNotificationTextEntry("jamyfafi")
	AddTextComponentString(message)
	return DrawNotification(0, 1)
end

local notifID
function Voice:OnModeModified()
	local modeData = VoiceMode[self.Mode]
	if modeData then
		self.distance = modeData.dist
		self.onlyVehicle = modeData.veh
		if modeData.message then
			if notifID then RemoveNotification(notifID) end
			notifID = ShowAboveRadarMessage(modeData.message)
			Citizen.SetTimeout(4000, function() if notifID then RemoveNotification(notifID) end end)
		end

		self:UpdateVoices()
	end
end

function Voice:CanPedBeListened(ped, otherPed)
	local listenerHeadPos, InSameVeh = GetPedBoneCoords(otherPed, 12844, .0, .0, .0), IsPedInAnyVehicle(ped) and GetVehiclePedIsUsing(ped) == GetVehiclePedIsUsing(otherPed)
	local distance = GetDistanceBetweenCoords(listenerHeadPos, GetEntityCoords(ped))

	local bypassVOIP, checkDistance = InSameVeh, self.distance
	return bypassVOIP or (not self.onlyVehicle and (HasEntityClearLosToEntityInFront(ped, otherPed) or distance < (math.max(0, math.min(18, checkDistance)) * .6)) and distance < checkDistance)
end

function Voice:ShouldSendVoice()
	return NetworkIsPlayerTalking(PlayerId()) or IsControlPressed(0, 249)
end

local shouldReset = false
Citizen.CreateThread(function()
	for i = 0, 63 do SendVoiceToPlayer(i, false) end
	NetworkSetTalkerProximity(-1000.0)

	while true do
		Citizen.Wait(300)

		local sendVoice = Voice:ShouldSendVoice()
		if sendVoice then
			if not shouldReset then
				shouldReset = true
				--TriggerEvent("pichot:toggleNUI", { voip = Voice.Mode }) -- you can implement a microphone icon
			end
		elseif not sendVoice and shouldReset then
			shouldReset = false
			--TriggerEvent("pichot:toggleNUI", { voip = false })
			for i = 0, 63 do
				SendVoiceToPlayer(i, false)
			end
		end

		Voice:UpdateVoices()
	end
end)

local function DrawText3D(x,y,z, canSee)
	local _, _x, _y = World3dToScreen2d(x,y,z)
	local px, py, pz = table.unpack(GetGameplayCamCoords())
	local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)

	local scale = ( 1 / dist ) * 20
	scale = scale * ( ( 1 / GetGameplayCamFov() ) * 100 )
end

local function UpdateVocalMode(mode)
	local nextMode = mode or Voice.Mode + 1
	while not VoiceMode[nextMode] or (VoiceMode[nextMode] and VoiceMode[nextMode].func and not VoiceMode[nextMode].func(GetPlayerPed(-1))) do
		nextMode = VoiceMode[nextMode + 1] or 1
	end

	Voice.Mode = nextMode
	Voice:OnModeModified()
end

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		if IsControlJustPressed(1, 171) then
			UpdateVocalMode()
		end

		if IsControlPressed(1, 171) then
			local ped = GetPlayerPed(-1)
			local headPos = GetPedBoneCoords(ped, 12844, .0, .0, .0)

			for k,v in pairs(GetPlayers()) do
				local otherPed = GetPlayerPed(v)
				if otherPed and Voice.Listeners[GetPlayerServerId(v)] then
					local entPos = GetEntityCoords(otherPed)
					DrawText3D(entPos.x, entPos.y, entPos.z, true)
				end
			end

			local distance = Voice.distance + .0
			DrawMarker(28, headPos, 0.0, 0.0, 0.0, 0.0, 0.0, .0, distance + .0, distance + .0, distance + .0, 20, 192, 255, 70, 0, 0, 2, 0, 0, 0, 0)
		end
	end
end)

Thank you very much sir and for your time. You are good man

1 Like

Anyone have an issue where voice is global until you adjust the range once, then it sets to proximity?

Hey, my server write Couldn’t load ressource gamz-voice

Can you help me ?

How can I change colors per range, so shouting is red whispering is green