berry172 Posted August 23, 2012 Share Posted August 23, 2012 Hello! How to create random playsound connect script? Link to comment
myonlake Posted August 23, 2012 Share Posted August 23, 2012 (edited) This should work unless I made some kind of weird mistake. Remember to add the sound files in your meta.xml file and make sure the path is correct with the table's paths. Client-side local sounds = {"sounds/1.wav", "sounds/2.wav"} addEvent("onPlayerTrueJoin", true) addEventHandler("onPlayerTrueJoin", root, function() playSound(sounds[math.random(1, #sounds)], false) end ) Server-side addEventHandler("onPlayerJoin", root, function() triggerClientEvent(source, "onPlayerTrueJoin", source) end ) Edited August 23, 2012 by Guest Link to comment
Guest Guest4401 Posted August 23, 2012 Share Posted August 23, 2012 This should work unless I made some kind of weird mistake.Yes you made 2 weird mistakes.1. You forgot to read the first sentence of wiki in onClientPlayerJoin: This event is triggered when a player joins a server. It is triggered for all players except the local player, as the local player joins the server before their client-side resources are started. It would also be possible for two players to join within a few seconds of each other and for the two players' scripts may not receive onClientPlayerJoin events as their scripts wouldn't have started yet. 2. playSound(math.random(1, #sounds), false) should be playSound(sounds[math.random(1, #sounds)], false) Link to comment
myonlake Posted August 23, 2012 Share Posted August 23, 2012 Correct there, I'll update my code. Link to comment
Guest Guest4401 Posted August 23, 2012 Share Posted August 23, 2012 Correct there, I'll update my code. Use onClientResourceStart. Because it will say Event not added clientside if you're using onPlayerJoin event to trigger something (If the files aren't downloaded) local sounds = {"sounds/1.wav", "sounds/2.wav"} addEventHandler("onClientResourceStart", resourceRoot, function() playSound(sounds[math.random(1, #sounds)], false) end ) Link to comment
berry172 Posted August 23, 2012 Author Share Posted August 23, 2012 Correct there, I'll update my code. Use onClientResourceStart. Because it will say Event not added clientside if you're using onPlayerJoin event to trigger something (If the files aren't downloaded) local sounds = {"sounds/1.wav", "sounds/2.wav"} addEventHandler("onClientResourceStart", resourceRoot, function() playSound(sounds[math.random(1, #sounds)], false) end ) how to url playsound? Link to comment
Castillo Posted August 23, 2012 Share Posted August 23, 2012 Instead of the file path, you set the URL. 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