PDA

View Full Version : Little Assistance on a "SprintBind" Detection System


Th3b3ast5
22/07/2013, 07:29 AM
So I've been wondering, how would this system work? What I've come to a conclusion with is that if the player presses a given Key more than a given amount of times per second, that this would send a message saying that they may be using a sprintbind, if this is the right direction of this system, let me know by posting down there.. I may have more inquiries.. Thanks if you respond and let me know.

Edit: If you can, give me a format of how this would be scripted, if a player clicks a key a certain amount of times in a second that it would send a message, not an advanced scripter. Thanks in advance.

Donvalley
22/07/2013, 07:33 AM
http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange#Detecting_holding_a_key

hope that helps

Th3b3ast5
22/07/2013, 07:37 AM
I understand the whole "OnPlayerKeyStateChange" consept, but how would you make it check for How many times a given key in pressed in a given time period?

Donvalley
22/07/2013, 07:39 AM
// HOLDING(keys)
#define HOLDING(%0) \
((newkeys & (%0)) == (%0))


if (HOLDING( KEY_SPRINT ))
{
SendClientMessageToAll(COLOR_YELLOW, "Someone is holding the sprint key");
return 1;
}


example.... is that what your after?

Th3b3ast5
22/07/2013, 07:54 AM
Not exactly.. I'm after if a player presses the Sprint Key 13+ times within a second, it would send a message to the Moderators/Admins that the player is using a bind.

Donvalley
22/07/2013, 08:01 AM
ahhh i understand. i will look into it aswell :)

Th3b3ast5
22/07/2013, 05:48 PM
Anybody else know how this would look?

Pottus
22/07/2013, 07:24 PM
Sure this is pretty easy.


// PRESSED(keys)
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

// Amount of time between press
#define MINIMUM_PRESS_TIME 20

// Amount of times in a row to be considered sprint macro
#define EXCESSIVE_PRESS_COUNT 5

// Last time a player pressed sprint
new LastPressTime[MAX_PLAYERS];

// Amount of times in a row exccessively fast sprinting has been detected
new SprintPressCounter[MAX_PLAYERS];

//Pressed a key
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Sprint was pressed
if(PRESSED(KEY_SPRINT))
{
// Did the player press sprint too quickly ?
if(GetTickCount() - LastPressTime[playerid] < MINIMUM_PRESS_TIME)
{
// Increment press counter
SprintPressCounter[playerid]++;

// Happened too many times
if(SprintPressCounter[playerid] == EXCESSIVE_PRESS_COUNT)
{
// Write whatever you want the script to do here

}
}
// Make sure we keep the counter reset
else SprintPressCounter[playerid] = 0;

// Keep track of the last time sprint was pressed
LastPressTime[playerid] = GetTickCount();
}
return 1;
}