How do I make this cmd only work once every 20 minutes?
#1

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

Reply
#2

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;
}
Reply
#3

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.
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)