SA-MP Forums Archive
How do I make this cmd only work once every 20 minutes? - 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)
+--- Thread: How do I make this cmd only work once every 20 minutes? (/showthread.php?tid=662221)



How do I make this cmd only work once every 20 minutes? - aKnoxx - 26.12.2018

PHP код:
CMD:repaircar(playeridparams[])
{
    new 
vehid GetPlayerVehicleID(playerid); 
    
        
RepairVehicle(vehid);
        
GivePlayerMoney(playerid, -850);
        
    return 
1;




Re: How do I make this cmd only work once every 20 minutes? - iorp - 26.12.2018

use gettime to check the time passed like

Quote:

CMD:repaircar(playerid, params[])
{
if(gettime() - GetPVarInt(playerid,"last_time_repaircar") < 20*60*1000) return 0;
SetPVarInt(playerid,"last_time_repaircar",gettime( ));
new vehid = GetPlayerVehicleID(playerid);

RepairVehicle(vehid);
GivePlayerMoney(playerid, -850);

return 1;
}



Re: How do I make this cmd only work once every 20 minutes? - Logic_ - 26.12.2018

Quote:
Originally Posted by iorp
Посмотреть сообщение
use gettime to check the time passed like
Oh please! Don't promote P-Vars, use normal variables. And it's better to use an array with your set of enumeration.


Re: How do I make this cmd only work once every 20 minutes? - DaryltheCoder - 26.12.2018

I can't help with much but, I recreated the command that " iorp " created.


Код:
CMD:repaircar(playerid, params[]) 
{ 
if(gettime() - GetPVarInt(playerid,"last_time_repaircar") < 200000) return SendClientMessage(playerid, 0xAA3333AA, "[SERVER]: You can use this command only one time every 20 minutes!");
SetPVarInt(playerid,"last_time_repaircar",gettime( ));
if(GetPlayerMoney(playerid) < 850) return SendClientMessage(playerid, 0xAA3333AA, "[SERVER]: You don't have enough money to repair your car!");
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAA3333AA, "[SERVER]: You must be in vehicle to use this command!");

RepairVehicle(playerid); // No need to add ' new vehid '.
GivePlayerMoney(playerid, -850); 

return 1; 
}