Jump to content

Bind key to a specified command in script.


Recommended Posts

Posted

Hi!
I'd like to bind a key on serverside, for a command (/seatbelt), i wrote a pretty good and modern script for it, but its not working with bindKey, it has no errors, i have no clue why. Help please.

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

that is more clear
you can use that as an exemple

you can change down to up 
down is when you press the botton 
and up when you leave the botton

Posted (edited)
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

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