Jump to content

Sync "playSound"?


Fawxy

Recommended Posts

just trigger event from server to client like:

SERVER:

function some_function()
if (something_happen) then
triggerClientEvent(getRootElement(), "playMyMusic", getRootElement())
end
end

CLIENT:

addEvent("playMyMusic",true)
addEventHandler("playMyMusic", getRootElement(), function()
playSound (parameters, here)
--or any other things
end)

EDIT:

afair you can overwrite mta native functions, so write own server side playSound :P (in the way showed above - but when triggering client event also pass filename parameter - to play correct file on client) search wiki for examples of triggering events :)

Link to comment

i tried and failed, could anyone fix it :wink:

client

addEvent("playMyMusic",true)
addEventHandler("playMyMusic", getRootElement(), function()
local sound = playSound("mariosong.mp3",false) 
setSoundVolume(sound, 1.0)
end)

server

function PlayMusic()
triggerClientEvent(getRootElement(), "playMyMusic", getRootElement())
end
addCommandHandler("play", PlayMusic)

Edited by Guest
Link to comment

you are making me wanna kill myself.. :roll:

maybe the others are deaf? or they are lying to you? or they have sound turned off?

on client side put:

addEvent("playMyMusic",true)
addEventHandler("playMyMusic", getRootElement(), function()
local sound = playSound("files/mariosong.mp3",false) 
setSoundVolume(sound, 1.0)
outputChatBox("this is freaking DEBUG, DEBUG FTW!")
end)

read this (btw: read whole manual before asking anything)

https://wiki.multitheftauto.com/wiki/Debugging

and if you are really desperated use this for debug (gift from me):

server

function PlayMusic()
triggerClientEvent(getRootElement(), "playMyMusic", getRootElement())
end
addCommandHandler("mario", PlayMusic)
 
addEvent("catchDebug", true)
addEventHandler("catchDebug", getRootElement(), function()
local name=getPlayerName(source)
outputChatBox(name.." should hear the sound - debug don't lie"
end)

client

addEvent("playMyMusic",true)
addEventHandler("playMyMusic", getRootElement(), function()
local sound = playSound("files/mariosong.mp3",false) 
setSoundVolume(sound, 1.0)
outputChatBox("this is freaking DEBUG, DEBUG FTW!")
triggerServerEvent("catchDebug", getLocalPlayer())
end)

and..

i gave you a link,

again:

https://wiki.multitheftauto.com/wiki/Debugging

I don't think so you will bother to read

but you can read there about debugscript command.

Use it to spot errors in your script.

Do "/debugscript 3" in chat

or "debugscript 3" in console.

Link to comment

Ask them to type the command. They will triggerClientEvent and if you can hear the music after they type the command in, they can hear the music when you type the command in.

Link to comment
triggerClientEvent(getRootElement(), "playMyMusic", getRootElement())

you are triggering event to local player..

triggerClientEvent("playMyMusic", getRootElement())

maybe lsomething like that ? :roll::?

Do you know what you're talking about? Both of them are correct. There is no local player on server-side.

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