How to detect when someone is clicking a button? / Command Zones?
#1

I've seen people using that kind of scripts where you can detect when someone clicks a button on the keyboard it reacts in a certain how would you do that?

Also, if anyone doesn't mind explain how can you create a certain zone that a command can only happen in?
Reply
#2

How to detect a button being pressed:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
Here's a link to all of the KEY_'s
https://sampwiki.blast.hk/wiki/GetPlayerKeys#Key_List

To detect if a command made in an area / zone:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, RANGE, PosX, PosY, PosZ))
{
      .... // code
}
Replace RANGE with the max distance from player to points ( PosX, Y and Z).

Good luck! REP if I helped
Reply
#3

Is it really needed to have an old key? What if he clicks it at any point while he hasn't had clicked any button, by that I mean what if he is afk and he comes back and clicks a button or he connects and its the first button he presses.
Reply
#4

No don't have to use an oldkey
you can use something like this
pawn Код:
if(!IsPlayerInAnyVehicle(playerid))
    {
        if(newkeys == KEY_YES)
        {
              SendClientMessage(playerid, -1, " You are not inside a vehicle. ");
        }
      }
This function says: if a player isn't inside a vehicle and he taps KEY_YES (known as Y) it sends him message he isn't inside a vehicle.
Reply
#5

No, oldkey is optional. Detects the player's old pressed key. Just check for the new as Ceez said and you'll be fine
Reply
#6

One last question! If I make it only new_key do I need to use old_key after or does it keep detecting automatically the old one? :P
Reply
#7

Not at all, btw the correct usage is:
pawn Код:
if(newkeys & KEY_FIRE)
// or
if(oldkeys & KEY_FIRE)
Use the first if you want to use only the newkeys.
SA-MP system makes the hard job.
Reply
#8

let me explain you something
newkeys mean if the player has changed his keys to something else it will use them (if a player's KEY_YES button was Y and he changed to Z, he'll need to click Z for the KEY_YES.)

oldkeys mean if the player has changed/didnt change, key stays the same (if key is KEY_YES, it will stay Y no matter if player changed it or no)
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)