Jump to content

Bind key to a specified command in script.


Recommended Posts

10 hours ago, NOONE said:

 function exemple () 
end
bindKey ( player, "F1", "down", exemple )

 

That's not hooked to a command but to a function..

--client
function smt()
  outputChatbox("smt")
end
addCommandHandler("smt_command", smt)

bindKey("o", "up", "smt_command")

On server:

--server

addEventHandler("onResourceStart", resourceRoot, function() -- in case you restart or start the resource while the server is running
    for k, v in ipairs(getElementsByType("player")) do
      bindKey(v, "o", "up", "smt_command")
    end
end)

addEventHandler("onPlayerJoin", root, function() -- when somebody new joins and missed the "onResourceStart" event, bind the command to the source only
    bindKey(source, "o", "up", "smt_command")
end)

function smt(p)
  outputChatbox("smt", p)
end
addCommandHandler("smt_command", smt)

 

Edited by pa3ck
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...