CMD:repaircar(playerid, params[])
{
if(gettime() - GetPVarInt(playerid,"last_time_repaircar") < 5) return SendClientMessage(playerid, 0xAA3333AA, "[INFO]: You can only use this command once every 15 minutes.");
new Float:vehhp;
GetVehicleHealth(GetPlayerVehicleID(playerid), vehhp);
if(!IsPlayerInRangeOfPoint(playerid, 5, 2073.6338, -1831.2242, 13.5469)) return SendClientMessage(playerid, -1, "[INFO]: You are not at of the repair center");
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAA3333AA, "[INFO]: You must be in vehicle to use this command!");
if(vehhp == 1000) return SendClientMessage(playerid, 0xAA3333AA, "[INFO] Your car doesn't need to be repaired.");
if(GetPlayerMoney(playerid) < 850) return SendClientMessage(playerid, 0xAA3333AA, "[INFO]: You don't have enough money to repair your car!");
SetPVarInt(playerid,"last_time_repaircar",gettime( ));
RepairVehicle(GetPlayerVehicleID(playerid));
GivePlayerMoney(playerid, -850);
SendClientMessage(playerid, -1, "You paid $850 to repair your vehicle.");
PlayerPlaySound(playerid, 1133, 0, 0, 0);
return 1;
}
forward OnPlayerRepairTimerZero(playerid);
public OnPlayerRepairTimerZero(playerid)
{
if(gettime() - GetPVarInt(playerid,"last_time_repaircar") < 1) SendClientMessage(playerid, -1, "[INFO]: You can now use the repair center again.");
return 1;
}
|
You have to set a timer that will call the public function OnPlayerRepairTimerZero after the desired time interval.
https://sampwiki.blast.hk/wiki/SetTimerEx |
|
Just as Georgia said you need to set a player timer, which does everything exactly like SetTimer but you use it for player functions.
|
|
So then how do I get the timer value after that?
For example after /repaircar ---> it sets a timer for 10mins How do I get the timer value so that if someone types /repaircar while the timer is still on, they get a msg saying, "You cant use this cmd now"? Do I just... new timer = SetTimer(blah blah); ?? |
//global array or just add as an enum constant if you already have one
new bool:CarRepairLock[MAX_PLAYER];
//....
CMD:repaircar(playerid, params[]){
if(CarRepairLock[playerid]){
//send error message
return 1;
}
//rest of the cmd......
//settimer
CarRepairLock[playerid] = true;
return 1;
}
forward OnPlayerRepairTimerZero(playerid);
public OnPlayerRepairTimerZero(playerid){
SendClientMessage(playerid, -1, "[INFO]: You can now use the repair center again.");
//no more restriction..
CarRepairLock[playerid] = false;
return 1;
}