On top:
[pawn]new autofix[101];
new vehid[101];[/pawn]
On OnGameModeInit:
[pawn]public OnGameModeInit(){
SetTimer("autofixtimer", 500, 1);//this is the line you need to add
}[/pawn]
On OnPlayerText:
public OnPlayerText(playerid, cmdtext[])
{
if(strfind(cmdtext, "!", true) == 0) OnPlayerCommand(playerid, cmdtext[1]);//this is to prevent confusion between different scripts.
}
Add public OnPlayerCommand:
public OnPlayerCommand(playerid, command[])
{
new idx, cmd[243];
new tmp[243], tmp2[243];//we put array to be able to use strcmp on it
cmd = strtok(command, idx);
tmp = strtok(command, idx);//we use this here so we dont always need to define tmp
tmp2 = strtok(command, idx);
if(strcmp(command, "autofix", true) == 0){
if(autofix[playerid] == 0)
{
autofix[playerid] = 1;
SendClientMessage(playerid, 0x0FFDD349, "Autofix set to: [ON]");
}
if(autofix[playerid] == 1)
{
autofix[playerid] = 0;
SendClientMessage(playerid, 0x0FFDD349, "Autofix set to: [OFF]");
}
}
}
Add public autofixtimer
[pawn]public autofixtimer()
{
for(new mpl; mpl <= 100; mpl++) if(IsPlayerConnected(mpl) && autofix[mpl] == 1 && vehid[mpl] != 700){
SetVehicleHealth(vehid[mpl], 1000);
//printf("Auto-fixed player vehicle: [%d]", mpl);//uncomment if you want to be notified on every autofix
}
}[/pawn]
On OnPlayerEnterVehicle:
[pawn]public OnPlayerEnterVehicle(playerid, vehicleid)//yours may have parameter ispassenger
{
vehid[playerid] = vehicleid;
}[/pawn]
On OnPlayerExitVehicle:
[pawn]public OnPlayerExitVehicle(playerid)//yours may have additional parameters
{
vehid[playerid] = 700;
}[/pawn]
If you find any bugs, report them now!
Also, dont forget to rate!
NOTE: To add more commands to OnPlayerCommand, DO NOT use ! before text for example you use !say it will be activated when player types !!say and not !say.