SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 30/08/2009, 07:32 AM   #1
Abernethy
Gangsta
 
Join Date: May 2009
Posts: 898
Reputation: -1
Default OnPlayerKeyStateChange

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  new keys, updown, leftright;
    new Float:X, Float:Y, Float:Z;
    if (AirBreakMode[playerid] == 1)
    {
      GetPlayerKeys(playerid, keys, updown, leftright);

      if (updown == KEY_UP)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y+2.5, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
        else if (updown == KEY_DOWN)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y-2.5, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
       
        else if (leftright == KEY_RIGHT)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X+2.5, Y, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
       
        else if (leftright == KEY_LEFT)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X-2.5, Y, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
    }
    return 1;
}
I've been trying to make a little bit of code that when you type /amove. You enter a mode where you can press the UP, DOWN, LEFT, & RIGHT keys to move Y+/- and X+/-
It isn't going too well. I don't have much experience at all with OnPlayerKeyStateChange. When I press capslock though; my character moves Y-2.5. I need to know how to properly use this.
Abernethy is offline  
Old 30/08/2009, 08:59 AM   #2
Zeex
Guest
 
Posts: n/a
Default Re: OnPlayerKeyStateChange

Use "&" operator (bit and), e.g.:
pawn Code:
if (newkeys & KEY_ANALOG_UP)
{
    // Up arrow pressed
}
if (newkeys & KEY_ANALOG_LEFT)
{
    // left arrow pressed
}
....
etc.
 
Old 30/08/2009, 09:35 AM   #3
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 6,340
Reputation: 365
Default Re: OnPlayerKeyStateChange

You can't detect keys UP, DOWN, LEFT or RIGHT at OnPlayerKeyStateChange callback, use GetPlayerKeys with the timer.
Correlli is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Onplayerkeystatechange Razvann Help Archive 2 26/03/2010 07:50 PM
OnPlayerKeyStateChange Zoutdaxv Help Archive 9 12/12/2009 02:10 AM
help with OnPlayerKeyStateChange KIDUL Help Archive 6 31/10/2009 04:36 PM
[HELP]OnPlayerKeyStateChange RedFaction444 Help Archive 2 01/08/2009 07:59 PM
OnPlayerKeyStateChange [top_Shoter] Help Archive 17 19/07/2009 09:57 AM


All times are GMT. The time now is 03:54 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.