Hotkeys system :)

Started by karan20000000000, Oct 19, 2014, 05:14 AM

Previous topic - Next topic


Hello. My first post ^_^
Hope you'll like it ;)
Ok so first under onScriptLoad you'll need to create some global variables which will represent keybindings using BindKey function.
<variable> <- BindKey(boolean value,hex code,some integer value(keep it 0),0 here too); Well idk whats that boolean value for so keep true as default one.
For hex codes use this website -->
So, here are some of my key bindings
onScriptLoad() {
 I <- BindKey(true, 0x49, 0, 0);
   H <- BindKey(true, 0x48,0,0);
   P <- BindKey(true, 0x50,0,0);
   K <- BindKey(true, 0x4B,0,0);
   L <- BindKey(true, 0x4C,0,0); }
Now, to use these keybindings you have onKeyDown function.
Syntax: onKeyDown(player,key) Now you can simply use your keybindings through their respective variables through switch-case or if-else if.
Here's mine for nitro :
  function onKeyDown(player,key)
{ if(player.Vehicle!=null) { local v=player.Vehicle; v.RelativeSpeed*=1.3;} }
Hope you like this ^_^.

With regards,


nice but for newbies u could have used MessagePlayer instead of nitro which will really confuse newbies like
function onKeyDown(player,key)
if ( key == I )
 { MessagePlayer("Wow U Pressed I BUTTON and IT WORKED :D",player);}
else if ( key == H ) {
 MessagePlayer("wow its still working if u press H :D",player);
hope u understand :D and for nitro post it in another release..
* Karan ([email protected]) has joined #CDM
<Karan> retarded dickheads
* Karan ([email protected]) has left #CDM ("Leaving")


Actually, I believe  they will learn in both ways. ;)
I was wondering when someone will post such a script. It is more like a Speed-Boost instead of Nitro.  :D
Good job !


How is this a snippet? It just explains the BindKey syntax, and should be posted on the wiki instead of here.


You should have posted the email directly because it's more descriptive on the whole process ;D (untested though)

QuoteSorry for the late reply but I haven't visited my email in a while. In vcmp 0.4 you bind a key using the BindKey() function:

BindKey(boolean [down: true = press, false = release], integer [key1: ], integer [key2: ], integer [key3: ]);Note: You can also insert the hex value directly because Squirrel will convert it to integer automatically.

The first parameter tells whether you are binding for the press event instead of the release event. Since it's a boolean if you pass true then it'll create a keybind for the press event and false does the opposite by creating a keybind for the release event.

The three remaining integer parameters represent the unique number (aka the keycode) of the button on the keyboard that you wish to bind to. You can bind to three buttons primary, secondary and alternative.

When you successfully bind a key you get another unique ID which represents the event that you just created. Using that ID you can identify whether the key you binded was used or not. (If the binding fails then you'll receive null as the return value)

If you binded for the release event of a button on the keyboard then you'll receive your events through the onKeyUp() function which has the following signature:

onKeyUp(instance [player: ], integer [bind_id: ]);
If you binded for the press event of a button on the keyboard then you'll receive your events through the onKeyDown() function which has the following signature:

onKeyDown(instance [player: ], integer [bind_id: ]);
The first parameter is an instance of the player who pressed the key. And the second parameter is the unique ID which you received as a return value previously from the BindKey() function. That's how you identify what key that player pressed.

The following snipped should illustrate what I mean:

// Somewhere to store the returned keybind id
local my_bind = null;
function onServerStart()
// Bind for the press event of a keyboard button
my_bind = BindKey(true, 0x50);
// Note: the 0x50 is the keycode for the <P> keyboard button
function onKeyDown(player, bind_id)
// If the bind id matches our bind id then we know the player
// pressed his <P> keyboard button
if (bind_id == my_bind) {
print("You pressed the P keyboard button.");

I might be incorrect about it because nobody documented anything. I just looked at the Squirrel source code and to see how it works. If this is incorrect then you should ask on the forum. Maybe someone from the staff will clear this out.