Cronoss Posted January 27, 2022 Share Posted January 27, 2022 Hello Everybody, I need help with this specific function in client-side The main script (/bloquear function) it's in server-side, I know playSound3D must be in Client-Side but I don't know how to connect them, because in server side the script look like this: addCommandHandler("bloquear", function(player,cmd) local acc = player:getAccount() local owner = acc:getName() local vehicle = getNearestVehicle(player,5) or Ped.getOccupiedVehicle(player) if (vehicle:getData("vehicles:owner") == owner) then setPlayerVehicleLocked(player, vehicle) else player:outputChat("", 255, 0, 0) end end) function setPlayerVehicleLocked(player, vehicle) local vehname = vehicle:getName() if (vehicle:getData("vehicles:locked") == 1) then vehicle:setData("vehicles:locked", 0) vehicle:setLocked(false) player:outputChat("> Desbloqueaste tu "..vehname..".", 233, 24, 189) connection:exec("UPDATE vehicles SET locked=? WHERE id=? AND owner=?", 0, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner")) elseif (vehicle:getData("vehicles:locked") == 0) then vehicle:setData("vehicles:locked", 1) vehicle:setLocked(true) player:outputChat("> Bloqueaste tu "..vehname..".", 233, 24, 189) connection:exec("UPDATE vehicles SET locked=? WHERE id=? AND owner=?", 1, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner")) end end And in Client side looks like this: local x, y, z = client:getPosition() function sonidoBloq() local bloqueo = playSound3D( "sonidoBloq.mp3", x, y, z, false ) setSoundMaxDistance(bloqueo,10) end addEventHandler(???) When I try to connect them, with "callClientFunction" or any variant of it, the resource stop working and hides every vehicle. It only happens with the playsound, I've tried making another client-side functions and works, but with this simply It doesn't work Link to comment
βurak Posted January 27, 2022 Share Posted January 27, 2022 (edited) local x, y, z = getElementPosition(localPlayer) -- get player position function sonidoBloq() local bloqueo = playSound3D("sonidoBloq.mp3", x, y, z, false) setSoundMaxDistance(bloqueo, 10) end addEvent("playSound", true) -- add event with name "playSound" or whatever you want addEventHandler("playSound", root, sonidoBloq) -- add event listener create an event on the client side to play the sound you can use triggerClientEvent to call this on server side triggerClientEvent(player, "playSound", player) Edited January 27, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 It seems so easy now, thank you for your help Just one more thing, if I want the "x, y, z" to play the sound, is that possible without being inside the car? Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) yes it's possible you can call it with triggerClientEvent likewise triggerClientEvent(player, "playSound", player) but be careful with the player parameter because it will change based on where it is called. As an example, here I made 3 parameters as posX, posY, posZ. function sonidoBloq(posX, posY, posZ) local bloqueo = playSound3D("sonidoBloq.mp3", posX, posY, posZ, false) setSoundMaxDistance(bloqueo, 10) end addEvent("playSound", true) -- add event with name "playSound" or whatever you want addEventHandler("playSound", root, sonidoBloq) -- add event listener you can run it on the server side with triggerClientEvent in the same way, but here we will need to add 3 x, y, z coordinates as an extra, so we can play the sound in the coordinates we want. triggerClientEvent(player, "playSound", player, 0, 50, 3) -- play sound 0,50,3 coordinates Edited January 28, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 I just tested again the first code (x,y,z of the player) and I don't know why, but if I leave the position where the vehicle was before connecting, the playsound doesn't work Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) function sonidoBloq() local x, y, z = getElementPosition(localPlayer) -- get player position local bloqueo = playSound3D("sonidoBloq.mp3", x, y, z, false) setSoundMaxDistance(bloqueo, 10) end addEvent("playSound", true) -- add event with name "playSound" or whatever you want addEventHandler("playSound", root, sonidoBloq) -- add event listener hmmm can you try to enclose the getElementPosition in a function? Edited January 28, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 It worked!! Thank you so much for helping me 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 Uh, and what If I want other players hear it? 1 Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) oh my fault sorry forgot to say triggerClientEvent(root, "playSound", player) change the first player parameter to root this should work so it will send to all players Edited January 28, 2022 by Burak5312 1 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