Mawmad Posted September 22, 2023 Share Posted September 22, 2023 Hello I'm Working On a Parking Sensor For MTA:SA Also I'm New To MTA And Scripting My problem is that when I start the resource and move the car in reverse gear, there is no sound Parkings.lua -- parking sensor for mta:sa function isVehicleReversing(theVehicle) local theVehicle = getPedOccupiedVehicle ( thePlayer ) local getMatrix = getElementMatrix (theVehicle) local getVelocity = Vector3 (getElementVelocity(theVehicle)) local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) if (getVectorDirection < 0) then return true function getDistanceBetweenElements(arg1, arg2) local car = Vector3(getPedOccupiedVehicle( arg1 )) local nearObject = Vector3(getNearestElement( arg2 )) local distance = getDistanceBetweenPoints3D( car,nearObject ) if vehicle then local sound = playSound("beep.mp3") setSoundVolume(sound, 0.5) setSoundProperties(sound, 48000.0, 128.00, distance, false) return distance addEventHandler("onClientResourceStart", resourceRoot, isVehicleReversing, getDistanceBetweenElements) -- meta.xml <meta> <script src="parkings.lua" type="client" /> <file src="beep.mp3" type="client" /> </meta> What is wrong with my script? 1 Link to comment
Hydra Posted September 26, 2023 Share Posted September 26, 2023 On 23/09/2023 at 02:17, Mawmad said: Hello I'm Working On a Parking Sensor For MTA:SA Also I'm New To MTA And Scripting My problem is that when I start the resource and move the car in reverse gear, there is no sound Parkings.lua -- parking sensor for mta:sa function isVehicleReversing(theVehicle) local theVehicle = getPedOccupiedVehicle ( thePlayer ) local getMatrix = getElementMatrix (theVehicle) local getVelocity = Vector3 (getElementVelocity(theVehicle)) local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) if (getVectorDirection < 0) then return true function getDistanceBetweenElements(arg1, arg2) local car = Vector3(getPedOccupiedVehicle( arg1 )) local nearObject = Vector3(getNearestElement( arg2 )) local distance = getDistanceBetweenPoints3D( car,nearObject ) if vehicle then local sound = playSound("beep.mp3") setSoundVolume(sound, 0.5) setSoundProperties(sound, 48000.0, 128.00, distance, false) return distance addEventHandler("onClientResourceStart", resourceRoot, isVehicleReversing, getDistanceBetweenElements) -- meta.xml <meta> <script src="parkings.lua" type="client" /> <file src="beep.mp3" type="client" /> </meta> What is wrong with my script? There are a lot of problems with your script Try this: local alarm = nil bindKey("s", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then if isVehicleReversing(vehicle) then local nearObject = getNearestElement(vehicle, "object", 15) if nearObject then if alarm == nil then alarm = playSound("beep.mp3", false) end end end end end) function ForceSoundOff() local vehicle = getPedOccupiedVehicle(localPlayer) if not isVehicleReversing(vehicle) then if alarm ~= nil then stopSound(alarm) alarm = nil end end end addEventHandler("onClientRender", root, ForceSoundOff) function getNearestElement(player, type, distance) local result = false local dist = nil if player and isElement(player) then local elements = getElementsWithinRange(Vector3(getElementPosition(player)), distance, type, getElementInterior(player), getElementDimension(player)) for i = 1, #elements do local element = elements[i] if not dist then result = element dist = getDistanceBetweenPoints3D(Vector3(getElementPosition(player)), Vector3(getElementPosition(element))) else local newDist = getDistanceBetweenPoints3D(Vector3(getElementPosition(player)), Vector3(getElementPosition(element))) if newDist <= dist then result = element dist = newDist end end end end return result end function isVehicleReversing(theVehicle) local getMatrix = getElementMatrix (theVehicle) local getVelocity = Vector3 (getElementVelocity(theVehicle)) local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) if (getVectorDirection < 0) then return true end return false end Link to comment
Mawmad Posted September 26, 2023 Author Share Posted September 26, 2023 Wow , Thanks a Lot Mate ! Sorry and it still doesn't work... Everything seems fine, I don't know what the problem is 1 Link to comment
Hydra Posted September 26, 2023 Share Posted September 26, 2023 39 minutes ago, Mawmad said: Wow , Thanks a Lot Mate ! Sorry and it still doesn't work... Everything seems fine, I don't know what the problem is If you don't hear the sound, try to look for one for about 2-3 seconds maximum and in playSound("beep.mp3", false) put playSound("beep.mp3", true) so that the sound repeats. if this don't work idk then Link to comment
Mawmad Posted September 26, 2023 Author Share Posted September 26, 2023 I Changed playSound("beep.mp3", false) to playSound("beep.mp3", true) And I even tried to increase the getNearestElement limit to 300 but it didn't work 1 Link to comment
FlorinSzasz Posted September 26, 2023 Share Posted September 26, 2023 (edited) On 23/09/2023 at 02:17, Mawmad said: Hello I'm Working On a Parking Sensor For MTA:SA Also I'm New To MTA And Scripting My problem is that when I start the resource and move the car in reverse gear, there is no sound Parkings.lua -- parking sensor for mta:sa function isVehicleReversing(theVehicle) local theVehicle = getPedOccupiedVehicle ( thePlayer ) local getMatrix = getElementMatrix (theVehicle) local getVelocity = Vector3 (getElementVelocity(theVehicle)) local getVectorDirection = (getVelocity.x * getMatrix[2][1]) + (getVelocity.y * getMatrix[2][2]) + (getVelocity.z * getMatrix[2][3]) if (getVectorDirection < 0) then return true function getDistanceBetweenElements(arg1, arg2) local car = Vector3(getPedOccupiedVehicle( arg1 )) local nearObject = Vector3(getNearestElement( arg2 )) local distance = getDistanceBetweenPoints3D( car,nearObject ) if vehicle then local sound = playSound("beep.mp3") setSoundVolume(sound, 0.5) setSoundProperties(sound, 48000.0, 128.00, distance, false) return distance addEventHandler("onClientResourceStart", resourceRoot, isVehicleReversing, getDistanceBetweenElements) -- meta.xml <meta> <script src="parkings.lua" type="client" /> <file src="beep.mp3" type="client" /> </meta> What is wrong with my script? remove type client from there maybe that could be the problem (from client i mean) -> u only need this -> <file src="beep.mp3"/> Edited September 26, 2023 by FlorinSzasz Link to comment
Hydra Posted September 26, 2023 Share Posted September 26, 2023 40 minutes ago, FlorinSzasz said: remove type client from there maybe that could be the problem (from client i mean) -> u only need this -> <file src="beep.mp3"/> There is nothing wrong in meta, you can put type for <file src> too 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