/fix command with 60 seconds
#1

hey guys
so I want to make a command ...(/fix). that I can use every 60 seconds.so in this command Clearly I will have to use timers for playerid. so I tried to do the next thing :

up on the GM
Код:
new canRep[MAX_PLAYERS];
forward FreeRepair(playerid);
if canRep is 0 then he can repair.if its 1 then he cant.(has to wait 60 secs)

now,OnPlayerConnect
Код:
canRap[playerid] = 0;
then under onplayercommandtext
Код:
	if (strcmp("/fix",cmdtext,true,10) == 0) //ElkaBlazer
	{
	    for(new i = 0;i < MAX_PLAYERS;i++)
		{
		    if(canRep[playerid] == 0)
		    {
		        if(IsPlayerInAnyVehicle(playerid))
				{
				SetVehicleHealth(GetPlayerVehicleID(playerid),100.000);
				SendClientMessage(playerid,COLOR_ADMINS,"You have fixed the vehicle!");
                canRep[playerid] = 1;
                SetTimerEx("FreeRepair",60000,0,"i");
				}
		    }
		}
	    return 1;
	}
and i have the public
Код:
public FreeRepair(playerid)
{
	canRep[playerid] = 0;
}
Reply
#2

Код:
SetTimerEx("FreeRepair", 60000, false, "i", playerid);
And remove the loop.
Reply
#3

Okey.thanks.
can you explain me what you did ?
Reply
#4

Quote:
Originally Posted by bijoyekuza
Посмотреть сообщение
Okey.thanks.
can you explain me what you did ?
You forgot the ''playerid'' param at the end of SetTimerEx.
And there's no need to make a loop for this.
Reply
#5

There's no need to even use a timer for this! Why not just use GetTickCount();?

For example:

pawn Код:
new intLastTick[MAX_PLAYERS] = 0;
pawn Код:
if (strcmp("/fix",cmdtext,true) == 0)
{
    if((GetTickCount() - intLastTick[playerid]) > 60000)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            SetVehicleHealth(GetPlayerVehicleID(playerid),100.000);
            SendClientMessage(playerid,COLOR_ADMINS,"You have fixed the vehicle!");
            intLastTick[playerid] = GetTickCount();
        }
    }
    return 1;
}
No timers and the code is much cleaner!

P.S: Fix your indentation!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)