Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[New G2O][Client-Side] bindKey
#1
*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):

Squirrel Script
  1. bindKey(KEY_P,"Pressed",function()
  2. {
  3. switch(getPlayerAni(heroId))
  4. {
  5. case "S_RUN": // checking if player is doing nothing
  6. playAni(heroId,"T_STAND_2_PEE")
  7. setFreeze(heroId,true)
  8. break
  9.  
  10. case "S_PEE": // checking if player is peeing
  11. playAni(heroId,"T_PEE_2_STAND")
  12. setFreeze(heroId,false)
  13. break
  14. }
  15. })



*Same example but with holding key ("Both" state):

Squirrel Script
  1. local sw = false
  2.  
  3. bindKey(KEY_P,"Both",function()
  4. {
  5. switch(sw)
  6. {
  7. case false: // checking if player is holding the key
  8. playAni(heroId,"T_STAND_2_PEE")
  9. setFreeze(heroId,true)
  10. break
  11.  
  12. case true: // checking if player released the key
  13. playAni(heroId,"T_PEE_2_STAND")
  14. setFreeze(heroId,false)
  15. break
  16. }
  17.  
  18. sw = !sw
  19. })



*Basic unbind key:

Squirrel Script
  1. function testBindFunc()
  2. {
  3. print("This bind will be called only once!")
  4. unbindKey(KEY_Q,"Pressed",testBindFunc) // removing bind
  5. }
  6. bindKey(KEY_Q,"Pressed",testBindFunc)




*Basic binding timer key:

Squirrel Script
  1. local seconds = 0
  2.  
  3. bindKey(KEY_P,"Down",function()
  4. {
  5. seconds++
  6. print(seconds) // printing seconds in console (~)
  7. },1000,false) // this timer key won't kill the rest, if player is holding more than one key
  8.  
  9. bindKey(KEY_P,"Released",function()
  10. {
  11. seconds = 0 // cleaning seconds variable, when player release P key
  12. })


Reply


Messages In This Thread
[New G2O][Client-Side] bindKey - by Patrix - 07.06.2017, 15:36

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Client] Version check Quarchodron 2 4,010 25.08.2019, 14:06
Last Post: Quarchodron
  [Client] GUI Creator Quarchodron 6 7,516 12.08.2019, 23:05
Last Post: Arkhan
  [New G2O][Shared] Command Handler Patrix 3 6,171 05.09.2018, 15:42
Last Post: Patrix
  [New G2O][Shared] packetListener Patrix 3 6,653 20.06.2018, 18:43
Last Post: Tommy
  [0.1.4.*] [client/server] Simple anty-cheat Profesores 8 10,244 20.03.2018, 19:16
Last Post: Patrix
  [0.1.3] [client/server] BotCreator HammelGammel 22 26,549 08.02.2018, 22:02
Last Post: HammelGammel
  [0.1.3] [client/server] Utility Scripts HammelGammel 1 5,252 27.01.2018, 14:03
Last Post: HammelGammel
  [G2O v.0.1.2][Server-Side] NPC Manager Quarchodron 16 17,484 21.01.2018, 19:59
Last Post: Quarchodron
  [New G2O][Client-Side] Key Combination Patrix 1 3,784 23.12.2017, 13:16
Last Post: Patrix
  [CLIENT]Draw(Line/Color) Tommy 0 3,118 19.12.2017, 04:23
Last Post: Tommy

Forum Jump:


Users browsing this thread: 1 Guest(s)