cmd timer
#1

How to make a timer when I use CMD the cmd wait few seconds and after that preform the action?

Like steal timer...

+Rep helper
Reply
#2

You have to learn about timers. Consider the wiki.
PHP код:
CMD:cmdname(playeridparams[])
{
    
SetTimerEx("CommandTimer"Time0"i"playerid); //Run a timer. When the command executes
    
return 1;
}
forward CommandTimer(playerid);
public 
CommandTimer(playerid)
{
   
//The things you want to do.

Reply
#3

Here is a mini tutorial: (You can still copy paste but I suggest you to understand it)
PHP код:
//On top of your script
new StealTimer[MAX_PLAYERS]; //Declaring a variable to store the player timers in
new StealCount[MAX_PLAYERS]; //Declaring a variable to check where the timer has reached (counting)
CMD:steal(playerid//A command using ZCMD include
{
    
StealTimer[playerid] = SetTimerEx("StealFromPlayer"1000true"i"playerid); //Here we assigned the variable StealTimer to a player timer which repeats every one second
    
StealCount[playerid] = 5//CHANGE THIS > Assign the time in seconds to do the action after (countdown variable)
    
new counttext[25]; //The following 3 lines just to print to the player a message on where the count has reached
    
format(counttextsizeof(counttext), "~r~~h~%i Seconds Remaining"StealCount);
    
GameTextForPlayer(playeridcounttext10004);
    return 
1;
}
forward StealFromPlayer(playerid); //Forwarded the function of the timer
public StealFromPlayer(playerid)
{
    
StealCount[playerid]--; //We decrese the counter every one second by one
    
if(StealCount[playerid] == 0//This is if 5 seconds passed to the count (reached 0)
    
{
        
KillTimer(StealTimer[playerid]); //Don't forget to kill the timer so it doesn't stay on after you have done your things
        
GameTextForPlayer(playerid"~g~~h~Done"10004);
        
//Robbed from player (YOUR CODES)
    
}
    else 
//If the count didn't reach 0 yet. print him the remaining time
    
{
        new 
counttext[25];
        
format(counttextsizeof(counttext), "~r~~h~%i Seconds Remaining"StealCount);
        
GameTextForPlayer(playeridcounttext10004);
    }
    return 
1;

Reply
#4

Quote:
Originally Posted by FailerZ
Посмотреть сообщение
Here is a mini tutorial: (You can still copy paste but I suggest you to understand it)
PHP код:
//On top of your script
new StealTimer[MAX_PLAYERS]; //Declaring a variable to store the player timers in
new StealCount[MAX_PLAYERS]; //Declaring a variable to check where the timer has reached (counting)
CMD:steal(playerid//A command using ZCMD include
{
    
StealTimer[playerid] = SetTimerEx("StealFromPlayer"1000true"i"playerid); //Here we assigned the variable StealTimer to a player timer which repeats every one second
    
StealCount[playerid] = 5//CHANGE THIS > Assign the time in seconds to do the action after (countdown variable)
    
new counttext[25]; //The following 3 lines just to print to the player a message on where the count has reached
    
format(counttextsizeof(counttext), "~r~~h~%i Seconds Remaining"StealCount);
    
GameTextForPlayer(playeridcounttext10004);
    return 
1;
}
forward StealFromPlayer(playerid); //Forwarded the function of the timer
public StealFromPlayer(playerid)
{
    
StealCount[playerid]--; //We decrese the counter every one second by one
    
if(StealCount[playerid] == 0//This is if 5 seconds passed to the count (reached 0)
    
{
        
KillTimer(StealTimer[playerid]); //Don't forget to kill the timer so it doesn't stay on after you have done your things
        
GameTextForPlayer(playerid"~g~~h~Done"10004);
        
//Robbed from player (YOUR CODES)
    
}
    else 
//If the count didn't reach 0 yet. print him the remaining time
    
{
        new 
counttext[25];
        
format(counttextsizeof(counttext), "~r~~h~%i Seconds Remaining"StealCount);
        
GameTextForPlayer(playeridcounttext10004);
    }
    return 
1;

And how to do if player move the cmd didn't perform?
Reply
#5

Quote:
Originally Posted by CheckItOut
Посмотреть сообщение
And how to do if player move the cmd didn't perform?
Add/Replace to the following
PHP код:
CMD:steal(playerid)
{
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz); //Get the player position when he starts to rob
    
StealTimer[playerid] = SetTimerEx("StealFromPlayer"1000true"ifff"playeridxyz); //Passed the float of the coordinations
    
return 1;
}
forward StealFromPlayer(playeridFloat:xFloat:yFloat:z); //Notice you have to forward them and add Float: tag before them
public StealFromPlayer(playeridFloat:xFloat:yFloat:z//Here too
{
    if(!
IsPlayerInRangeOfPoint(playerid1.0xyz)) //Here we check every after every second passed if the player in the range of his old position. decrese the range (1.0) to lesser number if you don't want him to move at all
    
{
        
KillTimer(StealTimer[playerid]); //As always kill the timer
        
GameTextForPlayer(playerid"~r~~h~Failed to rob"10004);
        return 
1//we return 1 so it doesn't continue the codes below
    
}

Reply
#6

Quote:
Originally Posted by FailerZ
Посмотреть сообщение
Add/Replace to the following
PHP код:
CMD:steal(playerid)
{
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz); //Get the player position when he starts to rob
    
StealTimer[playerid] = SetTimerEx("StealFromPlayer"1000true"ifff"playeridxyz); //Passed the float of the coordinations
    
return 1;
}
forward StealFromPlayer(playeridFloat:xFloat:yFloat:z); //Notice you have to forward them and add Float: tag before them
public StealFromPlayer(playeridFloat:xFloat:yFloat:z//Here too
{
    if(!
IsPlayerInRangeOfPoint(playerid1.0xyz)) //Here we check every after every second passed if the player in the range of his old position. decrese the range (1.0) to lesser number if you don't want him to move at all
    
{
        
KillTimer(StealTimer[playerid]); //As always kill the timer
        
GameTextForPlayer(playerid"~r~~h~Failed to rob"10004);
        return 
1//we return 1 so it doesn't continue the codes below
    
}

When I steal it's give me the staff and after start the timer... what to do? and thanks!
Reply
#7

Quote:
Originally Posted by CheckItOut
Посмотреть сообщение
When I steal it's give me the staff and after start the timer... what to do? and thanks!
Where did you post your giving stuff?

You should post them right under here:
Код:
    if(StealCount[playerid] == 0)
    {  
        //Robbed from player (YOUR CODES) 
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)