Author Topic: What are the parameters of onPlayerKeyStateChange ?  (Read 1510 times)

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
What are the parameters of onPlayerKeyStateChange ?
« on: August 09, 2013, 09:19:41 am »
I need to use onPlayerKeyStateChange, but the wiki doesn't show anything about it, just that it exist.

I'm trying to add info when a player press some buttons.
This is how I did:

Code: [Select]
if(newkeys && "Y") {
But it is not working... and when I press a moveable key of ped, the info appears.
How to fix it ?
( here I use server-side script )

Juppi

  • Developer
  • Jr. Member
  • *****
  • Posts: 86
  • Karma: +3/-1
    • View Profile
    • Kuslahden alaste GTA:MP clan
Re: What are the parameters of onPlayerKeyStateChange ?
« Reply #1 on: August 09, 2013, 09:48:18 am »
onPlayerKeyStateChange only detects GTA's control keys, and it can't be used to detect other keys. For that you'll want to use client-side key binds (BindKey etc.)

The parameters for onPlayerKeyStateChange are a player pointer and two integers, oldkeys and newkeys. These show the current and previous states of the player's GTA controls. For example, if you want to detect whether the fire key was pressed (you can find a list of key constants here)


Code: [Select]
function onPlayerKeyStateChange( player, oldkeys, newkeys )
{
if ( ( oldkeys & KEY_ONFOOT_FIRE == 0 ) && ( newkeys & KEY_ONFOOT_FIRE != 0 ) )
{
MessagePlayer( "Fire key pressed", player );
}
return 1;
}

Didn't actually test it but it should give you the right idea.

sseebbyy

  • Newbie
  • *
  • Posts: 34
  • Karma: +2/-1
    • View Profile
Re: What are the parameters of onPlayerKeyStateChange ?
« Reply #2 on: August 09, 2013, 11:04:58 am »
hhmm, I got it somehow, thank you !

 

© Liberty Unleashed Team.