SA-MP Forums Archive
How to get near car id? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to get near car id? (/showthread.php?tid=657239)



How to get near car id? - R3SpaWn0 - 03.08.2018

Hi again ! .. i want to make an offset for my character to dont get stuck in the car when i spawn but.. i need to get the near car id and save in x,y,z, then spawn player +2,y,z or something, how to do this?


pd: all questions that i make here i ussualy solve them after i post XDDD


Re: How to get near car id? - DBZdabIt3Bro7 - 03.08.2018

So what you want to do is... loop through all vehicles to check if the position of said vehicle is in the area of the player, and if it is, set the z-coordinate to +2.00?

PHP код:
#define VEHICLE_MARGINATION            (5)
#define VEHICLE_MARGINATION_DEPTH (2)
enum COORDINATIONS {
  
COORDINATE_BREADTH,
  
COORDINATE_HEIGTH,
  
COORDINATE_DEPTH
}
execution(playerid) {
  new 
virtualWorld GetPlayerVirtualWorld(playerid);
  for(new 
index 0maxIndex GetVehiclePoolSize(); index <= maxIndexindex++) {
    if(
IsValidVehicle(index) && (GetVehicleVirtualWorld(index) == virtualWorld)) {
      
      new 
Float:vehiclePosition[COORDINATIONS];
      
GetVehiclePos(indexvehiclePosition[COORDINATE_BREADTH], vehiclePosition[COORDINATE_HEIGTH], vehiclePosition[COORDINATE_DEPTH]);
      if(
IsPlayerInRangeOfPoint(playeridfloat(VEHICLE_MARGINATION), vehiclePosition[COORDINATE_BREADTH], vehiclePosition[COORDINATE_HEIGTH], vehiclePosition[COORDINATE_DEPTH])) {
        
        new 
Float:pedPosition[COORDINATIONS];
        
GetPlayerPos(playeridpedPosition[COORDINATE_BREADTH], pedPosition[COORDINATE_HEIGTH], pedPosition[COORDINATE_DEPTH]),
        
SetPlayerPos(playeridpedPosition[COORDINATE_BREADTH], pedPosition[COORDINATE_HEIGTH], floatadd(pedPosition[COORDINATE_DEPTH], float(VEHICLE_MARGINATION_DEPTH)));
        
        break;
      }
    }
  }


i'm too lazy to write a description to what's happening, you should be able to figure it out.


Re: How to get near car id? - R3SpaWn0 - 03.08.2018

Quote:
Originally Posted by DBZdabIt3Bro7
Посмотреть сообщение
So what you want to do is... loop through all vehicles to check if the position of said vehicle is in the area of the player, and if it is, set the z-coordinate to +2.00?

PHP код:
#define VEHICLE_MARGINATION_DEPTH (2)
enum COORDINATIONS {
  
COORDINATE_BREADTH,
  
COORDINATE_HEIGTH,
  
COORDINATE_DEPTH
}
execution(playerid) {
  new 
virtualWorld GetPlayerVirtualWorld(playerid);
  for(new 
index 0maxIndex GetVehiclePoolSize(); index <= maxIndexindex++) {
    if(
IsValidVehicle(index) && (GetVehicleVirtualWorld(index) == virtualWorld)) {
      
      new 
Float:vehiclePosition[COORDINATIONS];
      
GetVehiclePos(indexvehiclePosition[COORDINATE_BREADTH], vehiclePosition[COORDINATE_HEIGTH], vehiclePosition[COORDINATE_DEPTH]);
      if(
IsPlayerInRangeOfPoint(playeridVEHICLE_MARGINATIONvehiclePosition[COORDINATE_BREADTH], vehiclePosition[COORDINATE_HEIGTH], vehiclePosition[COORDINATE_DEPTH])) {
        
        new 
Float:pedPosition[COORDINATIONS];
        
GetPlayerPos(playeridpedPosition[COORDINATE_BREADTH], pedPosition[COORDINATE_HEIGTH], pedPosition[COORDINATE_DEPTH]),
        
SetPlayerPos(playeridpedPosition[COORDINATE_BREADTH], pedPosition[COORDINATE_HEIGTH], floatadd(pedPosition[COORDINATE_DEPTH], float(VEHICLE_MARGINATION_DEPTH)));
        
        break;
      }
    }
  }


i'm too lazy to write a description to what's happening, you should be able to figure it out.
i will try to use that what you say, but vehicles is loaded from mysql, idk if work like that but i go try train my brain to get it work , thank you !


Re: How to get near car id? - DBZdabIt3Bro7 - 03.08.2018

Quote:
Originally Posted by R3SpaWn0
Посмотреть сообщение
i will try to use that what you say, but vehicles is loaded from mysql, idk if work like that but i go try train my brain to get it work , thank you !
It shouldn't matter where you get your vehicle's data from... as long as they're spawned in the script.


Re: How to get near car id? - R3SpaWn0 - 03.08.2018

Quote:
Originally Posted by DBZdabIt3Bro7
Посмотреть сообщение
It shouldn't matter where you get your vehicle's data from... as long as they're spawned in the script.
thank you a lot man, but, this script have to be called somewere, in onplayerspawn, yes?