PDA

View Full Version : Help with OnPlayerKeyStateChange


Merciful
13/12/2016, 04:38 AM
Hey guys,

Basically I am trying to detect if someone is activating some particular hacks. I know some troll hacks and their activation keys and I want to take advantage of OnPlayerKeyStateChange function to tell me if someone is holding those 2 keys together.

Here is my script:

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new Keys,ud,lr;
new name[24];
new string[100];
if(Keys == KEY_ACTION && KEY_SUBMISSION)
{
GetPlayerKeys(playerid,Keys,ud,lr);
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),"Warning :- %s is suspected to be using car troll hacks.",string);
MessageToAdmins(red,string);
}
return 1;
}


This was supposed to detect if someone is HOLDING CTRL + 2 but it is not detecting it.

I kindly request to the scripters here to take out some time to help me fix this script.

Thank you very much in advance :)

X337
13/12/2016, 05:20 AM
Your if() statement is invalid, and you don't need that GetPlayerKeys() since there is a newkeys parameter in that callback.
There's a tutorial on SA-MP wiki about checking multiple keys: http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange#How_to_check_for_multiple_k eys

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new name[24], string[100];
if((newkeys & KEY_ACTION) && (newkeys & KEY_SUBMISSION))
{
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "Warning :- %s is suspected to be using car troll hacks.", name);
MessageToAdmins(red,string);
}
return 1;
}

Merciful
13/12/2016, 09:15 AM
Your if() statement is invalid, and you don't need that GetPlayerKeys() since there is a newkeys parameter in that callback.
There's a tutorial on SA-MP wiki about checking multiple keys: http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange#How_to_check_for_multiple_k eys

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new name[24], string[100];
if((newkeys & KEY_ACTION) && (newkeys & KEY_SUBMISSION))
{
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "Warning :- %s is suspected to be using car troll hacks.", name);
MessageToAdmins(red,string);
}
return 1;
}


Thanks, appreciated.

It is working.