please help me with jump
#3

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.

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;
}
Those extra checks done in the callbacks are there so that no player updating is affected by the timer.
Reply


Messages In This Thread
please help me with jump - by Barnwell - 24.05.2015, 16:59
Re : please help me with jump - by KillerDVX - 24.05.2015, 20:22
Re: please help me with jump - by Gammix - 25.05.2015, 09:33

Forum Jump:


Users browsing this thread: 1 Guest(s)