How put timer in command
#1

Yo. I try put timer into my command bat i get bugged when i type that command its all time says "You must wait 2minutes, bat i killed timer and the end" and same shit all time. When i try different put timer, then its work bat then my timer doesn't work so can you guys help me with this?
Код:
CMD:fr( playerid, params[] )
{
	new rand = random( 10 );
	new id,Float:x,Float:y,Float:z;
	
	switch( rand )
	{
		case 1: // if rand is between 0 and 2 then run the code here
		{
			GivePlayerWeapon(playerid, 31, 9999);
			SendClientMessage(playerid,-1,""chat""COL_RED" You got ultimate M4 weapon ammo!");
		}

		case 2: // if rand is between 3 and 5 then run the code here
		{
			SetPlayerSkin(playerid, 123);
			SendClientMessage(playerid,-1,""chat""COL_RED" You're Thug now!");
		}

		case 3: // if rand is between 6 and 8 then run the code here
		{
			SetPlayerHealth(playerid, 10);
			SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
		}

		case 4: // if rand is between 9 and 11 then run the code here
		{
            GetPlayerPos(id,x,y,z);
            SetPlayerPos(id,x,y,z+10);
            SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
		}
		case 5: // if rand is between 9 and 11 then run the code here
		{
            SetPlayerScore(playerid, GetPlayerScore(playerid) + 100);
            SendClientMessage(playerid,-1,""chat""COL_RED" You got some EXP!");
		}
		case 6: // if rand is between 9 and 11 then run the code here
		{
            SetPlayerColor(playerid,0xCC0000);
            SendClientMessage(playerid,-1,""chat""COL_RED" You're unique now!");
		}
		case 7:
		{
            SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
		}
		case 8:
		{
            SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
		}
		case 9: // if rand is between 6 and 8 then run the code here
		{
	    SetPlayerArmour(playerid, 95);
		SendClientMessage(playerid,-1,""chat""COL_RED" You got Armor");
		}
	}
	return 1;
}
Now i deleted me timer and give it without.
Reply
#2

I didn't understand clearly what you wanted but let me try to add you the timer.
PHP код:
new CanTypeFR true;
CMD:frplayeridparams[] )
{
    new 
rand random10 );
    new 
id,Float:x,Float:y,Float:z;
    if(
CanTypeFR)
    {
        
SetTimer("FRCommand"120000false);
                
CanTypeFR false//Don't forget to add this!
        
switch( rand )
        {
            case 
1// if rand is between 0 and 2 then run the code here
            
{
                
GivePlayerWeapon(playerid319999);
                
SendClientMessage(playerid,-1,""chat""COL_RED" You got ultimate M4 weapon ammo!");
            }
            case 
2// if rand is between 3 and 5 then run the code here
            
{
                
SetPlayerSkin(playerid123);
                
SendClientMessage(playerid,-1,""chat""COL_RED" You're Thug now!");
            }
            case 
3// if rand is between 6 and 8 then run the code here
            
{
                
SetPlayerHealth(playerid10);
                
SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
            }
            case 
4// if rand is between 9 and 11 then run the code here
            
{
                
GetPlayerPos(id,x,y,z);
                
SetPlayerPos(id,x,y,z+10);
                
SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
            }
            case 
5// if rand is between 9 and 11 then run the code here
            
{
                
SetPlayerScore(playeridGetPlayerScore(playerid) + 100);
                
SendClientMessage(playerid,-1,""chat""COL_RED" You got some EXP!");
            }
            case 
6// if rand is between 9 and 11 then run the code here
            
{
                
SetPlayerColor(playerid,0xCC0000);
                
SendClientMessage(playerid,-1,""chat""COL_RED" You're unique now!");
            }
            case 
7:
            {
                
SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
            }
            case 
8:
            {
                
SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
            }
            case 
9// if rand is between 6 and 8 then run the code here
            
{
            
SetPlayerArmour(playerid95);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got Armor");
            }
        }
    }
    else
    {
        
SendClientMessage(playerid,-1,""chat""COL_RED" Wait 2 minutes before doing that!");
    }
    return 
