jingzhi Posted February 10, 2015 Posted February 10, 2015 Client side addEvent("onvehiclelock",true) function playSoundLock() playSound3D("lock.wav",vehposx,vehposy,vehposz) outputChatBox("playsound") end addEventHandler("onvehiclelock",getRootElement(),playSoundLock) addEvent("onvehicleunlock",true) function playSoundUnlock() playSound3D("unlock.wav",vehposx,vehposy,vehposz) outputChatBox("playsound") end addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) Server side function lockcar ( thePlayer ) local vehicle = getPedOccupiedVehicle ( thePlayer ) if ( vehicle ) then vehposx,vehposy,vehposz = getElementPosition(vehicle) if isVehicleLocked ( vehicle ) then setVehicleLocked ( vehicle, false ) triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle) outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) else setVehicleLocked ( vehicle, true ) triggerClientEvent(getRootElement(),"onvehiclelock",vehicle) outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) end end end addCommandHandler("lock",lockcar) function unlock(vehicle) setVehicleLocked(vehicle, false) triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle) end addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) I want to make the vehicle play a 3d sond when its locked/unlocked, but it always says the vector3 of play3dsound is nil, please help
JR10 Posted February 10, 2015 Posted February 10, 2015 Server-side and client-side variables are not synced, even if they're global. The position variables never get sent to the client. Another problem you have is getRootElement in triggerClientEvent, this will play the sound for everyone in the server regardless of who triggered the event. Server: function lockcar ( thePlayer ) local vehicle = getPedOccupiedVehicle ( thePlayer ) if ( vehicle ) then local vehposx,vehposy,vehposz = getElementPosition(vehicle) if isVehicleLocked ( vehicle ) then setVehicleLocked ( vehicle, false ) triggerClientEvent(thePlayer,"onvehicleunlock",vehicle, vehposx, vehposy, vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) else setVehicleLocked ( vehicle, true ) triggerClientEvent(thePlayer,"onvehiclelock",vehicle, vehposx, vehposy, vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) end end end addCommandHandler("lock",lockcar) function unlock(vehicle) setVehicleLocked(vehicle, false) triggerClientEvent(source,"onvehicleunlock",vehicle) end addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) Client: addEvent("onvehiclelock",true) function playSoundLock(vehposx, vehposy, vehposz) playSound3D("lock.wav",vehposx,vehposy,vehposz) outputChatBox("playsound") end addEventHandler("onvehiclelock",getRootElement(),playSoundLock) addEvent("onvehicleunlock",true) function playSoundUnlock(vehposx, vehposy, vehposz) playSound3D("unlock.wav",vehposx,vehposy,vehposz) outputChatBox("playsound") end addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock)
SkatCh Posted February 10, 2015 Posted February 10, 2015 -- Client Side function playSoundLock(x,y,z) local sound = playSound3D("lock.wav",x,y,z) setSoundMaxDistance(sound, 100 ) end addEvent("onvehiclelock",true) addEventHandler("onvehiclelock",getRootElement(),playSoundLock) function playSoundUnlock(x,y,z) local sound = playSound3D("unlock.wav",x,y,z) setSoundMaxDistance(sound, 100 ) end addEvent("onvehicleunlock",true) addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) -- Server side function lockcar ( thePlayer ) local vehicle = getPedOccupiedVehicle ( thePlayer ) if ( vehicle ) then vehposx,vehposy,vehposz = getElementPosition(vehicle) if isVehicleLocked ( vehicle ) then setVehicleLocked ( vehicle, false ) triggerClientEvent(thePlayer,"onvehicleunlock",thePlayer,vehposx,vehposy,vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) else setVehicleLocked ( vehicle, true ) triggerClientEvent(thePlayer,"onvehiclelock",thePlayer,vehposx,vehposy,vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) end end end addCommandHandler("lock",lockcar)
jingzhi Posted February 10, 2015 Author Posted February 10, 2015 Server-side and client-side variables are not synced, even if they're global. The position variables never get sent to the client.Another problem you have is getRootElement in triggerClientEvent, this will play the sound for everyone in the server regardless of who triggered the event. Server: function lockcar ( thePlayer ) local vehicle = getPedOccupiedVehicle ( thePlayer ) if ( vehicle ) then local vehposx,vehposy,vehposz = getElementPosition(vehicle) if isVehicleLocked ( vehicle ) then setVehicleLocked ( vehicle, false ) triggerClientEvent(thePlayer,"onvehicleunlock",vehicle, vehposx, vehposy, vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) else setVehicleLocked ( vehicle, true ) triggerClientEvent(thePlayer,"onvehiclelock",vehicle, vehposx, vehposy, vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) end end end addCommandHandler("lock",lockcar) function unlock(vehicle) setVehicleLocked(vehicle, false) triggerClientEvent(source,"onvehicleunlock",vehicle) end addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) Client: addEvent("onvehiclelock",true) function playSoundLock(vehposx, vehposy, vehposz) playSound3D("lock.wav",vehposx,vehposy,vehposz) outputChatBox("playsound") end addEventHandler("onvehiclelock",getRootElement(),playSoundLock) addEvent("onvehicleunlock",true) function playSoundUnlock(vehposx, vehposy, vehposz) playSound3D("unlock.wav",vehposx,vehposy,vehposz) outputChatBox("playsound") end addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) Hey its still not working, I made it like you said Server function lockcar ( thePlayer ) local vehicle = getPedOccupiedVehicle ( thePlayer ) if ( vehicle ) then local vehx,vehy,vehz = getElementPosition(vehicle) if isVehicleLocked ( vehicle ) then setVehicleLocked ( vehicle, false ) triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle, vehx,vehy,vehz) outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) else setVehicleLocked ( vehicle, true ) triggerClientEvent(getRootElement(),"onvehiclelock",vehicle,vehx,vehy,vehz) outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) end end end addCommandHandler("lock",lockcar) function unlock(vehicle) setVehicleLocked(vehicle, false) triggerClientEvent(getRootElement(),"onvehicleunlock",vehicle,vehx,vehy,vehz) end addEventHandler("onPlayerVehicleExit",getRootElement(),unlock) Client addEvent("onvehiclelock",true) function playSoundLock() playSound3D("lock.mp3",vehx,vehy,vehz) end addEventHandler("onvehiclelock",getRootElement(),playSoundLock) addEvent("onvehicleunlock",true) function playSoundUnlock() playSound3D("unlock.mp3",vehx,vehy,vehz) end addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock)
SkatCh Posted February 10, 2015 Posted February 10, 2015 do it like this -- Client side function playSoundLock(x,y,z) local sound = playSound3D("lock.wav",x,y,z) setSoundMaxDistance(sound, 100 ) end addEvent("onvehiclelock",true) addEventHandler("onvehiclelock",getRootElement(),playSoundLock) function playSoundUnlock(x,y,z) local sound = playSound3D("unlock.wav",x,y,z) setSoundMaxDistance(sound, 100 ) end addEvent("onvehicleunlock",true) addEventHandler("onvehicleunlock",getRootElement(),playSoundUnlock) -- server side function lockcar ( thePlayer ) local vehicle = getPedOccupiedVehicle ( thePlayer ) if ( vehicle ) then vehposx,vehposy,vehposz = getElementPosition(vehicle) if isVehicleLocked ( vehicle ) then setVehicleLocked ( vehicle, false ) triggerClientEvent(thePlayer,"onvehicleunlock",thePlayer,vehposx,vehposy,vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been unlocked", thePlayer,0,255,0) else setVehicleLocked ( vehicle, true ) triggerClientEvent(thePlayer,"onvehiclelock",thePlayer,vehposx,vehposy,vehposz) outputChatBox("Your "..getVehicleName(vehicle).." have been locked", thePlayer,0,255,0) end end end addCommandHandler("lock",lockcar)
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