Trailer Detached
#1

Hi!
How do i check if a trailer detached the truck i am driving?
Reply
#2

https://sampwiki.blast.hk/wiki/IsTrailerAttachedToVehicle
Hope it helped.
Reply
#3

How do i check that while i'm driving the vehicle and the trailer get detached?
Reply
#4

pawn Код:
new TRAILER_TIMER [ MAX_PLAYERS ];
new TRAILER_OLD_STATE [ MAX_VEHICLES ];
new TRAILER_NEW_STATE [ MAX_VEHICLES ];


public OnPlayerConnect ( playerid ) {
    TRAILER_TIMER [ playerid ] = -1;
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    TRAILER_TIMER [ playerid ] = -1;
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new veh_id = GetPlayerVehicleID ( playerid );
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) // Player entered a vehicle as a driver
    {
        if ( GetVehicleModel ( veh_id ) == 403 || GetVehicleModel ( veh_id ) == 514 || GetVehicleModel ( veh_id ) == 515 ) {
            TRAILER_TIMER [ playerid ] = SetTimerEx ( "TRAILER_STATE_CHANGE", 1000, true, "i", TRAILER_STATE_CHANGE );
        }  
    }
    if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER) // Player exited from vehicle.
    {
        if ( TRAILER_TIMER [ playerid ] != -1 ) { KillTimer ( TRAILER_TIMER [ playerid ] ); }
    }  
    return 1;
}

forward TRAILER_STATE_CHANGE ( playerid );
public TRAILER_STATE_CHANGE ( playerid ) {
    new p_veh = GetPlayerVehicleID ( playerid );
    TRAILER_OLD_STATE [ p_veh ] = TRAILER_NEW_STATE [ p_veh ];
    if ( IsTrailerAttachedToVehicle ( p_veh ) ) { TRAILER_NEW_STATE [ p_veh ] = 1; } else { TRAILER_NEW_STATE [ p_veh ] = 0; } // 1 - true is attached | 0 - false isn't attached
   
    if ( TRAILER_OLD_STATE [ p_veh ] == 0 && TRAILER_NEW_STATE [ p_veh ] == 1 ) {
        // attached
    }
    if ( TRAILER_OLD_STATE [ p_veh ] == 1 && TRAILER_NEW_STATE [ p_veh ] == 0 ) {
        // de-attached
    }  
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    TRAILER_OLD_STATE [ vehicleid ] = 0;
    TRAILER_NEW_STATE [ vehicleid ] = 0;
    return 1;
}
try.. if work +rep me please.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)