WhoAmI Posted March 1, 2014 Share Posted March 1, 2014 I got this addCommandHandler("zaczep", function ( ) if (isPedInVehicle(localPlayer)) then local veh = getPedOccupiedVehicle(localPlayer) local x, y, z = getElementPosition(veh) local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) setSoundVolume(sound1, 0.7) setSoundMaxDistance( sound1, 30 ) attachElements(sound1, veh) end end ) addCommandHandler("odczep", function ( ) if (isPedInVehicle(localPlayer)) then local veh = getPedOccupiedVehicle(localPlayer) local elements = getAttachedElements(veh) if (#elements > 0) then for _,sound in ipairs(elements) do if (getElementType(sound) == "sound") then destroyElement(sound) end end end end end ) How i can do that all people can hear the sound? Couse only client can hear it. Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 Trigger a client side event from the server side using triggerClientEvent. Link to comment
WhoAmI Posted March 1, 2014 Author Share Posted March 1, 2014 That's all? addCommandHandler("hardbasson", function (player) triggerClientEvent(player, "bassOn", root) end ) addCommandHandler("hardbassoff", function (player) triggerClientEvent(player, "bassOff", root) end ) @EDIT: It doesn't work. Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 Post the client side, I take it that you have added "bassOn" and "bassOff" events? Also, if you put "player" at triggerClientEvent, it'll only trigger it to the player who used the command. Link to comment
WhoAmI Posted March 1, 2014 Author Share Posted March 1, 2014 addCommandHandler("hardbasson", function (player) local veh = getPedOccupiedVehicle(player) triggerClientEvent("bassOn", root, veh) end ) addCommandHandler("hardbassoff", function (player) local veh = getPedOccupiedVehicle(player) triggerClientEvent("bassOff", root, veh) end ) Client local sound addEvent("bassOn", true) addEventHandler("bassOn", root, function (veh) if (isPedInVehicle(localPlayer)) then local x, y, z = getElementPosition(veh) local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) setSoundVolume(sound1, 0.7) setSoundMaxDistance( sound1, 30 ) attachElements(sound1, veh) end end ) addEvent("bassOff", true) addEventHandler("bassOff", root, function (veh) if (isPedInVehicle(localPlayer)) then local elements = getAttachedElements(veh) if (#elements > 0) then for _,sound in ipairs(elements) do if (getElementType(sound) == "sound") then destroyElement(sound) end end end end end ) It's only for 1 player. Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 Well, you are checking if all the players are in a vehicle, then play the sound. Link to comment
WhoAmI Posted March 1, 2014 Author Share Posted March 1, 2014 Well, It works, but it doesn't attach sound to vehicle. addEvent("bassOn", true) addEventHandler("bassOn", root, function () local veh = getPedOccupiedVehicle(localPlayer) local x, y, z = getElementPosition(veh) local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) setSoundVolume(sound1, 0.7) setSoundMaxDistance( sound1, 40 ) attachElement(sound1, veh) end ) addEvent("bassOff", true) addEventHandler("bassOff", root, function (veh) local veh = getPedOccupiedVehicle(localPlayer) local elements = getAttachedElements(veh) if (#elements > 0) then for _,sound in ipairs(elements) do if (getElementType(sound) == "sound") then destroyElement(sound) end end end end ) Server addCommandHandler("hardbasson", function (player) triggerClientEvent("bassOn", root) end ) addCommandHandler("hardbassoff", function (player) triggerClientEvent("bassOff", root) end ) Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 attachElement(sound1, veh) It's attachElements, not attachElement. Link to comment
WhoAmI Posted March 1, 2014 Author Share Posted March 1, 2014 Ah yea. Client: addEvent("bassOn", true) addEventHandler("bassOn", root, function () local veh = getPedOccupiedVehicle(localPlayer) local x, y, z = getElementPosition(veh) local sound1 = playSound3D("sounds/sound.mp3", x, y, z, true) setSoundVolume(sound1, 0.7) setSoundMaxDistance( sound1, 40 ) attachElements(sound1, veh) end ) addEvent("bassOff", true) addEventHandler("bassOff", root, function (veh) local veh = getPedOccupiedVehicle(localPlayer) local elements = getAttachedElements(veh) if (#elements > 0) then for _,sound in ipairs(elements) do if (getElementType(sound) == "sound") then destroyElement(sound) end end end end ) Server: addCommandHandler("hardbasson", function (player) triggerClientEvent("bassOn", root) end ) addCommandHandler("hardbassoff", function (player) triggerClientEvent("bassOff", root) end ) And know other can't hear this. Only me. Link to comment
Castillo Posted March 1, 2014 Share Posted March 1, 2014 -- client side: addEvent ( "bassOn", true ) addEventHandler ( "bassOn", root, function ( veh ) local x, y, z = getElementPosition ( veh ) local sound1 = playSound3D ( "sounds/sound.mp3", x, y, z, true ) setSoundVolume ( sound1, 0.7 ) setSoundMaxDistance ( sound1, 40 ) attachElements ( sound1, veh ) end ) addEvent ( "bassOff", true ) addEventHandler ( "bassOff", root, function ( veh ) local elements = getAttachedElements ( veh ) if ( #elements > 0 ) then for _, sound in ipairs ( elements ) do if ( getElementType ( sound ) == "sound" ) then destroyElement ( sound ) end end end end ) -- server side: addCommandHandler ( "hardbasson", function ( player ) local veh = getPedOccupiedVehicle ( player ) if ( veh ) then triggerClientEvent( "bassOn", root, veh ) end end ) addCommandHandler ( "hardbassoff", function ( player ) local veh = getPedOccupiedVehicle ( player ) if ( veh ) then triggerClientEvent ( "bassOff", root, veh ) end end ) Link to comment
WhoAmI Posted March 1, 2014 Author Share Posted March 1, 2014 Thanks, I'd test it tomorrow, but I can already see It will work. 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