02.10.2015, 12:01
This isn't something you would want to use a timer for anyways.
Make a variable that holds the last time the player executed. Example:
When the dropcar command is executed, do this:
Before the command is executed you can do this to prevent use within 20 minutes:
That's it! No timers needed!
Here is the full command:
ALSO: You should really switch to a command processor, using OnPlayerCommandText is stupid for plenty of reasons. I removed IsPlayerConnected in the command because that is useless, a player would have to be connected to execute a command. If you don't want it removed for some weird, stupid reason you should put it at the top of OnPlayerCommandText. You should ditch OnPlayerCommandText completely anyways like I said before. Use the best of what you got, command processors such as ZCMD, YCMD, iZCMD. OnPlayerCommandText is by far the worst option.
Make a variable that holds the last time the player executed. Example:
pawn Код:
PlayerInfo[playerid][pLastDropTime]
pawn Код:
PlayerInfo[playerid][pLastDropTime] = gettime();
pawn Код:
if((PlayerInfo[playerid][pLastDropTime] + (20 * 60 * 1000)) < gettime())
{
// rest of command here
}
Here is the full command:
pawn Код:
if(strcmp(cmd, "/dropcar", true) == 0)
{
if((PlayerInfo[playerid][pLastDropTime] + (20 * 60 * 1000)) < gettime())
{
//if(PlayerInfo[playerid][pJob] == 5)
//{
if(PlayerOnMission[playerid] > 0)
{
SendClientMessage(playerid, COLOR_GREY, " On a mission right now, can't use this command !");
return 1;
}
if((GetPlayerState(playerid)) == 3){//checks if passenger
SendClientMessage(playerid, COLOR_GREY, " Hey, this isn't your vehicle!"); // sends error
return 1;
}
GameTextForPlayer(playerid, "~w~Car Selling ~n~~r~Drop the car at the Crane", 5000, 1);
CP[playerid] = 1;
SetPlayerCheckpoint(playerid, 2506.9529,-2629.9968,13.6465,8.0);
PlayerInfo[playerid][pLastDropTime] = gettime();
//}
//else
//{
// SendClientMessage(playerid, COLOR_GREY, " You are not a Car Jacker !");
//}
}
else
{
format(string, sizeof(string), "You already sold a car, you'll have to wait %d minutes before you can sell another.", SecondsToMinutes(PlayerInfo[playerid][pLastDropTime]));
SendClientMessage(playerid, COLOR_GREY, string);
return 1;
}
return 1;
}