Keys State Help -
Istrator - 29.04.2018
Hi!
How to detect a player when he/she used "KEY_JUMP" for 3 times? and apply an animation for it?
Thank you for your response!
Re: Keys State Help -
RedRex - 29.04.2018
https://sampwiki.blast.hk/wiki/GetPlayerKeys
Re: Keys State Help -
Loinal - 29.04.2018
PHP код:
new Used[MAX_PLAYERS];
if(PRESSED(KEY_JUMP))
{
Used[playerid] += 1;
if(Used[playerid] >= 3)
{
new string[100];
format(string, sizeof(string), "*** %s (ID:%d) has used the JUMP KEY more than 3 times", GetName(playerid), playerid);
SendClientMessageToAll(-1, string);
}
}
You should have the stock GetName
Код:
stock GetName(playerid)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid,Name,MAX_PLAYER_NAME);
return Name;
}
Re: Keys State Help -
Pottus - 29.04.2018
Quote:
Originally Posted by Loinal
PHP код:
new Used[MAX_PLAYERS];
if(PRESSED(KEY_JUMP))
{
Used[playerid] += 1;
if(Used[playerid] >= 3)
{
new string[100];
format(string, sizeof(string), "*** %s (ID:%d) has used the JUMP KEY more than 3 times", GetName(playerid), playerid);
SendClientMessageToAll(-1, string);
}
}
You should have the stock GetName
Код:
stock GetName(playerid)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid,Name,MAX_PLAYER_NAME);
return Name;
}
|
How do you expect that work correctly without checking the times between presses? No resetting of the variable either.
The best thing to do would be to create your own system that allows defining custom key combo detection.
Re: Keys State Help -
git - 29.04.2018
Quote:
Originally Posted by Pottus
How do you expect that work correctly without checking the times between presses? No resetting of the variable either.
The best thing to do would be to create your own system that allows defining custom key combo detection.
|
PHP код:
#include <a_samp>
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new timesJump[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(!IsPlayerInAnyVehicle(playerid))
{
new firstjumpTime;
if(PRESSED(KEY_JUMP))
{
timesJump[playerid]++;
if(timesJump[playerid] == 1)
{
firstjumpTime = gettime()+4500;
return 1;
}
if(timesJump[playerid] > 3)
{
timesJump[playerid] = 0;
if(firstjumpTime < gettime())
{
OnPlayerJumpThreeTimes(playerid);
}
}
return 1;
}
}
return 1;
}
forward public OnPlayerJumpThreeTimes(playerid);
public OnPlayerJumpThreeTimes(playerid)
{
SendClientMessage(playerid, -1, "detected jumping 3 times within timespan of 4.5 seconds");
// the code when the player jumps three times
ApplyAnimation(playerid, "GYMNASIUM", "gym_tread_falloff", 4.1, 0, 1, 1, 0, 1500, 1);
timesJump[playerid] = 0;
return 1;
}
here's what i've come up with.
to the op:
it uses timestamps. it gets the current time + 4.5 seconds so for example if the time is 12:50:30 (hh mm ss) it will store 12:50:34 in the variable.
if the player has jumped 3 times while the time is less than 12:50:34 (time span of 4 seconds) it will detect and reset the variable for the jump counter.
(technically timestamp is in seconds so 199999 would be 200003 if 4 seconds were added to it).
this code may be bad practice, but it is an idea of what you want.
i can confirm that my method works.
alternatively, you could use ziggi's
GetTickDiff function and check the interval in ms of each jump, so this way, when people spam the jump key and they do it within below a specific value, you can apply an animation to make them trip or what not.
Re: Keys State Help -
Istrator - 30.04.2018
Quote:
Originally Posted by git
PHP код:
#include <a_samp>
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new timesJump[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(!IsPlayerInAnyVehicle(playerid))
{
new firstjumpTime;
if(PRESSED(KEY_JUMP))
{
timesJump[playerid]++;
if(timesJump[playerid] == 1)
{
firstjumpTime = gettime()+4500;
return 1;
}
if(timesJump[playerid] > 3)
{
timesJump[playerid] = 0;
if(firstjumpTime < gettime())
{
OnPlayerJumpThreeTimes(playerid);
}
}
return 1;
}
}
return 1;
}
forward public OnPlayerJumpThreeTimes(playerid);
public OnPlayerJumpThreeTimes(playerid)
{
SendClientMessage(playerid, -1, "detected jumping 3 times within timespan of 4.5 seconds");
// the code when the player jumps three times
ApplyAnimation(playerid, "GYMNASIUM", "gym_tread_falloff", 4.1, 0, 1, 1, 0, 1500, 1);
timesJump[playerid] = 0;
return 1;
}
|
Thank you for helping although this doesn't work for me. I want something like on sampdm.
Re: Keys State Help -
jasperschellekens - 30.04.2018
Keep in mind that the sniper zoom uses the same key. If you are creating some kind of anti bunnyhop this is a no-no.
Re: Keys State Help -
git - 30.04.2018
Quote:
Originally Posted by Istrator
Thank you for helping although this doesn't work for me. I want something like on sampdm.
|
You've just stated you wanted if a player jumps 3 times, they will get an animation played? What from where I have made for you, doesn't work for you?
I've just researched this sampdm server and my code does exactly what sampdm does.