18.10.2014, 16:11
Hi!
How do i check if a trailer detached the truck i am driving?
How do i check if a trailer detached the truck i am driving?
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;
}