Merged in gps-vehicle-atm-command (pull request #70)

/gps vehicle/atm
This commit is contained in:
Marin Kovač 2019-02-03 09:27:16 +00:00 committed by Lorenc Pekaj
commit f3849a6a86
2 changed files with 56 additions and 1 deletions

View File

@ -195,9 +195,31 @@ CMD:gps( playerid, params[ ] )
GPS_StopNavigation( playerid ); GPS_StopNavigation( playerid );
return SendServerMessage( playerid, "You have de-activated your GPS." ), 1; return SendServerMessage( playerid, "You have de-activated your GPS." ), 1;
} }
else if ( GetPlayerState( playerid ) != PLAYER_STATE_DRIVER ) return SendError( playerid, "You have to be a driver of a vehicle to use this a command." );
else if ( GetPlayerInterior( playerid ) != 0 ) return SendError( playerid, "You must be outside of the interior." );
else if( !strcmp( params, "atm", false, 3 ) ) {
new Float: oX, Float: oY, Float: oZ;
new atmID = GetClosestATM( playerid );
GetATMPos( atmID, oX, oY, oZ );
GPS_SetPlayerWaypoint( playerid, "Closest ATM", oX, oY, oZ );
SendServerMessage( playerid, ""COL_GREY"[GPS]"COL_WHITE" You have set your destination to closest atm." );
}
else if( !strcmp( params, "vehicle", false, 7 ) ){
new vehName[ 24 ];
if ( sscanf( params[ 8 ], "s[ 24 ]", vehName ) ) return SendUsage( playerid, "/gps vehicle [NAME]" );
new Float: vXp, Float: vYp, Float: vZp, vehID = GetVehicleModelFromName( vehName );
if( vehID == -1 ) return SendError( playerid, "Invalid vehicle name." );
GetVehiclePos( GetClosestVehicleModel( playerid, vehID ), vXp, vYp, vZp );
SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GPS]"COL_WHITE" You have set your destination to closest %s", GetVehicleName( vehID ) );
GPS_SetPlayerWaypoint( playerid, sprintf( "Closest vehicle: %s", GetVehicleName( vehID ) ), vXp, vYp, vZp );
}
else else
{ {
if ( GetPlayerState( playerid ) != PLAYER_STATE_DRIVER ) return SendError( playerid, "You have to be a driver of a vehicle to use this a command." );
ShowPlayerDialog( playerid, DIALOG_GPS_CITY, DIALOG_STYLE_LIST, "{FFFFFF}GPS - Choose City", "San Fierro\nLas Venturas\nLos Santos", "Select", "Cancel" ); ShowPlayerDialog( playerid, DIALOG_GPS_CITY, DIALOG_STYLE_LIST, "{FFFFFF}GPS - Choose City", "San Fierro\nLas Venturas\nLos Santos", "Select", "Cancel" );
} }
return 1; return 1;
@ -282,3 +304,18 @@ function GPS_Update( playerid, Float: destX, Float: destY, Float: destZ )
PlayerTextDrawSetString( playerid, p_GPSInformation[ playerid ], sprintf( "~g~Location:~w~ %s~n~~g~Distance:~w~ %0.2fm", p_GPSDestName[ playerid ], distance ) ); PlayerTextDrawSetString( playerid, p_GPSInformation[ playerid ], sprintf( "~g~Location:~w~ %s~n~~g~Distance:~w~ %0.2fm", p_GPSDestName[ playerid ], distance ) );
return 1; return 1;
} }
stock GetClosestVehicleModel( playerid, id ){
new closest = -1, Float: closestDist = 8000.00, Float: distance, Float: pX, Float: pY, Float: pZ;
GetPlayerPos( playerid, pX, pY, pZ );
for ( new i = 0; i < MAX_VEHICLES; i++ ) {
if( GetVehicleModel( i ) == id ) {
distance = GetVehicleDistanceFromPoint( i, pX, pY, pZ );
if( closestDist > distance ){
closestDist = distance;
closest = i;
}
}
}
return closest;
}

View File

@ -239,3 +239,21 @@ stock CreateATM( Float: X, Float: Y, Float: Z, Float: rX, Float: offset = 180.0,
} }
return ID; return ID;
} }
stock GetClosestATM( playerid ){
new closest = -1, Float: closestDist = 8000.00, Float: distance, Float: pX, Float: pY, Float: pZ, Float: oX, Float: oY, Float: oZ;
GetPlayerPos( playerid, pX, pY, pZ );
for( new i = 0; i < MAX_ATMS; i++ ){
GetATMPos( i, oX, oY, oZ );
distance = VectorSize( pX-oX, pY-oY, pZ-oZ );
if( closestDist > distance ){
closestDist = distance;
closest = i;
}
}
return closest;
}
stock GetATMPos( atmID, &Float: X, &Float: Y, &Float: Z ) {
return GetDynamicObjectPos( g_atmData[ atmID ] [ E_OBJECT ], X, Y, Z );
}