Jump to content

[Help] Play Music Serverside


BieHDC

Recommended Posts

Hello,

how the subject already tell, i want to play the music serverside.

Why?

I wanna make a Harlem Shake Map and the Music should be 100% sincron with the moving objects, which are also serverside.

The sound should start whan map start, like moving objects.

I already scriped something, but i want to now if it could work:

  
-- define the onGamemodeMapStart handler function 
function onGamemodeMapStart() 
    -- play sound 
    callClientFunction(source, "sound = playSound", "harlem.mp3) 
end 
-- add the event handler 
addEventHandler("onGamemodeMapStart", root, onGamemodeMapStart) 
  
  
 

Link to comment

you can't play the sound server side you can only trigger a client event to play the sound client side

you didn't make a client side , did you? that's why its not working , you gotta create a client side file then put this function in

function callClientFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do arg[key] = tonumber(value) or value end 
    end 
    loadstring("return "..funcname)()(unpack(arg)) 
end 
addEvent("onServerCallsClientFunction", true) 
addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction) 

also in your serverside you gotta put this function

function callClientFunction(client, funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do 
            if (type(value) == "number") then arg[key] = tostring(value) end 
        end 
    end 
    -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element 
    triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) 
end 

also you've forgot to close the string

-- define the onGamemodeMapStart handler function 
function onGamemodeMapStart() 
    -- play sound 
    callClientFunction(source, "sound = playSound", "harlem.mp3") 
end 
-- add the event handler 
addEventHandler("onGamemodeMapStart", root, onGamemodeMapStart) 
  
  

Link to comment

you wasn't really have to use call client function because you can do it with trigger event i just post it cause you said yours not working , anyways you can make it simply like this :

-- server side ( server.lua ) 
addEventHandler("onPlayerSpawn",root,function () -- links the event onPlayerSpawn with a function 
triggerClientEvent(source,"PlaySound",source) -- triggers the client side event "PlaySound" which plays the sound just for the source player 
end) 
  
-- client side (client.lua)  
addEvent("PlaySound",true) -- creates a custom event 
addEventHandler("PlaySound",root,function () -- links the custom event with a function 
sound = playSound("harlem.mp3") -- defines and plays the sound file harlem.mp3 
end) 
  

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