From bb530eb1c9cb7f0f4bb3795ff07299f20124dc1c Mon Sep 17 00:00:00 2001 From: Crova Date: Sun, 3 Feb 2019 09:12:45 +0100 Subject: [PATCH 1/3] /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 From 406d705ae12843240f5fb31524554fc80b03c92e Mon Sep 17 00:00:00 2001 From: Crova Date: Sun, 3 Feb 2019 10:13:39 +0100 Subject: [PATCH 2/3] Interior check, vehicle id validation --- gamemodes/irresistible/cnr/features/gps.pwn | 20 +++++-------------- .../cnr/features/robbery/atms.pwn | 14 +++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gamemodes/irresistible/cnr/features/gps.pwn b/gamemodes/irresistible/cnr/features/gps.pwn index 53cd3b9..58666b6 100644 --- a/gamemodes/irresistible/cnr/features/gps.pwn +++ b/gamemodes/irresistible/cnr/features/gps.pwn @@ -196,6 +196,7 @@ CMD:gps( playerid, params[ ] ) 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 ); @@ -208,9 +209,12 @@ CMD:gps( playerid, params[ ] ) 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 vehicle (model %d)", vehID ); + SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GPS]"COL_WHITE" You have set your destination to closest %s", GetVehicleName( vehID ) ); GPS_SetPlayerWaypoint( playerid, "Closest vehicle (model)", vXp, vYp, vZp ); } @@ -301,20 +305,6 @@ function GPS_Update( playerid, Float: destX, Float: destY, Float: destZ ) 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++){ diff --git a/gamemodes/irresistible/cnr/features/robbery/atms.pwn b/gamemodes/irresistible/cnr/features/robbery/atms.pwn index 7d19990..682fd71 100644 --- a/gamemodes/irresistible/cnr/features/robbery/atms.pwn +++ b/gamemodes/irresistible/cnr/features/robbery/atms.pwn @@ -240,6 +240,20 @@ stock CreateATM( Float: X, Float: Y, Float: Z, Float: rX, Float: offset = 180.0, 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; + 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 GetATMPos( atmID, &Float: X, &Float: Y, &Float: Z ) { return GetDynamicObjectPos( g_atmData[ atmID ] [ E_OBJECT ], X, Y, Z ); } \ No newline at end of file From a15fa28382902ad5110085036aee4ff1188e86a6 Mon Sep 17 00:00:00 2001 From: Crova Date: Sun, 3 Feb 2019 10:25:33 +0100 Subject: [PATCH 3/3] Sexying the code --- gamemodes/irresistible/cnr/features/gps.pwn | 12 ++++++------ gamemodes/irresistible/cnr/features/robbery/atms.pwn | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gamemodes/irresistible/cnr/features/gps.pwn b/gamemodes/irresistible/cnr/features/gps.pwn index 58666b6..c00470c 100644 --- a/gamemodes/irresistible/cnr/features/gps.pwn +++ b/gamemodes/irresistible/cnr/features/gps.pwn @@ -205,8 +205,8 @@ CMD:gps( playerid, params[ ] ) 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 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 ); @@ -216,7 +216,7 @@ CMD:gps( playerid, params[ ] ) SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GPS]"COL_WHITE" You have set your destination to closest %s", GetVehicleName( vehID ) ); - GPS_SetPlayerWaypoint( playerid, "Closest vehicle (model)", vXp, vYp, vZp ); + GPS_SetPlayerWaypoint( playerid, sprintf( "Closest vehicle: %s", GetVehicleName( vehID ) ), vXp, vYp, vZp ); } else { @@ -307,9 +307,9 @@ function GPS_Update( playerid, Float: destX, Float: destY, Float: destZ ) 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 ); + 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; diff --git a/gamemodes/irresistible/cnr/features/robbery/atms.pwn b/gamemodes/irresistible/cnr/features/robbery/atms.pwn index 682fd71..0cc3224 100644 --- a/gamemodes/irresistible/cnr/features/robbery/atms.pwn +++ b/gamemodes/irresistible/cnr/features/robbery/atms.pwn @@ -242,10 +242,10 @@ stock CreateATM( Float: X, Float: Y, Float: Z, Float: rX, Float: offset = 180.0, 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++){ + GetPlayerPos( playerid, pX, pY, pZ ); + 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) ) ) ); + distance = VectorSize( pX-oX, pY-oY, pZ-oZ ); if( closestDist > distance ){ closestDist = distance; closest = i;