/gps vehicle/atm

This commit is contained in:
Crova 2019-02-03 09:12:45 +01:00
parent bf94e5f763
commit bb530eb1c9
2 changed files with 52 additions and 1 deletions

View File

@ -195,9 +195,27 @@ CMD:gps( playerid, params[ ] )
GPS_StopNavigation( playerid );
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( !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 );
GetVehiclePos( GetClosestVehicleModel( playerid, vehID ), vXp, vYp, vZp );
SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GPS]"COL_WHITE" You have set your destination to closest vehicle (model %d)", vehID );
GPS_SetPlayerWaypoint( playerid, "Closest vehicle (model)", vXp, vYp, vZp );
}
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" );
}
return 1;
@ -282,3 +300,32 @@ 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 ) );
return 1;
}
stock GetClosestATM( playerid ){
new closest = -1, Float: closestDist = 8000.00, Float: distance, Float: pX, Float: pY, Float: pZ, Float: oX, Float: oY, Float: oZ;
for(new i = 0; i < MAX_ATMS; i++){
GetATMPos( i, oX, oY, oZ );
GetPlayerPos( playerid, pX, pY, pZ );
distance = floatsqroot( ( (pX - oX) * (pX - oX) ) + ( (pY - oY) * (pY - oY) + ( (pZ - oZ) * (pZ - oZ) ) ) );
if( closestDist > distance ){
closestDist = distance;
closest = i;
}
}
return closest;
}
stock GetClosestVehicleModel( playerid, id ){
new closest = -1, Float: closestDist = 8000.00, Float: distance, Float: pX, Float: pY, Float: pZ;
for(new i = 0; i < MAX_VEHICLES; i++){
if( GetVehicleModel(i) == id ){
GetPlayerPos( playerid, pX, pY, pZ );
distance = GetVehicleDistanceFromPoint( i, pX, pY, pZ );
if( closestDist > distance ){
closestDist = distance;
closest = i;
}
}
}
return closest;
}

View File

@ -239,3 +239,7 @@ stock CreateATM( Float: X, Float: Y, Float: Z, Float: rX, Float: offset = 180.0,
}
return ID;
}
stock GetATMPos( atmID, &Float: X, &Float: Y, &Float: Z ) {
return GetDynamicObjectPos( g_atmData[ atmID ] [ E_OBJECT ], X, Y, Z );
}