SA-MP Forums Archive
==>Auto Fix Problem<== - 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: ==>Auto Fix Problem<== (/showthread.php?tid=403251)



==>Auto Fix Problem<== - ThePrograme - 29.12.2012

Ok I have a small problem with my script. When i drive and hit stuff with vehicles the auto fix works pefectly but when my vehicle (car) is upside down and starts bunring it doesn't fix it so i blow up. If there is a way to do this i will be grateful.
HERE IS THE SCRIPT:
pawn Код:
//=====INCLUDES=====//
#include <a_samp>
//===================DEFINES====================//
#define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))

#define RELEASED(%0) \
    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
//====================FORWARDS=================//
forward Repair(playerid);
//=============================================//
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n-----------------------------------------");
    print(" /AutoFix/Flip/InfinityNos/by ThePrograme/ ");
    print("-----------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n-----------------------------------------");
    print(" /AutoFix/Flip/InfinityNos/by ThePrograme/ ");
    print("-----------------------------------------\n");
}

#endif

public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
{
    if ( HOLDING( KEY_FIRE ) && GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
    {
          AddVehicleComponent( GetPlayerVehicleID( playerid ), 1010 );
    }

    if (  RELEASED( KEY_FIRE ) && GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
    {
          RemoveVehicleComponent( GetPlayerVehicleID( playerid ), 1010 );
    }
    if((newkeys&KEY_CROUCH)&&!(oldkeys&KEY_CROUCH))
    {
        new VehicleID,Float:B;
        VehicleID = GetPlayerVehicleID(playerid);
        GetVehicleZAngle(VehicleID,B);
        SetVehicleZAngle(VehicleID,B);
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    SetTimerEx("Repair",1000,true,"i",playerid);
    return 1;
}
public Repair(playerid)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
    new Float:health;
    new vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleHealth(vehicleid, health);
    if (health <= 1000)
        {
    SetVehicleHealth(vehicleid,1000);
    }
    }
}

public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    #pragma unused playerid

    RepairVehicle(vehicleid);
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    tires = encode_tires(0, 0, 0, 0);
    panels = encode_panels(0, 0, 0, 0, 0, 0, 0);
    doors = encode_doors(0, 0, 0, 0, 0, 0);
    lights = encode_lights(0, 0, 0, 0);
    UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    return 1;
}

encode_tires(tire1, tire2, tire3, tire4) return tire1 | (tire2 << 1) | (tire3 << 2) | (tire4 << 3);
encode_panels(flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper)
{
    return flp | (frp << 4) | (rlp << 8) | (rrp << 12) | (windshield << 16) | (front_bumper << 20) | (rear_bumper << 24);
}
encode_doors(bonnet, boot, driver_door, passenger_door, behind_driver_door, behind_passenger_door)
{
    #pragma unused behind_driver_door
    #pragma unused behind_passenger_door
    return bonnet | (boot << 8) | (driver_door << 16) | (passenger_door << 24);
}
encode_lights(light1, light2, light3, light4)
{
    return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
}
Oh and this script also contains scripts for vehicles to FLIP and have NITRO
One more thing if you like to have this script and get more details for it go here:
https://sampforum.blast.hk/showthread.php?tid=373147
OR click [FilterScript] AutoFix/Flip/InfinityNos at the bottom.

========>THANKS IN ADVANCE<========


Re: ==>Auto Fix Problem<== - Konstantinos - 29.12.2012

Just use a timer and inside the callback a for loop through all the players. Check if they are connected and if they are drivers and repairvehicle by using the function to get the vehicle ID.


Re: ==>Auto Fix Problem<== - ThePrograme - 29.12.2012

Can you make that for this script? I'm not such a scripter, or anyone!!


Re: ==>Auto Fix Problem<== - ThePrograme - 29.12.2012

Can anyone at least help me make this in my script: ??
Quote:
Originally Posted by Dwane
Посмотреть сообщение
Just use a timer and inside the callback a for loop through all the players. Check if they are connected and if they are drivers and repairvehicle by using the function to get the vehicle ID.



Re: ==>Auto Fix Problem<== - Konstantinos - 29.12.2012

Sorry, I was on the mobile the time I replied and it would take ages to make it there.
pawn Код:
#define FILTERSCRIPT

new
    af_timer
;

public OnFilterScriptInit( )
{
    af_timer = SetTimer( "AutoRepair", 500, true );
    return 1;
}

public OnFilterScriptExit( )
{
    KillTimer( af_timer );
    return 1;
}

forward AutoRepair( );
public AutoRepair( )
{
    for( new playerid; playerid < MAX_PLAYERS; playerid ++ )
    {
        if( !IsPlayerConnected( playerid ) ) continue;
        if( GetPlayerState( playerid ) != PLAYER_STATE_DRIVE ) continue;
        RepairVehicle( GetPlayerVehicleID( playerid ) );
    }
    return 1;
}



Re: ==>Auto Fix Problem<== - ThePrograme - 29.12.2012

Oh no problem. You don't need to apologise!!


Re: ==>Auto Fix Problem<== - ThePrograme - 29.12.2012

Thanks man it works perfectly now :P