oldnag Posted April 1, 2013 Posted April 1, 2013 i was just wondering can i make just music play only on the login screen and stop playing when the player spawns ingame
oldnag Posted April 1, 2013 Author Posted April 1, 2013 this is the code i have function startSound ( ) -- Adding the function playSound ( "music.mp3", false ) end addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), startSound ) function stopMySound() stopSound( sound ) end addEventHandler ( "onPlayerSpawn", getRootElement() stopMySound )
Castillo Posted April 1, 2013 Posted April 1, 2013 Use: "onClientPlayerSpawn" and attach it to the local player instead of to the root element. Also, you forgot to define "sound": sound = playSound ( "music.mp3" ) And use destroyElement instead of stopSound.
oldnag Posted April 1, 2013 Author Posted April 1, 2013 ok i changed to this and still no sound plays function startSound ( ) sound = playSound ( "music.mp3" ) end addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), startSound ) function stopMySound() destroyElement( sound ) end addEventHandler ( "onClientPlayerSpawn", localPlayer() stopMySound )
Castillo Posted April 1, 2013 Posted April 1, 2013 addEventHandler ( "onClientPlayerSpawn", localPlayer() stopMySound ) That's wrong, should be: addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound ) Also, check if the sound exist, because the player won't spawn just once, so, use: isElement to check if the sound element exists before attemp to destroy it.
oldnag Posted April 1, 2013 Author Posted April 1, 2013 i have taken out the destry sound atm but still nothing playes when i join the login screen
Castillo Posted April 1, 2013 Posted April 1, 2013 You got me wrong, I didn't told you to remove destroyElement. function stopMySound ( ) if isElement ( sound ) then destroyElement ( sound ) end end addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound )
oldnag Posted April 1, 2013 Author Posted April 1, 2013 ok i tryed that mate but the music still plays after i spawn in function loginMusic () local sound = playSound("music.mp3", false) setSoundVolume(sound, 3.2) end addEventHandler ( "onClientResourceStart", getRootElement(), loginMusic) function stopMySound ( ) if isElement ( sound ) then destroyElement ( sound ) end end addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound )
Castillo Posted April 1, 2013 Posted April 1, 2013 That's because you made your sound variable local: local sound = playSound("music.mp3", false) Should be: function loginMusic () sound = playSound("music.mp3", false) setSoundVolume(sound, 3.2) end addEventHandler ( "onClientResourceStart", resourceRoot, loginMusic) function stopMySound ( ) if isElement ( sound ) then destroyElement ( sound ) end end addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound )
ixjf Posted April 2, 2013 Posted April 2, 2013 And use destroyElement instead of stopSound. Why would one use destroyElement instead of stopSound?
Castillo Posted April 2, 2013 Posted April 2, 2013 Hmm, if I'm right, before it didn't destroy the element, but I may have read wrong, so I guess there's no difference.
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