Jump to content

A little problem


Starkz

Recommended Posts

Hi, I'm a real newbie in LUA script, and doing "something", I checked it but it doesn't work.

The idea is to play a song (Which is played) and then pressing "space", the song stops.

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    setTimer(function() 
        playSound("winsound.mp3") 
    end, 2000, 1) 
end 
) 
  
function stopMusic(player, key, keyState) 
    if(keyState == "down") then 
        stopSound("winsound.mp3") 
    end 
end 
  
function bindTheKeys(player, commandName) 
    bindKey(player, "space", "down", stopMusic) 
end 

Link to comment

The problem is that "bindTheKeys" function is never executed. Also, bindKey client side has no player argument.

addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        setTimer ( 
            function ( ) 
                sound = playSound ( "winsound.mp3" ) 
                bindKey ( "space", "down", stopMusic ) 
            end 
            ,2000, 1 
        ) 
    end 
) 
  
function stopMusic ( key, keyState ) 
    if ( keyState == "down" ) then 
        stopSound ( sound ) 
    end 
end 

Link to comment
addEventHandler("onClientResourceStart", resourceRoot, 
function() 
    setTimer(function() 
        sound = playSound("winsound.mp3") 
        bindKey("space", "down", stopMusic) 
    end, 2000, 1) 
end 
) 
  
function stopMusic(key, keyState) 
    if(keyState == "down") then 
        stopSound(sound) 
    end 
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...