TESTED AND WORKING
Way 1:
pawn Код:
//OnGameModeInit
SetTimer("Timer", 1000, true);
pawn Код:
new bool:AutoFix[MAX_PLAYERS];
pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
if(AutoFix[playerid])
{
AutoFix[playerid] = false;
return SendClientMessage(playerid, COLOR, "Autofix stopped");
}
else
{
if(!IsPlayerInAnyVehicle(i)) return SendClientMessage(playerid, COLOR, "You need to be in a vehicle to start autofix");
AutoFix[playerid] = true;
return SendClientMessage(playerid, COLOR, "Autofix started");
}
return 1;
}
pawn Код:
forward Timer();
public Timer()
{
new Float:health, var1;
for(new i = 0, m = GetMaxPlayers(); i < m; i++)
{
if(!IsPlayerConnected(i)) continue;
if(AutoFix[i] && IsPlayerInAnyVehicle(i))
{
var1 = GetPlayerVehicleID(i);
GetVehicleHealth(var1 , health);
if(health < 500) SetVehicleHealth(var1, 1000.0);
}
}
}
Way 2:
pawn Код:
new AutoFixTimer[MAX_PLAYERS];
pawn Код:
if(!strcmp("/afix", cmdtext, true))
{
if(AutoFixTimer[playerid])
{
KillTimer(AutoFixTimer[playerid]);
AutoFixTimer[playerid] = false;
return SendClientMessage(playerid, COLOR, "Autofix stoped");
}
else
{
if(!IsPlayerInAnyVehicle(i)) return SendClientMessage(playerid, COLOR, "You need to be in a vehicle to start autofix");
AutoFixTimer[playerid] = SetTimerEx("AutoFix", 1000, true, "i", playerid);
return SendClientMessage(playerid, COLOR, "Autofix started");
}
return 1;
}
pawn Код:
forward AutoFix(playerid);
public AutoFix(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vid = GetPlayerVehicleID(playerid), Float:health;
GetVehicleHealth(vid , health);
if(health < 500) SetVehicleHealth(vid , 1000.0);
}
}