![]() |
[New G2O][Client-Side] bindKey - Printable Version +- Gothic Online Forums (https://archive.gothic-online.com) +-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html) +--- Forum: Resources (https://archive.gothic-online.com/forum-14.html) +---- Forum: Scripts (https://archive.gothic-online.com/forum-17.html) +---- Thread: [New G2O][Client-Side] bindKey (/thread-2091.html) |
[New G2O][Client-Side] bindKey - Patrix - 07.06.2017 *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
*Same example but with holding key ("Both" state): Squirrel Script
*Basic unbind key: Squirrel Script
*Basic binding timer key: Squirrel Script
RE: [G2O v.0.1.0][Client-Side] bindKey - Patrix - 09.06.2017 Script has been updated. I've removed some repeated things in code. Also i'm thinking to add fourth argument to bindKey function, which could define, if function will be called when we're holding our key more than one time, or only one time. RE: [G2O v.0.1.0][Client-Side] bindKey - Patrix - 09.06.2017 Thread and script has been updated, I've changed how "Pressed" and "Both" state works. Now "Pressed" state is called only once, when we click key (not hold), same thing in "Both". To add function which will be called more than one time when we are holding our key, use "Down" state. Now in thread we have key-states description. RE: [G2O v.0.1.0][Client-Side] bindKey - Patrix - 29.07.2017 Thread and script have been updated. I've fixed errors which were caused by bad if syntax. RE: [G2O v.0.1.0][Client-Side] bindKey - Patrix - 21.08.2017 Thread and script have been updated. I've added new argument into functions: bindKey and unbindKey. This argument is delay of timer, which is calling when you hold your key. NOTE that this script version is stable, but it's experimental. I'm testing this new feature, it's very possible, that i'll add something new in the future ![]() RE: [New G2O][Client-Side] bindKey - Patrix - 20.12.2017 Thread and script have been updated. -Old thread has been completely rewritten. -Script has been optimalized, and added the fitth argument to bindKey and unbindKey functions which is "single_downKey". RE: [New G2O][Client-Side] bindKey - Patrix - 14.11.2018 Script has been updated. -From now on script (down state) doesn't use timers, but onRender event, be sure to enable it! -Removed instant call in down state, first call is after some delay I think that this script (if it's free from bugs) is finished. Maybe it's not the most optimal, but it's not that bad either. |