berry172 Posted August 28, 2012 Share Posted August 28, 2012 Please help me.Random url music (no radio) on player connect? Link to comment
Al3grab Posted August 28, 2012 Share Posted August 28, 2012 Urlz = { "http://url1.com", "http://url2.com", } function playRandomUrl() if ( Urlz and #Urlz ~= 0 ) then local randomUrl = Urlz[math.random(#Urlz)] if tostring(randomUrl) then theURL = playSound(tostring(randomUrl)) end end end addEventHandler("onClientResourceStart",resourceRoot,playRandomUrl) Link to comment
berry172 Posted August 29, 2012 Author Share Posted August 29, 2012 Not work... Player connect & not play music... Link to comment
Scripting Moderators Sarrum Posted August 29, 2012 Scripting Moderators Share Posted August 29, 2012 local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } addEventHandler ( "onClientResourceStart", resourceRoot, function ( ) playSound ( sounds [ math.random ( 1, #sounds ) ] ) end ) Link to comment
Fury Posted August 29, 2012 Share Posted August 29, 2012 server: local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } function zaa() triggerClientEvent ( "onPlayerJoinMusic", getRootElement(), sounds [ math.random ( 1, #sounds ) ] ) end addEventHandler ( "onPlayerJoin", resourceRoot, zaa) client: function music ( file ) playSound ( file ) end addEvent( "onPlayerJoinMusic", true ) addEventHandler( "onPlayerJoinMusic", root, music ) ---------------------------or------------------------- client: local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } function zaa() playSound ( sounds [ math.random ( 1, #sounds ) ] ) end addEventHandler ( "onClientPlayerJoin", getRootElement(), zaa) Link to comment
Kenix Posted August 29, 2012 Share Posted August 29, 2012 server: local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } function zaa() triggerClientEvent ( "onPlayerJoinMusic", getRootElement(), sounds [ math.random ( 1, #sounds ) ] ) end addEventHandler ( "onPlayerJoin", resourceRoot, zaa) client: function music ( file ) playSound ( file ) end addEvent( "onPlayerJoinMusic", true ) addEventHandler( "onPlayerJoinMusic", root, music ) ---------------------------or------------------------- client: local sounds = { "http://www.mysound1.com/sound1", "http://www.mysound1.com/sound2" } function zaa() playSound ( sounds [ math.random ( 1, #sounds ) ] ) end addEventHandler ( "onClientPlayerJoin", getRootElement(), zaa) Both code is wrong. 1 When player join player need download script so this not triggered to client side. 2 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. Zver-CR's code is correct. 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