From bb530eb1c9cb7f0f4bb3795ff07299f20124dc1c Mon Sep 17 00:00:00 2001 From: Crova Date: Sun, 3 Feb 2019 09:12:45 +0100 Subject: [PATCH] /gps vehicle/atm --- gamemodes/irresistible/cnr/features/gps.pwn | 49 ++++++++++++++++++- .../cnr/features/robbery/atms.pwn | 4 ++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/gamemodes/irresistible/cnr/features/gps.pwn b/gamemodes/irresistible/cnr/features/gps.pwn index b85097f..53cd3b9 100644 --- a/gamemodes/irresistible/cnr/features/gps.pwn +++ b/gamemodes/irresistible/cnr/features/gps.pwn @@ -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; +} \ No newline at end of file diff --git a/gamemodes/irresistible/cnr/features/robbery/atms.pwn b/gamemodes/irresistible/cnr/features/robbery/atms.pwn index 71c04b4..7d19990 100644 --- a/gamemodes/irresistible/cnr/features/robbery/atms.pwn +++ b/gamemodes/irresistible/cnr/features/robbery/atms.pwn @@ -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 ); +} \ No newline at end of file