FSXTim Posted May 16, 2012 Share Posted May 16, 2012 Hello, I have a problem with my script. When a player press the button XY, a song has to start, but it doesn't. /debugscript 3 error: ... attempt to call global 'playSound' (a nil value) client: function startMusic1 (state) local player = getLocalPlayer() if state == "left" then if source == GUIEditor_Button[13] then triggerServerEvent("Music1", getLocalPlayer(), player) end end end addEventHandler("onClientGUIClick", getRootElement(), startMusic1) server: function Music1 (player) local name = getPlayerName(player) song = playSound("everything.mp3", false) setSoundVolume(song, 1) outputChatBox(name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255) end addEvent("Music1", true) addEventHandler("Music1", getRootElement(), Music1) Can anybody help me, please? Greets Link to comment
Stanley Sathler Posted May 17, 2012 Share Posted May 17, 2012 Show us your meta.xml. Your must set the file (song) in this file. You did it? Something like this: <file src="everything.mp3" /> <script src="server.lua" type="server" /> <script src="client.lua" type="client" /> Oh, and please: show us your directory structure. If you have something like this: /MyGamemode/scripts/server.lua /MyGamemode/scripts/everything.mp3 /MyGamemode/meta.xml You must set, in code, the complete structure: playSound("scripts/everything.mp3", false) And remember: no double posts. Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks for your answer. meta.xml "music\everything.mp3" /> directory: gamemode/shop_client gamemode/shop_server gamemode/music/everything gamemode/meta.xml I will try it like this: 1.playSound("music/everything.mp3", false) Greets Link to comment
Stanley Sathler Posted May 17, 2012 Share Posted May 17, 2012 Yes FSX, is it. Try and come back to say to us. (: Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks for your help, sir! I did it like this: client: function startMusic1 (state) local player = getLocalPlayer() if state == "left" then if source == GUIEditor_Button[13] then triggerServerEvent("Music1", getLocalPlayer(), player) end end end addEventHandler("onClientGUIClick", getRootElement(), startMusic1) server: function Music1 (player) local name = getPlayerName(player) song = playSound("music/everything.mp3", false) setSoundVolume(song, 1) outputChatBox(name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255) end addEvent("Music1", true) addEventHandler("Music1", getRootElement(), Music1) Still not working. Same error: server_shop.lua:3: attempt to call global 'playSound' (a nil value) Greets Link to comment
Stanley Sathler Posted May 17, 2012 Share Posted May 17, 2012 The playSound() function is usable only in client-side. Client-side function startMusic1 (state) local player = getLocalPlayer() if state == "left" then if source == GUIEditor_Button[13] then local song = playSound("music/everything.mp3", false) setSoundVolume(song, 1) triggerServerEvent("Music1", getLocalPlayer(), player) end end end addEventHandler("onClientGUIClick", getRootElement(), startMusic1) Server-side function Music1 (player) local name = getPlayerName(player) outputChatBox(name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255) end addEvent("Music1", true) addEventHandler("Music1", getRootElement(), Music1) Link to comment
Castillo Posted May 17, 2012 Share Posted May 17, 2012 That's wrong FSXTim, you have to trigger to the client side again. -- client side: function startMusic1 ( state ) if ( state == "left" ) then if ( source == GUIEditor_Button[13] ) then triggerServerEvent ( "Music1", localPlayer ) end end end addEventHandler ( "onClientGUIClick", getRootElement(), startMusic1 ) addEvent ( "playTheSound", true ) addEventHandler ( "playTheSound", root, function ( ) song = playSound ( "music/everything.mp3", false ) setSoundVolume ( song, 1 ) end ) -- server side: function Music1 ( ) local name = getPlayerName ( source ) outputChatBox ( name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255 ) triggerClientEvent ( "playTheSound", root ) end addEvent ( "Music1", true ) addEventHandler ( "Music1", getRootElement(), Music1 ) Link to comment
Stanley Sathler Posted May 17, 2012 Share Posted May 17, 2012 Yes, use the Castillo example. The mainly information is: playSound() is not usable on server-side. Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Okay, I see! Thanks for everything, I will tell you, if it is working or not! Greets Link to comment
Castillo Posted May 17, 2012 Share Posted May 17, 2012 Edit your post if it works. You're welcome. Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks, it's working now, but still having one problem. I created a GUI and I can see it perfectly, as you can see here: http://s14.directupload.net/file/d/2891 ... 4_png.htm# But my friend can't see the complete GUI, please have a look: http://s14.directupload.net/file/d/2893 ... kv_png.htm Can anybody test it on my server, if he has the same problem as my friend or can anybody tell me the reason for this problem? Link to comment
Castillo Posted May 17, 2012 Share Posted May 17, 2012 Different resolution must be the problem. Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Thanks for your answer, sir! How can I make it working for everybody? Link to comment
Smart. Posted May 17, 2012 Share Posted May 17, 2012 You could either make the gui in relative mode, or: guiGetScreenSize Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 function() local sWidth, sHeight = guiGetScreenSize() local px = sWidth/1920 local py = sHeight/1080 Still having the same problem as before. Need help, please! Greets Link to comment
Smart. Posted May 17, 2012 Share Posted May 17, 2012 I would just suggest using relative, if you use guieditor (which I assume you do) then right click -> settings -> and mark "Relative" then click save. Or, you could make it even more simple by using: https://wiki.multitheftauto.com/wiki/CenterWindow Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 I'm using the guieditor. But when I mark relativ, it won't relative the texts, buttons and edits, will it? (Only the window, eh?) Greets Link to comment
Smart. Posted May 17, 2012 Share Posted May 17, 2012 Click in the "Default child type" as well. Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Now I did it like this: Default screen output type: [X] Relative [ ] Absolute Default child output type: [X] Relative [ ] Absolute Correct? And by the way, thanks for your help, sir! Link to comment
FSXTim Posted May 17, 2012 Author Share Posted May 17, 2012 Ok, that's working, but can you please help me with teamviewer? Please, I need your help, there is still one problem. Greets 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