25.05.2015, 09:33
Pretty simple using a timer whenever the player presses the JUMP key.
NOTE, the timer interval must be set accordingly. I prefer a 2 seconds timer but each jump differs.
Those extra checks done in the callbacks are there so that no player updating is affected by the timer.
NOTE, the timer interval must be set accordingly. I prefer a 2 seconds timer but each jump differs.
pawn Код:
new nohptimer[MAX_PLAYERS] = -1;
public OnPlayerConnect(playerid)
{
nohptimer[playerid] = -1;
return 1;
}
forward OnPlayerReachGround(playerid, Float:health);
public OnPlayerReachGround(playerid, Float:health)
{
nohptimer[playerid] = -1;
SetPlayerHealth(playerid, health);
return 1;
}
//just to make sure player updating and taking damage is not effected by the timer
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
if(nohptimer[playerid] != -1) KillTimer(nohptimer[playerid]);
nohptimer[playerid] = -1;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(nohptimer[playerid] != -1) KillTimer(nohptimer[playerid]);
nohptimer[playerid] = -1;
return 1;
}
public OnPlayerSpawn(playerid)
{
if(nohptimer[playerid] != -1) KillTimer(nohptimer[playerid]);
nohptimer[playerid] = -1;
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
if(nohptimer[playerid] != -1) KillTimer(nohptimer[playerid]);
nohptimer[playerid] = -1;
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_JUMP)
{
new Float:health;
GetPlayerHealth(playerid, health);
if(nohptimer[playerid] != -1) KillTimer(nohptimer[playerid]);
nohptimer[playerid] = SetTimerEx("OnPlayerReachGround", 2 * 1000, false, "if", playerid, health);
}
return 1;
}