Ben_Sherman Posted March 26, 2014 Posted March 26, 2014 Hello everyone, I'm making a K9 script and so far everything is working well besides that I can't seem to get the barking part working for everyone thats near the K9, it's only playing the sound for the player that executes the command. Any idea whats wrong here? function Bark() local x, y, z = getElementPosition(getLocalPlayer()) local int = getElementInterior(getLocalPlayer()) local dim = getElementDimension(getLocalPlayer()) local px, py, pz = getElementPosition(getLocalPlayer()) if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then local sound = playSound3D("Barking.wav", x, y, z) setSoundMaxDistance(sound, 40) setElementDimension(sound, dim) setElementInterior(sound, int) attachElements ( sound, getLocalPlayer() ) if (isPedInVehicle(getLocalPlayer())) then setSoundVolume(sound, 0.5) else setSoundVolume(sound, 1.0) end end end addCommandHandler("bark", Bark)
WhoAmI Posted March 26, 2014 Posted March 26, 2014 You have to get player serverside and trigger server event for everyone. It should look like -- server addCommandHandler ( "bark", function ( player ) triggerClientEvent ( "barkEvent", player ) end ) -- client function Bark () local x, y, z = getElementPosition(source) local int = getElementInterior(source) local dim = getElementDimension(source) local px, py, pz = getElementPosition(source) if (getDistanceBetweenPoints3D(x, y, z, px, py, pz)<50) then local sound = playSound3D("Barking.wav", x, y, z) setSoundMaxDistance(sound, 40) setElementDimension(sound, dim) setElementInterior(sound, int) attachElements ( sound, source ) if (isPedInVehicle(source)) then setSoundVolume(sound, 0.5) else setSoundVolume(sound, 1.0) end end end addEvent ( "barkEvent", true ) addEventHandler ( "barkEvent", root, Bark )
Ben_Sherman Posted March 26, 2014 Author Posted March 26, 2014 Thanks man, works like a charm. Now I've learned something new today. Big thanks from sweden!
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