Stranger Posted September 21, 2013 Share Posted September 21, 2013 hello guys how can i attach sounds to the vehicle !! i try to do it but it's hard what is wrong in this: local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) function sound () local sound = playSound3D("s.mp3",1586.3, -1656.8, 28.6, true) setSoundMaxDistance( sound, 50 ) attachElements(sound, mm55, 0, 0, 0) end addEventHandler("onClientResourceStart", resourceRoot, sound) Link to comment
WASSIm. Posted September 21, 2013 Share Posted September 21, 2013 local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) function sound () local x, y, z = getElementPosition ( mm55 ) local sound = playSound3D("s.mp3",x, y, z, true) setSoundMaxDistance( sound, 50 ) attachElements(sound, mm55) end addEventHandler("onClientResourceStart", resourceRoot, sound) Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 thanx but there is a little problem, why i can't enter the vehicle Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 help please Link to comment
PaiN^ Posted September 21, 2013 Share Posted September 21, 2013 You can't enter vehicles created client-side Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 You can't enter vehicles created client-side so what is the solution Link to comment
PaiN^ Posted September 21, 2013 Share Posted September 21, 2013 Create it server-side ( use triggers and stuff ) ... Link to comment
manawydan Posted September 21, 2013 Share Posted September 21, 2013 you can use elementData or triggers, i think Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 Create it server-side ( use triggers and stuff ) ... i did use trigger but , it's not working Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 function sound () local x, y, z = getElementPosition ( mm55 ) local sound = playSound3D("s.mp3",x, y, z, true) setSoundMaxDistance( sound, 50 ) attachElements(sound, mm55) triggerServerEvent("vehicle", localPlayer) end addEventHandler("onClientResourceStart", resourceRoot, sound) addEvent("vehicle", true) addEventHandler("vehicle", root, function () local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) end ) Link to comment
WASSIm. Posted September 21, 2013 Share Posted September 21, 2013 CLIENT local sound = { } addEvent( "onStartMusic", true ) addEventHandler( "onStartMusic", getRootElement(), function (vehicle) if vehicle then local x,y,z = getElementPosition(vehicle) local d = getElementDimension(vehicle) local i = getElementInterior(vehicle) local sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) attachElements(sound[vehicle],vehicle,0,0,0) setSoundMaxDistance(sound[vehicle], 200) setElementDimension(sound[vehicle], d) setElementInterior(sound[vehicle], i) end end ) SERVER addEventHandler("onResourceStart", getRootElement(), function () local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) triggerClientEvent ( "onStartMusic", getRootElement(), mm55 ) end ) Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 the music doesn't working Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 debug ? ERROR: Server triggered clientside event onStartMusic, but event is not added clientside Link to comment
denny199 Posted September 21, 2013 Share Posted September 21, 2013 local sound = { } addEvent( "onStartMusic", true ) addEventHandler( "onStartMusic", root, function (vehicle) if vehicle then local x,y,z = getElementPosition(vehicle) local d = getElementDimension(vehicle) local i = getElementInterior(vehicle) sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) attachElements(sound[vehicle],vehicle,0,0,0) setSoundMaxDistance(sound[vehicle], 200) setElementDimension(sound[vehicle], d) setElementInterior(sound[vehicle], i) end end ) It didn't worked because the table element sound[vehicle] was local. Show us your meta.xml Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 "" type="script" version="1.3.4" /> Link to comment
denny199 Posted September 21, 2013 Share Posted September 21, 2013 It won't trigger because the client side script isn't loaded yet, you can fix this by this: server: addEventHandler("onResourceStart",resourceRoot, function () mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) setTimer ( function () triggerClientEvent ( "onStartMusic", root, mm55 ) end, 3000,1) end ) client: local sound = { } addEvent( "onStartMusic", true ) addEventHandler( "onStartMusic", getRootElement(), function(vehicle) if vehicle then local x,y,z = getElementPosition(vehicle) local d = getElementDimension(vehicle) local i = getElementInterior(vehicle) sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) attachElements(sound[vehicle],vehicle,0,0,0) setSoundMaxDistance(sound[vehicle], 200) setElementDimension(sound[vehicle], d) setElementInterior(sound[vehicle], i) end end) Note: it won't be synced if someone else is joining since you are only trigging it for everyone in the server (root) Link to comment
Stranger Posted September 21, 2013 Author Share Posted September 21, 2013 It won't trigger because the client side script isn't loaded yet, you can fix this by this:server: addEventHandler("onResourceStart",resourceRoot, function () mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) setTimer ( function () triggerClientEvent ( "onStartMusic", root, mm55 ) end, 3000,1) end ) client: local sound = { } addEvent( "onStartMusic", true ) addEventHandler( "onStartMusic", getRootElement(), function(vehicle) if vehicle then local x,y,z = getElementPosition(vehicle) local d = getElementDimension(vehicle) local i = getElementInterior(vehicle) sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) attachElements(sound[vehicle],vehicle,0,0,0) setSoundMaxDistance(sound[vehicle], 200) setElementDimension(sound[vehicle], d) setElementInterior(sound[vehicle], i) end end) Note: it won't be synced if someone else is joining since you are only trigging it for everyone in the server (root) Thank you for helping me 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