SA-MP Forums Archive
How to make a delay between actions? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to make a delay between actions? (/showthread.php?tid=479631)



How to make a delay between actions? - Voxel - 06.12.2013

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.


Re: How to make a delay between actions? - David (Sabljak) - 06.12.2013

Код:
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;
        }
    }



Re: How to make a delay between actions? - Voxel - 06.12.2013

Thank you i will test it!


Re: How to make a delay between actions? - iZN - 06.12.2013

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);
    }
}



Re: How to make a delay between actions? - Riddick94 - 06.12.2013

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.