Jump to content

Random url music (no radio) on player connect?


berry172

Recommended Posts

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
  • Scripting Moderators
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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...