SA-MP Forums Archive
/fix command with 60 seconds - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: /fix command with 60 seconds (/showthread.php?tid=241682)



/fix command with 60 seconds - bijoyekuza - 18.03.2011

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



Re: /fix command with 60 seconds - WackoX - 18.03.2011

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


Re: /fix command with 60 seconds - bijoyekuza - 18.03.2011

Okey.thanks.
can you explain me what you did ?


Re: /fix command with 60 seconds - WackoX - 18.03.2011

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.


Re: /fix command with 60 seconds - JaTochNietDan - 18.03.2011

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!