1;
}
forward FRCommand();
public 
FRCommand()
{
    
CanTypeFR true;

Reply
#3

You don't need a timer there.

PHP код:
new commandTime;
CMD:frplayeridparams[] )
{
    if (
gettime() - commandTime 120) return SendClientMessage(playerid, -1"Wait 2 minutes before you use this command again.")
    new 
rand random10 );
    new 
id,Float:x,Float:y,Float:z;
    
    
commandTime gettime();
    switch( 
rand )
    {
        case 
1// if rand is between 0 and 2 then run the code here
        
{
            
GivePlayerWeapon(playerid319999);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got ultimate M4 weapon ammo!");
        }
        case 
2// if rand is between 3 and 5 then run the code here
        
{
            
SetPlayerSkin(playerid123);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You're Thug now!");
        }
        case 
3// if rand is between 6 and 8 then run the code here
        
{
            
SetPlayerHealth(playerid10);
            
SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
        }
        case 
4// if rand is between 9 and 11 then run the code here
        
{
            
GetPlayerPos(id,x,y,z);
            
SetPlayerPos(id,x,y,z+10);
            
SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
        }
        case 
5// if rand is between 9 and 11 then run the code here
        
{
            
SetPlayerScore(playeridGetPlayerScore(playerid) + 100);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got some EXP!");
        }
        case 
6// if rand is between 9 and 11 then run the code here
        
{
            
SetPlayerColor(playerid,0xCC0000);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You're unique now!");
        }
        case 
7:
        {
            
SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
        }
        case 
8:
        {
            
SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
        }
        case 
9// if rand is between 6 and 8 then run the code here
        
{
            
SetPlayerArmour(playerid95);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got Armor");
        }
    }
    return 
1;

Reply
#4

Quote:
Originally Posted by Skimmer
Посмотреть сообщение
You don't need a timer there.

PHP код:
new commandTime;
CMD:frplayeridparams[] )
{
    if (
gettime() - commandTime 120) return SendClientMessage(playerid, -1"Wait 2 minutes before you use this command again.")
    new 
rand random10 );
    new 
id,Float:x,Float:y,Float:z;
    
    
commandTime gettime();
    switch( 
rand )
    {
        case 
1// if rand is between 0 and 2 then run the code here
        
{
            
GivePlayerWeapon(playerid319999);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got ultimate M4 weapon ammo!");
        }
        case 
2// if rand is between 3 and 5 then run the code here
        
{
            
SetPlayerSkin(playerid123);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You're Thug now!");
        }
        case 
3// if rand is between 6 and 8 then run the code here
        
{
            
SetPlayerHealth(playerid10);
            
SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
        }
        case 
4// if rand is between 9 and 11 then run the code here
        
{
            
GetPlayerPos(id,x,y,z);
            
SetPlayerPos(id,x,y,z+10);
            
SendClientMessage(playerid,-1,""chat""COL_RED" UPS!");
        }
        case 
5// if rand is between 9 and 11 then run the code here
        
{
            
SetPlayerScore(playeridGetPlayerScore(playerid) + 100);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got some EXP!");
        }
        case 
6// if rand is between 9 and 11 then run the code here
        
{
            
SetPlayerColor(playerid,0xCC0000);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You're unique now!");
        }
        case 
7:
        {
            
SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
        }
        case 
8:
        {
            
SendClientMessage(playerid,-1,""chat""COL_RED" Nothing happened!");
        }
        case 
9// if rand is between 6 and 8 then run the code here
        
{
            
SetPlayerArmour(playerid95);
            
SendClientMessage(playerid,-1,""chat""COL_RED" You got Armor");
        }
    }
    return 
1;

Yup, it's work fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)