novo Posted December 15, 2012 Posted December 15, 2012 Hello all. I wanna know if it's possible to get current playSound() working by another script. Something like the following; playSound("music.mp3") playSound("https://mtasa.com/"..getCurrentPlaySound()) Bye.
Anderl Posted December 15, 2012 Posted December 15, 2012 You can, however, create a sound "manager" resource. You create all the functions for playing sounds there and save the sound element in a variable inside that resource and then export all functions. Then you create a function to get current sound element. Here's an example: Audio resource > Sound.lua: local pSound = nil SoundPlay = function( path, loop ) pSound = playSound( path, loop ); if ( pSound ) then return true end return false end SoundStop = function() destroyElement( pSound ); if ( not isElement( pSound ) ) then return true end return false end SoundGetCurrent = function() return pSound end Sound resource > meta.xml: <meta> <script src="Sound.lua" type="client" /> <export function="SoundPlay" type="client"/> <export function="SoundStop" type="client"/> <export function="SoundGetCurrent" type="client"/> </meta> Your resource: exports.[[YOUR_AUDIO_RESOURCE_NAME]]:SoundPlay( "sound1.mp3", false ); -- ... local currentSound = exports.[[YOUR_AUDIO_RESOURCE_NAME]]:SoundGetCurrent(); -- ... exports.[[YOUR_AUDIO_RESOURCE_NAME]]:SoundStop(); --or exports["[[YOUR_AUDIO_RESOURCE_NAME]]"]:SoundPlay( "sound1.mp3", false ); -- ... local currentSound = exports["[[YOUR_AUDIO_RESOURCE_NAME]]"]:SoundGetCurrent(); -- ... exports["[[YOUR_AUDIO_RESOURCE_NAME]]"]:SoundStop();
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