PyArroz Posted September 10, 2020 Posted September 10, 2020 local themes = { "sounds/RADAR.mp3", "sounds/RADAR2.mp3", "sounds/RADAR3.mp3", } local sound = {} function Ruiner2000theme() local allVehicles = getElementsByType("vehicle") for index, veh in ipairs (allVehicles) do local model = getElementModel(veh) if model == 494 then if getVehicleEngineState(veh) then if isElement(sound[veh]) then triggerServerEvent ( "fullyloaded", resourceRoot) else local x, y, z = getElementPosition(veh) sound[veh] = playSound3D( math.random( 1,#themes ), x, y, z, true) attachElements(sound[veh], veh) setSoundMaxDistance(sound[veh], 1000) end else if isElement(sound[veh]) then destroyElement(sound[veh]) end end end end end addEventHandler("onClientPreRender", root, Ruiner2000theme) I have tried to make a script that when I get on the Ruiner 2000 it plays songs randomly, it works if I put the song as "RADAR.mp3", but it doesn't work if I put the mathrandom table, I have added the songs correctly in the meta and I don't know why it does not work
Moderators IIYAMA Posted September 10, 2020 Moderators Posted September 10, 2020 1 hour ago, Andres99907 said: songs correctly in the meta and I don't know why it does not work This code is executed every frame. I can see that you add some validation checks. But check the execution rate of the following code, if it is too high it will be a much bigger than not playing sounds: 1 hour ago, Andres99907 said: isElement(sound[veh]) then triggerServerEvent ( "fullyloaded", resourceRoot) else As for the not playing sound, you forgot to index the table: themes[math.random(#themes )] 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
PyArroz Posted September 10, 2020 Author Posted September 10, 2020 1 hour ago, IIYAMA said: This code is executed every frame. I can see that you add some validation checks. But check the execution rate of the following code, if it is too high it will be a much bigger than not playing sounds: As for the not playing sound, you forgot to index the table: themes[math.random(#themes )] :3 Thk you bro, it worked 1
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