OnPlayerKeyStateChange -
Matnix - 01.09.2013
Hello so, I'm asking for you help guys about
OnPlayerKeyStateChange.
I was trying to do a multiple key detection (
if he use the 3 key in the same time) - But I don't really see how I can do that, I've tryed this one but it's doesn't work.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(!IsPlayerInAnyVehicle(playerid) && /*idk*/)
{
if(Test== 1)
{
TestCount[playerid] ++;
if(TestCount[playerid] >= 3)
{
}
}
}
return 1;
}
I visit the wiki sa-mp and I still don't understand how to do it, so if you can explain me how and show me a example code, it's would be nice thanks.
AW: OnPlayerKeyStateChange -
NaS - 01.09.2013
Copy this function to the end of your script:
Код:
IsKeyPressed(newkeys, oldkeys, key)
{
if(newkeys & key && !(oldkeys & key)) return 1;
return 0;
}
Depending on which keys should be pressed (
List Of Keys) use it this way:
In OnPlayerKeyStateChange:
Код:
if(IsKeyPressed(newkeys, oldkeys, KEY_JUMP) && IsKeyPressed(newkeys, oldkeys, KEY_SPRINT))
{
//This code will be executed if both JUMP and SPRINT are pressed!
}
Re: OnPlayerKeyStateChange -
Borg - 01.09.2013
Try to check if key pressed or released. Try
if(newkeys > oldkeys) test++ else test--;
Re : OnPlayerKeyStateChange -
Matnix - 01.09.2013
I've tryed this one Borg, but still don't work.
NaS, I've tryed this :
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(IsKeyPressed(newkeys, oldkeys, KEY_UP) && IsKeyPressed(newkeys, oldkeys, KEY_SPRINT) && IsKeyPressed(newkeys, oldkeys, KEY_JUMP))
{
if(Test == 1)
{
TestCount[playerid] ++;
if(TestCount[playerid] >= 3)
{
}
}
}
return 1;
}
but still don't work..
Re : OnPlayerKeyStateChange -
Matnix - 02.09.2013
bumpy.
Re: OnPlayerKeyStateChange -
Borg - 02.09.2013
You shouldn't use TestCount in NaS variant, 'coz it's already check 3 buttons(KEY_UP, KEY_SPRINT, KEY_JUMP And not forget to set Test to 1. If you want to check if player pressed ANY 3 buttons, try this, it works.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(!IsPlayerInAnyVehicle(playerid))
{
new count = 0;
for(new i = 0; i < 20; i++)
count += (newkeys >> i) & 1;
if(count == 3)
{
SendClientMessageToAll(-1, "3 buttons!");
//TODO...
}
}
return 1;
}
Re : OnPlayerKeyStateChange -
Matnix - 02.09.2013
Quote:
If you want to check if player pressed ANY 3 buttons, try this, it works.
|
I can use a easy way to do this one, so with your example codes "It's will check if he press all of the 3 buttons in the same time"?
Re: OnPlayerKeyStateChange -
Borg - 02.09.2013
My example checks all possible buttons and count pressed ones. So, if count == 3, it will perform action.
If you need to check specified buttons, you should use this example.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(IsKeyPressed(newkeys, oldkeys, KEY_FIRE) && IsKeyPressed(newkeys, oldkeys, KEY_SPRINT) && IsKeyPressed(newkeys, oldkeys, KEY_JUMP))
{
//TODO...
}
return 1;
}
AW: OnPlayerKeyStateChange -
NaS - 02.09.2013
As Borg said above, if you want 3 specific keys to be checked, use my code
without your Test code.