14.08.2012, 18:00
Is there a way to check that player quickly clicks a key running for 'Super-sprint'?
P.S
I'd rather not use a SetTimer/Ex.
P.S
I'd rather not use a SetTimer/Ex.
if(HOLDING(KEY_SPRINT))
{
if(!PlayerInfo[playerid][pSprintEnabled])
{
PlayerInfo[playerid][pSprintEnabled] = true;
KillTimer(PlayerInfo[playerid][pSprintTimer]);
PlayerInfo[playerid][pSprintTimer] = SetTimerEx("CountSprint", SECONDS(1), true, "d", playerid);
}
return true;
}
if(RELEASED(KEY_SPRINT))
{
if(PlayerInfo[playerid][pSprintEnabled])
{
if(PlayerInfo[playerid][pSprintCount] < MAX_SPRINT_DEFAULT_VALUE)
{
KillTimer(PlayerInfo[playerid][pSprintTimer]);
PlayerInfo[playerid][pSprintTimer] = SetTimerEx("CountSprint", SECONDS(1), true, "d", playerid);
}
PlayerInfo[playerid][pSprintEnabled] = false;
}
return true;
}
return true;
}
function CountSprint(playerid)
{
if(PlayerInfo[playerid][pSprintEnabled])
{
PlayerInfo[playerid][pSprintCount] -= 1;
if(PlayerInfo[playerid][pSprintCount] <= 0)
{
PlayerInfo[playerid][pSprintCount] = 0;
PlayerInfo[playerid][pSprintEnabled] = false;
ApplyAnimation(playerid, "FAT", "IDLE_tired", 4.1, 1, 1, 1, 0, 0, 1);
}
}
else if(!PlayerInfo[playerid][pSprintEnabled])
{
PlayerInfo[playerid][pSprintCount] += 1;
if(PlayerInfo[playerid][pSprintCount] >= MAX_SPRINT_DEFAULT_VALUE)
{
ClearAnimations(playerid);
PlayerInfo[playerid][pSprintCount] = MAX_SPRINT_DEFAULT_VALUE;
KillTimer(PlayerInfo[playerid][pSprintTimer]);
}
}
new string[64];
format(string, sizeof(string), "~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~w~Sprint count: %d/%d", PlayerInfo[playerid][pSprintCount], MAX_SPRINT_DEFAULT_VALUE);
GameTextForPlayer(playerid, string, SECONDS(1), 3);
return true;
}