12.05.2009, 12:17
Quote:
Originally Posted by Weirdosport
(plus you can make sure the player is the driver rather than the passenger)
|
@topic
first of all, use [pawn][/pawn] tags
pawn Code:
new AutoRepairTimer[MAX_PLAYERS] = {-1, ...};
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
switch(GetVehicleModel(GetPlayerVehicleID(playerid)))
{
case 425, 447, 476, 520: {} //do nothing
default:
{
if(AutoRepairTimer[playerid] != -1) KillTimer(AutoRepairTimer[playerid]);
AutoRepairTimer[playerid] = SetTimerEx("AutoRepair", 1000, true, "d", playerid);
}
}
}
pawn Code:
forward AutoRepair(playerid);
public AutoRepair(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new
Float:health;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicleid, health);
if(health <= 300.0)
{
SetVehicleHealth(vehicleid, 1000.0);
GameTextForPlayer(playerid, "~g~Car Auto-Repaired!", 5000, 5);
PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
}
}
else KillTimer(AutoRepairTimer[playerid]), //kills the timer if the exist the vehicle or disconnects!
AutoRepairTimer[playerid] = -1;
}