Jump to content

bindKey problem


-stolka-

Recommended Posts

the debugscript reports bad argument for the bindKey function..

function showArrest ( playerSource ) 
local arrest = getAccountData(playeraccount, "arrest") 
if not arrest then 
outputChatBox("you dont have any arrest",playerSource) 
else 
outputChatBox("arrest: "..arrest,playerSource) 
accountN = getAccountName(playeraccount) 
        triggerClientEvent( "onArrestRequest",playerSource, arrest, accountN ) 
end 
end 
addCommandHandler ( "arrest", showArrest ) 
bindKey ( playerSource, "m", "down", showArrest) 

Link to comment

That's because the function bindKey when used server-side, it requires a player element, and 'playerSource' is obviously nil in your script.

addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            bindKey ( player, "m", "down", showArrest ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        bindKey ( source, "m", "down", showArrest ) 
    end 
) 
  
function showArrest ( playerSource ) 
    local playeraccount = getPlayerAccount ( playerSource ) 
    local arrest = getAccountData ( playeraccount, "arrest" ) 
    if ( not arrest ) then 
        outputChatBox ( "you dont have any arrest", playerSource ) 
    else 
        outputChatBox ( "arrest: ".. arrest, playerSource ) 
        local accountN = getAccountName ( playeraccount ) 
        triggerClientEvent ( playerSource, "onArrestRequest", playerSource, arrest, accountN ) 
    end 
end 
addCommandHandler ( "arrest", showArrest ) 

As you can see, I binded the key when the player joins and when the resource starts ( to bind it for everyone ).

Also, "playeraccount" was not defined, you had to get the account with getPlayerAccount.

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