Timiimit Posted December 9, 2011 Posted December 9, 2011 HI! does anyone know how to make music speed depends on speed of player?
myonlake Posted December 9, 2011 Posted December 9, 2011 Not sure if it's even possible to change the music speed yet?
Timiimit Posted December 9, 2011 Author Posted December 9, 2011 how about in beta test. there was nyan cat and music went depending on player speed!
BinSlayer1 Posted December 9, 2011 Posted December 9, 2011 https://wiki.multitheftauto.com/wiki/SetSoundSpeed https://wiki.multitheftauto.com/wiki/GetElementSpeed You'll need to get your own formula so that sound speed changes based on the element speed
Timiimit Posted December 9, 2011 Author Posted December 9, 2011 i tried but don't know how to make it work. my script: sound = playSound ( "music.mp3", true ) setSoundVolume ( sound, 1 ) can you help?
BinSlayer1 Posted December 9, 2011 Posted December 9, 2011 --FUNCTION FROM WIKI: [url=https://wiki.multitheftauto.com/wiki/GetElementSpeed]https://wiki.multitheftauto.com/wiki/GetElementSpeed[/url] function getElementSpeed(element,unit) if (unit == nil) then unit = 0 end if (isElement(element)) then local x,y,z = getElementVelocity(element) if (unit=="mph" or unit==1 or unit =='1') then return (x^2 + y^2 + z^2) ^ 0.5 * 100 else return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 end else outputDebugString("Not an element. Can't get speed") return false end end ---------------------- --YOUR SCRIPT sound = playSound ( "music.mp3", true ) setSoundVolume ( sound, 1 ) ------------- setTimer(function() local speed = getElementSpeed(getLocalPlayer(), 'mph') speed = math.floor(speed) local soundSpeed if speed < 20 then soundSpeed = 1 else soundSpeed = speed*0.05 end setSoundSpeed(sound, soundSpeed) end, 200, 0 ) Test this. It's a start for you and you can easily edit it now
AGENT_STEELMEAT Posted December 9, 2011 Posted December 9, 2011 Why on earth would you use a timer? -.- local sound = playSound("music.mp3", true) --This function adjusts the speed of the sound, every render, based on the local player's velocity. local function adjustSoundSpeed() --Remove this event handler is the sound is removed if not isElement(sound) then removeEventHandler("onClientRender", root, adjustSoundSpeed) return end --Determine whether or not to calculate the speed of the local player, or the vehicle he/she is in. local player = localPlayer if isPedInVehicle(player) then player = getPedOccupiedVehicle(player) end --Calculate the velocity of the local player local velX, velY, velZ = getElementVelocity(player) local velocity = (velX^2 + velX^2 + velX^2)^(0.5) --Calculate a reasonable speed local speed = --[[ ************* THIS IS UP TO YOU TO DO ****************]] setSoundSpeed(sound, speed) end addEventHandler("onClientRender", root, adjustSoundSpeed) That is a better solution. Note, however, that I've left it up to YOU to determine the speed based on the velocity, since you must decide the limits an such. Remember that speed must be between 0 and 1.
BinSlayer1 Posted December 10, 2011 Posted December 10, 2011 Why on earth would you use a timer? -.- I didn't think it was something worth calculated/recalculated every single frame.. You will most of the time not change your speed that much between 2 frames so I doubt there will be any significant changes
Timiimit Posted January 27, 2012 Author Posted January 27, 2012 thx for everithing! my finished script: sound = playSound ("nyancat.mp3", true) local function adjustSoundSpeed() --Remove this event handler is the sound is removed if not isElement(sound) then removeEventHandler("onClientRender", root, adjustSoundSpeed) return end local player = localPlayer if isPedInVehicle(player) then player = getPedOccupiedVehicle(player) end --Calculate the velocity of the local player local velX, velY, velZ = getElementVelocity(player) local velocity = (velX^2 + velY^2 + velZ^2)^(0.5) local speed = velocity / 2 -- Get the time local hour, minute = getTime ( ) -- Perform difficultz calculatus when time is involved if hour >= 0 and hour < 2 then if hour == 1 then minute = minute + 60 end local vol = 0.8 * getEasingValue ( ( 1 / 120 ) * minute, "InQuad" ) setSoundVolume ( sound, vol ) elseif hour >= 5 and hour < 7 then if hour == 6 then minute = minute + 60 end local vol = 0.8 * ( 1 - getEasingValue ( ( 1 / 120 ) * minute, "OutQuad" ) ) setSoundVolume ( sound, vol ) elseif hour >= 2 and hour < 5 then setSoundVolume ( sound, 0.8 ) else setSoundVolume ( sound, 0 ) return end --Calculate a reasonable speed velocity = velocity + 1.5 speed = velocity / 3 setSoundSpeed( sound, speed ) end addEventHandler("onClientRender", root, adjustSoundSpeed)
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