How to make a delay between actions?
#1

How would i make a delay between being able to do these actions?
pawn Код:
if(GetPlayerSkin(playerid) == 150)
    {
        if(newkeys & KEY_JUMP)
        {
            new Float:SuperJump[3];
            GetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]);
            SetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]+10);
        }
    }
I did some research on GetTickCount and timers but i'm not understanding how to implement this in my code, i want it so a player can only use the "super jump" every 10 seconds.

Example please? thank you.
Reply
#2

Код:
new UsedJump[MAX_PLAYERS];

if(GetPlayerSkin(playerid) == 150)
    {
        if(newkeys & KEY_JUMP)
        {
if(gettime() < UsedJump[playerid])
	{
		SendClientMessage(playerid,-1,  "You used your jump! Wait 10 seconds!");
		return 1;
	}
            new Float:SuperJump[3];
            GetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]);
            SetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]+10);
UsedJump[playerid] = gettime() + 10;
        }
    }
Reply
#3

Thank you i will test it!
Reply
#4

pawn Код:
/* With GetTickCount */

new pJumpInterval[MAX_PLAYERS];

new Var_ = GetTickCount();
if(GetPlayerSkin(playerid) == 150 && pJumpInterval[playerid] > Var_)
{
    if(newkeys & KEY_JUMP)
    {
        pJumpInterval[playerid] = GetTickCount() + 10000;
        new Float:SuperJump[3];
        GetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]);
        SetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]+10);
    }
}
Reply
#5

Quote:
Originally Posted by iZN
Посмотреть сообщение
pawn Код:
/* With GetTickCount */

new pJumpInterval[MAX_PLAYERS];

new Var_ = GetTickCount();
if(GetPlayerSkin(playerid) == 150 && pJumpInterval[playerid] > Var_)
{
    if(newkeys & KEY_JUMP)
    {
        pJumpInterval[playerid] = GetTickCount() + 10000;
        new Float:SuperJump[3];
        GetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]);
        SetPlayerVelocity(playerid, SuperJump[0], SuperJump[1], SuperJump[2]+10);
    }
}
"Hey! I am falling in the air straight to the ground and I'm gonna die! Actually.. why not press KEY_JUMP when I'm gonna be close enough to the ground to avoid killing myself!"


Solution:
MapAndreas.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)