Car Repair - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Car Repair (
/showthread.php?tid=285963)
Car Repair -
trapstar2020 - 26.09.2011
Код:
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
Re: Car Repair -
iJumbo - 26.09.2011
RepairVehicle(yourcustomcarid[i])
and a loop check all your custom cars...
i think you can make a timer and not player update
Re: Car Repair -
trapstar2020 - 27.09.2011
look check





so if i make
Код:
tcar1 = createcar x, y, z, rot, dt all i have 2
RepairVehicle(yourcustomcarid[tcar1])
or
RepairVehicle(tcar1[i])
Re: Car Repair -
aRoach - 27.09.2011
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 ] );
}
Re: Car Repair -
Ensconce - 27.09.2011
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.
Re: Car Repair -
aRoach - 27.09.2011
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 );
}
Re: Car Repair -
Dragony92 - 27.09.2011
@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;
}
Re: Car Repair -
Farsek - 27.09.2011
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;
}
Re: Car Repair -
aRoach - 27.09.2011
SHIT !

)
Re: Car Repair -
Dragony92 - 27.09.2011
@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....