Jump to content

playSound Error


FSXTim

Recommended Posts

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

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

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

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

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

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

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

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