seconds before executing a cmd
#1

can anyone show me how to make a timer to wait like 5 or 10 seconds before the cmd gets executed?
and if they move the command cancels? some players abuse some commands, and maybe doing this, then they wont go afk while they dm
Reply
#2

use SetTimerEx ,
make a command that triggers a public, and a public that acts as the command.
Reply
#3

i tried several ways and also searched but failed, can you give an example?
Reply
#4

Hm ... try something like:

pawn Код:
CMD:test(playerid, params[])
{
     new Float:X, Float:Y, Float:Z;
     GetPlayerPos(playerid, X, Y, Z);
     SetPVarFloat(playerid, "TempPosX", X);
     SetPVarFloat(playerid, "TempPosY", Y);
     SetPVarFloat(playerid, "TempPosZ", Z);
     SetTimerEx( "Testing", 5000, false, "i", playerid);
     return 1;
}

forward Testing(playerid);
public Testing(playerid)
{
     new Float:zX, Float:zY, Float:zZ;
     GetPlayerPos(playerid, zX, zY, zZ);
     if(zX != GetPVarFloat(playerid, "TempPosX") && zY != GetPVarFloat(playerid, "TempPosY") && zZ != GetPVarFloat(playerid, "TempPosZ"))
             return 0;

     SendClientMessage(playerid, -1, "5 seconds passed since you used /test command.");
     // Other things here
}
Not sure it works though ... but you can try and tell me what`s not working ... if that`s the case.
Reply
#5

create a variable first like
pawn Код:
new myvariable[MAX_PLAYERS];
them when the player uses the cmds put it on the top of the cmds

pawn Код:
if(myvariable[playerid] == 1)
        {
                SendClientMessage(playerid, COLOR_YELLOW2, "my variable on the player cant use the cmd");
                return true; // return true so the player cant use the cmdds
        }
at the send of the cmds createa a timer like this

pawn Код:
SetTimerEx("CanUse", 5000, 0, "d", playerid);

//now create a public function like this one

~forward CanUse(playerid);

public CanUse(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        myvariable[playerid] = 0; // and done after 5 seconds the player can use the cmds again
    }
}
Reply
#6

Antonio, the moving thing works, then it dont send the message and all.

But i directly go into afk, no 5 sec wait
Reply
#7

Alright, let me test it really quick I`ll be back with an edit ...

It works perfectly for me. Let me edit one small thing:
pawn Код:
forward Testing(playerid);
public Testing(playerid)
{
     SendClientMessage(playerid, -1, "Initiating teleport.");
     new Float:zX, Float:zY, Float:zZ;
     GetPlayerPos(playerid, zX, zY, zZ);
     if(zX != GetPVarFloat(playerid, "TempPosX") && zY != GetPVarFloat(playerid, "TempPosY") && zZ != GetPVarFloat(playerid, "TempPosZ"))
             return SendClientMessage(playerid, -1, "You must stay in a place to teleport.");

     SendClientMessage(playerid, -1, "5 seconds passed since you used /test command.");
     SetPlayerPos(playerid, -1948.9344,263.5333,40.7531);
     return 1;
}
Try it like this. If you use /test command and move, it won`t teleport you.

If you stay in the same place, it`ll teleport you.
Reply
#8

I tested that aswell and it works fine
Reply
#9

Thanks alot Antonio, it worked !

Respect
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)