2 or 3 keys pressed in the same time | Please help
#1

Hello, I don't know how to determine if, for instance, a play press W and in the same time he pressed also Q or E.. How can I get it..
I have a script like:
if (newkeys == KEY_LOOK_RIGHT) do smth

but this is called when is JUST E pressed without any key.. how can I activate this if even if is another key pressed.
In conclusion I want to know if a key is pressed even another one is also pressed. Thx. I hope you understand me
Reply
#2

Hmm "&&" = and , so you can use this tick.
if (newkeys == KEY_LOOK_RIGHT && "add new one here")
Reply
#3

The wiki page (which you should start checking before posting) has all the information you need on detecting keys reliably.

https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Reply
#4

Quote:
Originally Posted by ZToPMaN
Посмотреть сообщение
Hmm "&&" = and , so you can use this tick.
if (newkeys == KEY_LOOK_RIGHT && "add new one here")
An integer cant be equal to two different values at a time, so that if-code wont ever exeucte.
Reply
#5

You cannot detect two keys at the same time.
But, I think you can detect the keys if the player holds the first key and presses the next key.
Reply
#6

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
You cannot detect two keys at the same time.
But, I think you can detect the keys if the player holds the first key and presses the next key.
Sure you can, just check what Redirect Left posted.
Reply
#7

So, i checked the https://sampwiki.blast.hk/wiki/OnPlayerK..._multiple_keys but I want to know just if Q is pressed doesn't matter which one is also pressed. So I have to check for each combination like if ((newkeys & KEY_LOOK_LEFT) && (newkeys & KEY_CROUCH)) ??

Or if ((newkeys & KEY_LOOK_LEFT) && (newkeys >=-128 ) ), where (newkeys >=-128 ) is for another key (doesnt matter which is)
because -128 is the lowest key value i guess

Am I right or ?
Reply
#8

Quote:
Originally Posted by AdrianG
Посмотреть сообщение
So, i checked the https://sampwiki.blast.hk/wiki/OnPlayerK..._multiple_keys but I want to know just if Q is pressed doesn't matter which one is also pressed. So I have to check for each combination like if ((newkeys & KEY_LOOK_LEFT) && (newkeys & KEY_CROUCH)) ??

Or if ((newkeys & KEY_LOOK_LEFT) && (newkeys >=1)), where (newkeys >=1) is for another key (doesnt matter which is)
First one will work only if the player presses one key after the another.
Reply
#9

Quote:
Originally Posted by AdrianG
Посмотреть сообщение
So, i checked the https://sampwiki.blast.hk/wiki/OnPlayerK..._multiple_keys but I want to know just if Q is pressed doesn't matter which one is also pressed. So I have to check for each combination like if ((newkeys & KEY_LOOK_LEFT) && (newkeys & KEY_CROUCH)) ??

Or if ((newkeys & KEY_LOOK_LEFT) && (newkeys >=-128 ) ), where (newkeys >=-128 ) is for another key (doesnt matter which is)
because -128 is the lowest key value i guess

Am I right or ?
So you want to know if Q and ANY OTHER KEY are pressed at the same time?

pawn Код:
if((newkeys & KEY_LOOK_LEFT) && (newkeys & !KEY_LOOK_LEFT))
@ATGOggy: Quit being that guy that replies to random Scripting Help threads without any clue whether you're right or not. In this case you obviously don't know the answer so get out. No rep for you here.
Reply
#10

Use this:
PHP код:
if ((newkeys KEY_FIRE) && !(oldkeys KEY_FIRE) && (newkeys KEY_CROUCH) && !(oldkeys KEY_CROUCH)) 
Try it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)