Making exceptions for autorepair
#3

Quote:
Originally Posted by Weirdosport
(plus you can make sure the player is the driver rather than the passenger)
OnPlayerEnterVehicle dedects in which seats the player enters...

@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;
}
That code is better because the timer isnt the whole time active like in your code
Reply


Messages In This Thread
Making exceptions for autorepair - by dice7 - 12.05.2009, 12:02
Re: Making exceptions for autorepair - by Weirdosport - 12.05.2009, 12:11
Re: Making exceptions for autorepair - by Nero_3D - 12.05.2009, 12:17
Re: Making exceptions for autorepair - by Weirdosport - 12.05.2009, 12:20
Re: Making exceptions for autorepair - by Nero_3D - 12.05.2009, 12:23

Forum Jump:


Users browsing this thread: 1 Guest(s)