*Introduction:
NOTE! You have to enable event onRender via enableEvent_Render function
Info: This script is stable and propably doesn't have any bugs.
Hello everyone! I've been working on this little framework called "bindKey".
It's is very similar to bindKeys from MTA (Multi Theft Auto) modification.
We can bind some function to specific key and it's key-state only on client-side.
I didn't add this as shared, because it would be useless, we can call some server function from client-side when player click some key.
There are four different key-states: ("Pressed","Down","Released","Both"). You can modify this script whatever you want,
i'm hoping it will be useful in some way.
License
Download
*List of functions:
void bindKey(int or array key, string state, func callback, [[optional: int delay, bool single_downKey ]])
void unbindKey(int or array key, [[optional: string state, func callback, int delay, bool single_downKey ]])
*List of key states: (they're blind to letter capitalization)
"Pressed" // This key state calls function only once, when we pressed the key.
"Down" // This key state calls function more than one time, when we click the key and hold it.
"Released" // This key state calls function only once, when we released the key.
"Both" // This key state calls function only once, but in two states, "Pressed" and "Released".
*Function (bindKey, unbindKey) parameters description:
Info: The more arguments you give in unbindKey function, the more precise you remove bound key(s).
NOTE! You can skip (set as null) only arguments: callback, delay, single_downKey in calling unbindKey function
// Required parameters for bindKey (can't be skipped as null)
int or array key // Key(s) array or id.
string state // The key(s) state (look below).
void callback // The function which will be called.
// Optional parameters for bindKey (only for "Down" state)
int delay // The delay of timer.
bool single_downKey /* If this argument is equal true (default is), it will kill every existing down key timer
(except this one) when player press and hold "Down" key.*/
*Examples:
*Basic key binding (Playing pee animation):
*Same example but with holding key ("Both" state):
*Basic unbind key:
*Basic binding timer key:
NOTE! You have to enable event onRender via enableEvent_Render function
Info: This script is stable and propably doesn't have any bugs.
Hello everyone! I've been working on this little framework called "bindKey".
It's is very similar to bindKeys from MTA (Multi Theft Auto) modification.
We can bind some function to specific key and it's key-state only on client-side.
I didn't add this as shared, because it would be useless, we can call some server function from client-side when player click some key.
There are four different key-states: ("Pressed","Down","Released","Both"). You can modify this script whatever you want,
i'm hoping it will be useful in some way.
License
Download
*List of functions:
void bindKey(int or array key, string state, func callback, [[optional: int delay, bool single_downKey ]])
void unbindKey(int or array key, [[optional: string state, func callback, int delay, bool single_downKey ]])
*List of key states: (they're blind to letter capitalization)
"Pressed" // This key state calls function only once, when we pressed the key.
"Down" // This key state calls function more than one time, when we click the key and hold it.
"Released" // This key state calls function only once, when we released the key.
"Both" // This key state calls function only once, but in two states, "Pressed" and "Released".
*Function (bindKey, unbindKey) parameters description:
Info: The more arguments you give in unbindKey function, the more precise you remove bound key(s).
NOTE! You can skip (set as null) only arguments: callback, delay, single_downKey in calling unbindKey function
// Required parameters for bindKey (can't be skipped as null)
int or array key // Key(s) array or id.
string state // The key(s) state (look below).
void callback // The function which will be called.
// Optional parameters for bindKey (only for "Down" state)
int delay // The delay of timer.
bool single_downKey /* If this argument is equal true (default is), it will kill every existing down key timer
(except this one) when player press and hold "Down" key.*/
*Examples:
*Basic key binding (Playing pee animation):
Squirrel Script
- bindKey(KEY_P,"Pressed",function()
- {
- switch(getPlayerAni(heroId))
- {
- case "S_RUN": // checking if player is doing nothing
- playAni(heroId,"T_STAND_2_PEE")
- setFreeze(heroId,true)
- break
-
- case "S_PEE": // checking if player is peeing
- playAni(heroId,"T_PEE_2_STAND")
- setFreeze(heroId,false)
- break
- }
- })
*Same example but with holding key ("Both" state):
Squirrel Script
- local sw = false
-
- bindKey(KEY_P,"Both",function()
- {
- switch(sw)
- {
- case false: // checking if player is holding the key
- playAni(heroId,"T_STAND_2_PEE")
- setFreeze(heroId,true)
- break
-
- case true: // checking if player released the key
- playAni(heroId,"T_PEE_2_STAND")
- setFreeze(heroId,false)
- break
- }
-
- sw = !sw
- })
*Basic unbind key:
Squirrel Script
- function testBindFunc()
- {
- print("This bind will be called only once!")
- unbindKey(KEY_Q,"Pressed",testBindFunc) // removing bind
- }
- bindKey(KEY_Q,"Pressed",testBindFunc)
*Basic binding timer key:
Squirrel Script
- local seconds = 0
-
- bindKey(KEY_P,"Down",function()
- {
- seconds++
- print(seconds) // printing seconds in console (~)
- },1000,false) // this timer key won't kill the rest, if player is holding more than one key
-
- bindKey(KEY_P,"Released",function()
- {
- seconds = 0 // cleaning seconds variable, when player release P key
- })