Car Repair
#1

Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new Float:vhealth;
        GetVehicleHealth(GetPlayerVehicleID(playerid),vhealth);
        if(vhealth<999)
        {
            RepairVehicle(GetPlayerVehicleID(playerid));
            SetVehicleHealth(GetPlayerVehicleID(playerid),100);
            GameTextForPlayer(playerid,"~g~Auto ~w~Fix",1500,3);
        }
    }
    return 1;


}
Ok i have this for my code but i wanna it to be for certain cars i created(not vehicle id custom cars i made)
and anyone help me edit this. to do so
Reply
#2

RepairVehicle(yourcustomcarid[i])

and a loop check all your custom cars...
i think you can make a timer and not player update
Reply
#3

look check

so if i make
Код:
tcar1 = createcar x, y, z, rot, dt all i have 2 

RepairVehicle(yourcustomcarid[tcar1])

or

RepairVehicle(tcar1[i])
Reply
#4

You can do this:
pawn Код:
// At the top of your Script
new tCar[ 3 ]; // 3 = Number of Vehicles

// At OnGameModeInit
tCar[ 0 ] = CreateVehicle( ... );
tCar[ 1 ] = CreateVehicle( ... );
tCar[ 2 ] = CreateVehicle( ... );

// At OnPlayerUpdate
for( new VEHS = 0; VEHS <= 3; VEHS ++ )
{
    if( IsPlayerInVehicle( playerid, tCar[ i ] ) ) RepairVehicle( tCar[ i ] );
}
Reply
#5

There's no need to use OnPlayerUpdate for this as it is called 30 - 60 times each second. A better way to do it would be to create a 500 ms timer. Also I would strongly recommend against spamming the "AUTO FIX" game text.
Reply
#6

It's Better 1 s.( 1000 ms. ) :
pawn Код:
// At the top of your Script
new tCar[ 3 ]; // 3 = Number of Vehicles

// At OnGameModeInit
tCar[ 0 ] = CreateVehicle( ... );
tCar[ 1 ] = CreateVehicle( ... );
tCar[ 2 ] = CreateVehicle( ... );

for( new i = 0; i < MAX_PLAYERS; i ++ ) SetTimerEx( "Auto_Repair", 1000, 1, "i", i );

// Down in your Script
forward Auto_Repair( playerid );
public Auto_Repair( playerid )
{
    for( new v = 0; v < 3; v ++ )
    {
        if( IsPlayerInVehicleVehicle ( playerid, tCar[ v ] ) )
        {
            new Float: HP;  GetVehicleHealth( tCar[ v ], HP );
            if( HP < 1000 ) RepairVehicle( tCar[ v ] );
        }
    }
    return ( 1 );
}
Reply
#7

@aRoach Why are you calling Function 500 times in second :/
pawn Код:
// At the top of your Script
new tCar[ 3 ]; // 3 = Number of Vehicles

// At OnGameModeInit
tCar[ 0 ] = CreateVehicle( ... );
tCar[ 1 ] = CreateVehicle( ... );
tCar[ 2 ] = CreateVehicle( ... );

SetTimer("Auto_Repair", 1000, 1);

// Down in your Script
forward Auto_Repair( playerid );
public Auto_Repair( playerid )
{
    foreach(Player,i)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new Float: HP;  GetVehicleHealth( GetPlayerVehicleID( playerid ), HP );
            if( HP < 1000 ) RepairVehicle( GetPlayerVehicleID( playerid ) );
        }
    }
    return 1;
}
Reply
#8

pawn Код:
// At the top of your Script
new tCar[ 3 ]; // 3 = Number of Vehicles

// At OnGameModeInit
tCar[ 0 ] = CreateVehicle( ... );
tCar[ 1 ] = CreateVehicle( ... );
tCar[ 2 ] = CreateVehicle( ... );

SetTimer( "Auto_Repair", 1000, 1 );

// Down in your Script
forward Auto_Repair( );
public Auto_Repair( )
{
    for( new v = 0; v < sizeof tCar; v ++ )
    {
        static Float: HP;  GetVehicleHealth( tCar[ i ], HP );
        if( HP < 999 ) RepairVehicle( tCar[ i ] );
    }
    return 1;
}
Reply
#9

SHIT ! )
Reply
#10

@Farsek LoL? That wouldn't work :/ Undefined symbol i? Symbol v is never used? And your public is not checking that is there somebody in car....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)