Repair command [help] -
Diabloa - 11.05.2016
Код:
CMD:repair(playerid, params[])
{
new string[128], veh;
if(!IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playerid, COLOR_GREY, "You are not allowed to use command.");
if(PlayerInfo[playerid][pJob] != JOB_MECHANIC && PlayerInfo[playerid][pVIPJob] != JOB_MECHANIC && !IsATower(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not mechanic.");
if(sscanf(params, "i", veh)) return SendClientMessage(playerid, COLOR_WHITE, "How to use: /repair [IDof the car /dl]");
new Float:vH; GetVehicleHealth(GetPlayerVehicleID(playerid), vH);
new Float:vel[3]; GetVehicleVelocity(GetPlayerVehicleID(playerid), vel[0], vel[1], vel[2]);
if(vH < 250) return SendClientMessage(playerid, COLOR_GREY, "the car's engine is too hot to repair it.");
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You have to be on the driving seat to repair the car.");
if(vel[0] != 0 || vel[1] != 0 || vel[2] != 0) return SendClientMessage(playerid, COLOR_GREY, "You can't repair while moving");
RepairVehicle(GetPlayerVehicleID(playerid));
PlayerInfo[playerid][pJobSkill][JOB_MECHANIC] ++;
PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
format(string, sizeof(string), "* %s fixes the car's engine.", RPN(playerid));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
return 1;
}
Basically you can use this command without delay like whenever you want, I want there to be delay by every use like 1 minute.
Re: Repair command [help] -
Sew_Sumi - 11.05.2016
Near top of script put
PHP код:
new repaircooldown[MAX_PLAYERS];
in the command before the new velocity variables and the check for velocity
PHP код:
if(repaircooldown[playerid] > 0) return SendClientMessage(playerid, COLOR_GREY, "You can't repair yet");
new Float:vH;......
You'll need a timer at 1000 ms with a foreach to go through each player, and do
PHP код:
if(repaircooldown[i] > 0) repaircooldown[i]--
At the bottom of your repair command, you want to have
PHP код:
repaircooldown[playerid] = 60;
Re: Repair command [help] -
jlalt - 11.05.2016
This should do the job:
PHP код:
new pTimeREPAIR[MAX_PLAYERS]; // on top
CMD:repair(playerid, params[])
{
if((pTimeREPAIR[playerid]-gettime()) > 0) {
new string[85];
format(string,sizeof string,"Wait %d Seconds before using this command again!",pTimeREPAIR[playerid]-gettime());
SendClientMessage(playerid, -1, string);
return 1;
}
new string[128], veh;
if(!IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playerid, COLOR_GREY, "You are not allowed to use command.");
if(PlayerInfo[playerid][pJob] != JOB_MECHANIC && PlayerInfo[playerid][pVIPJob] != JOB_MECHANIC && !IsATower(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not mechanic.");
if(sscanf(params, "i", veh)) return SendClientMessage(playerid, COLOR_WHITE, "How to use: /repair [IDof the car /dl]");
new Float:vH; GetVehicleHealth(GetPlayerVehicleID(playerid), vH);
new Float:vel[3]; GetVehicleVelocity(GetPlayerVehicleID(playerid), vel[0], vel[1], vel[2]);
if(vH < 250) return SendClientMessage(playerid, COLOR_GREY, "the car's engine is too hot to repair it.");
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You have to be on the driving seat to repair the car.");
if(vel[0] != 0 || vel[1] != 0 || vel[2] != 0) return SendClientMessage(playerid, COLOR_GREY, "You can't repair while moving");
RepairVehicle(GetPlayerVehicleID(playerid));
PlayerInfo[playerid][pJobSkill][JOB_MECHANIC] ++;
PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
format(string, sizeof(string), "* %s fixes the car's engine.", RPN(playerid));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
pTimeREPAIR[playerid] = gettime()+60;
return 1;
}
What is gettime()?
Re: Repair command [help] -
Sew_Sumi - 11.05.2016
It's a lot simpler to use a tick timer...
Re: Repair command [help] -
Dayrion - 11.05.2016
Set a timer with a variable ? Like :
PHP код:
/* At the top of the script */
new Bool:allowedRepair[MAX_PLAYERS];
//------------------------------------------------------------------------------------------------
/* In your command */
if(!allowedRepair[playerid]) return SendClientMessage(playerid, X11_MEDIUM_ORCHID_3, "You can't repair this vehicle. You have to wait 1 minute!");
/* If the player can repair the vehicle, set this after RepairVehicle(vehicleid) */
allowedRepair[playerid] = false;
SetTimerEx("timerAllowedRepair", 60000, false, "i", playerid);
/* End of the command */
//------------------------------------------------------------------------------------------------
/* Timer allowed repair a vehicle : */
forward timerAllowedRepair(playerid);
public timerAllowedRepair(playerid)
{
allowedRepair[playerid] = true;
SendClientMessage(playerid, X11_MEDIUM_ORCHID_3, "You can repair vehicles");
return 1;
}
If you need some explications, say it. I don't think it's the best way to do what you want. :$
EDIT : Alright, they too fast for me. Wow.