[QUESTION] OnPlayerGameKeysChange

Started by ., Jan 16, 2015, 02:41 PM

Previous topic - Next topic

.

Here's an interesting question. What is the purpose of "OnPlayerGameKeysChange"? And by that I mean. What does it do? I have a couple of ideas but I don't like to assume things.
.

Fuzzie

It's basically the in-game controls. Eg, W,A,S,D, arrow keys, crouch, etc. It will call the callback every time an in-game control key is pressed.

.

Quote from: Fuzzie on Jan 16, 2015, 04:28 PMIt's basically the in-game controls. Eg, W,A,S,D, arrow keys, crouch, etc. It will call the callback every time an in-game control key is pressed.

Don't confuse this with "OnKeyBindUp" and "OnKeyBindDown".
.

Thijn

It surely can confuse people, but it's there for a reason.

Instead of binding on F, you can bind on the enter vehicle button. I personally like enter more then F. This way it will always be your own personal key bindings, instead of the ones the server owner wants you to use.

I personally don't see a lot of usage in this, but I can imagine people may find it useful.

.

Quote from: Thijn on Jan 16, 2015, 05:13 PMThis way it will always be your own personal key bindings, instead of the ones the server owner wants you to use.

To my understanding, I can bind a key like J for example and if that key is changed by the client to G for example. I get a callback through that function with the 'previous' argument being the ID to the parent/base keybind and the 'current' being the ID to the custom keybind which is like a child/derived keybind.

Couple of questions:
  • Does the parent/base keybind still remains in effect for the rest of the clients who haven't changed the key?
  • If I unbind the parent/base keybind then does the child/derived keybind still remains in effect? Or do I have to unbind the child/derived keybind as well.
  • Is the child/derived keybind a completely separate keybind from the parent/base keybind that I have to account for in my script?
  • [unlikely but possible] If 10 users decide to each have a custom key for a certain keybind then does that mean I have to test against 10 different keybinds to see if a certain action is requested by the client?
  • If the above situation repeats for a couple of other keys as well. Then wouldn't that be a bit overwhelming to the scriptwriter?
  • Isn't there a possibility that there could be a collision between custom keys and what the server expects them to be? (explained bellow)

Fictional situation for collision: Say that I bind the key J to activate nitro and the key K to activate something like a shield on the vehicle and a couple of other keybinds like this. Now ClientX rebinds key J to overlap with key K or another keybind. Does that mean that I have to find another keybind for ClientX in order for him to use nitro. And when I unbind the keybind for key J then do I have to unbind key K for ClientX as well which means I'm loosing the (fictional) shield option for that key? Sorry but I'm lost in the logic here. :-\

While this system does have it's usage I have to say that it looks like a really messed up approach. It's just like something awaiting to explode on the scriptwriter's face on the first chance it gets. I'm still trying to understand it and how to understand collisions and alleviate the burden that the scriptwriter has to go through with multiple rebinds. But for now I kinda get the picture.
.

Stormeus

#5
SLC, that's not what game keys are.

The OnPlayerGameKeysChange event is more or less the same as the OnPlayerKeyStateChange function in R2 Squirrel. Keybinds are for hardcoded keys that a scripter wants to use. Game keys are for detecting changes in Vice City keys. The way it works in 0.4, though, is that there's a mask for keys.

Vice City keys/game keys are what show up in the Options menu when you configure your keyboard or controller. If you want to make it so that you detect when a player is shooting, you can detect ONFOOT_FIRE instead of binding to MOUSE1, which may be inaccurate depending on the player's setup.

A better example: if you want to check when a player is jumping, you can check the ONFOOT_JUMP game key instead of binding to SPACE. This is easier for the scriptwriter than having to guess the user's configuration based on the most common jump keys. Some users might bind jumping to SPACE, but others might use LSHIFT, RSHIFT, etc.

So this is more for detecting a player's game actions. If you want to add a keybind to F7 to avoid interfering with game mechanics or because you don't have enough keys to handle keybinds, you can do that. These keybinds cannot be rebound by the player and never change.

I'll note that the constants for game keys don't exist in Squirrel at this time and will be added soon. Once they're added, I'll throw in a script example.

.

Quote from: stormeus on Jan 16, 2015, 08:10 PMI'll note that the constants for game keys don't exist in Squirrel at this time and will be added soon. Once they're added, I'll throw in a script example.

I'll be waiting for that and thanks for clearing things out. That's why I don't like to assume things.
.

Gudio

#7
An example how to request a spawn by pressing left mouse button:
function onPlayerGameKeysChange( player, old, new )
{
   if ( new == 64 && !player.IsSpawned )
   {
      if ( player.SpectateTarget )
         return;


      if ( onPlayerRequestSpawn( player ) )
         player.Spawn();


      return;
   }
}


Update: Added constants
KEY_ONFOOT_FORWARD
KEY_ONFOOT_BACKWARD
KEY_ONFOOT_LEFT
KEY_ONFOOT_RIGHT
KEY_ONFOOT_JUMP
KEY_ONFOOT_CROUCH
KEY_ONFOOT_PUNCH
KEY_ONFOOT_AIM
KEY_ONFOOT_FIRE
KEY_ONFOOT_NEXTWEP
KEY_ONFOOT_PREVWEP

KEY_INCAR_FORWARD
KEY_INCAR_BACKWARD
KEY_INCAR_LEFT
KEY_INCAR_RIGHT
KEY_INCAR_LOOKLEFT
KEY_INCAR_LOOKRIGHT
KEY_INCAR_LEANUP
KEY_INCAR_LEANDOWN
https://bitbucket.org/stormeus/0.4-squirrel/downloads