Jump to content

Sync "playSound"?


Fawxy

Recommended Posts

Posted

I have a script that plays music while in the server, but it doesnt sync up with the other players. Is there something I missed? This command should really be server side anyways.

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted (edited)

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
logo_left.png
Posted

its working if you have added it all right to meta.xml INCLUDING THE SOUND FILE

https://wiki.multitheftauto.com/wiki/Meta.xml

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
<meta>
   <info type="script" version="1.0.0" />
   <script src="musics.lua" type="server"/>
   <script src="musicc.lua" type="client"/>
   <file src="files/song.mp3" />
</meta>

logo_left.png
Posted

you are loading:

files/song.mp3

and want to play:

mariosong.mp3

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

zip your resource and post whole resource.

i dont know HOW and WHAT you messed up, but you messed up something for sure o_O

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
local sound = playSound("mariosong.mp3",false)

you are still trying to load sound without specifying full (but relative to resource root of course) in playSound argument...

local sound = playSound("files/mariosong.mp3",false)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

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.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

they can lie in that case also ..

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
triggerClientEvent(getRootElement(), "playMyMusic", getRootElement())

you are triggering event to local player..

triggerClientEvent("playMyMusic", getRootElement())

maybe lsomething like that ? :roll::?

Server Name: mR|Team Clan Race Server

Server IP: 84.82.81.225:22004

mrteamwebsite.jpg

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

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