Gaimo Posted April 9, 2021 Share Posted April 9, 2021 My voice resource is this https://community.multitheftauto.com/index.php?p=resources&s=details&id=15958 I couldn't test it, but does it work? CLIENT-SIDE: addEventHandler("onClientElementStreamIn", root, function () if source:getType() == "player" then if getElementData(source, "call") then return end triggerServerEvent("proximity-voice::broadcastUpdate", localPlayer, getElementsByType("player", root, true)) end end ) addEventHandler("onClientElementStreamOut", root, function () if source:getType() == "player" then if getElementData(source, "call") then return end triggerServerEvent("proximity-voice::broadcastUpdate", localPlayer, getElementsByType("player", root, true)) setSoundPan(source, 0) setSoundVolume(source, 0) end end ) SERVER-SIDE: addCommandHandler("call", function(plr, cmd, target) local target = getPlayerFromPartialName(target) -- return a player setElementData(plr, "call", true) setElementData(target, "call", true) setPlayerVoiceBroadcastTo(plr, target) setPlayerVoiceBroadcastTo(target, plr) end) Link to comment
Addlibs Posted April 9, 2021 Share Posted April 9, 2021 (edited) You should do the element data check on the server's code, as onClientElementStreamIn is triggered for all clients. This means that if we have a player A who is on call (i.e. has the "call" element data set to true), and player B nearby but out of streaming range, and he gets nearer into the streaming range, the event is called on both player A and player B's clients, and normally both would contact the server to update their broadcast list. Player A's event handler was cut short by the if on call return end line, however, player B does not have this cancelling effect and thus updates their broadcast to be able to talk to player A. The entire broadcast update code ought to be improved, but for now the following serverside handler could work: addEvent("proximity-voice::broadcastUpdate", true) addEventHandler("proximity-voice::broadcastUpdate", root, function (broadcastList) -- client has streamed in or out another player and the broadcast list has changed if client and source == client then else return end -- Loop the requested broadcast list and remove players who are on call to someone else than the source element local validList = {} for k, v in ipairs(broadcastList) do if not getElementData(v, "call") or getElementData(v, "call") == source then table.insert(validList, v) end end setPlayerVoiceIgnoreFrom(source, nil) setPlayerVoiceBroadcastTo(source, validList) end ) The above code needs the call command to be edited slightly, namely, to make "cell" element data to reference the player someone is on call with: addCommandHandler("call", function(plr, cmd, target) local target = getPlayerFromPartialName(target) -- return a player setElementData(plr, "call", target) setElementData(target, "call", plr) setPlayerVoiceBroadcastTo(plr, target) setPlayerVoiceBroadcastTo(target, plr) end ) Edited April 9, 2021 by Addlibs Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now