SA-MP Forums Archive
Get Car Pos - 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: Get Car Pos (/showthread.php?tid=384805)



Get Car Pos - Stefand - 13.10.2012

pawn Код:
dcmd_carpos(playerid,params[])
{
    new string[128], CARID;
    if(sscanf(params, "u", CARID))
    {
        SendClientMessage(playerid,COLOR_ERROR,"USAGE: /carpos (CARID)");
    }
    else
    {
        new Float: carx, Float: cary, Float: carz;
        GetVehiclePos(CARID, carx, cary, carz);
        format(string, sizeof(string), "%d's Position: %d, %d, %d.", CARID, carx, cary, carz);
        SendClientMessage(playerid, COLOR_WHITE, string);
        new Float: carangle;
        GetVehicleZAngle(CARID, carangle);
        format(string, sizeof(string), "%d's angle: %d.", CARID, carangle);
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Gives this result in game:

Код:
[15:32:37] 65535's Position: 0, 0, 0.
[15:32:38] 65535's angle: 0.
When I use /carpos 80


Re : Get Car Pos - lelemaster - 13.10.2012

Make sure the vehicle id exist.

Something like this.

if(CARID == INVALID_VEHICLE_ID) return //the message you want


Re: Get Car Pos - gtakillerIV - 13.10.2012

PHP код:
dcmd_carpos(playerid,params[])
{
    new 
string[128], CARID;
    if(
sscanf(params"i"CARID))
    {
        
SendClientMessage(playerid,COLOR_ERROR,"USAGE: /carpos (CARID)");
    }
    if(
CARID == INVALID_VEHICLE_ID) return SendClientMessage(playerid, -1"Wrong car ID!")
    else
    {
         new 
FloatcarxFloatcaryFloatcarz;
        
GetVehiclePos(CARIDcarxcarycarz);
        
format(stringsizeof(string), "%d's Position: %d, %d, %d."CARIDcarxcarycarz);
        
SendClientMessage(playeridCOLOR_WHITEstring);
        new 
Floatcarangle;
        
GetVehicleZAngle(CARIDcarangle);
        
format(stringsizeof(string), "%d's angle: %d."CARIDcarangle);
        
SendClientMessage(playeridCOLOR_WHITEstring);
    }
    return 
1;

That should do it.


Re: Get Car Pos - Stefand - 13.10.2012

Let me test it


Re: Get Car Pos - fordawinzz - 13.10.2012

just use '%f' instead of '%d' because the vehicle pos returns floats, lol


Re: Get Car Pos - Stefand - 13.10.2012



I use that DL ID and it sais Wrong ID


Re: Get Car Pos - Stefand - 13.10.2012

Quote:
Originally Posted by fordawinzz
Посмотреть сообщение
just use '%f' instead of '%d' because the vehicle pos returns floats, lol
and what % for the vehicle ID?


Re: Get Car Pos - Basssiiie - 13.10.2012



  1. The 'u' specifier in sscanf is for players, not for vehicles. It will check if there's someone with playerid 80, which there isn't.
  2. The '%d' specifier in format is for integers. The position and the angle of a vehicle are point numbers, or Floats. These have to be specified with '%f' instead of '%d'.
  3. It might be a good idea to check if the vehicle ID does actually exist, before you check it's position. There's a hidden native called 'IsValidVehicle'. If you want to use this, you need to add this to the top of your script:
    Код:
    native IsValidVehicle(vehicleid);
Edit: For your last question; the vehicle id it just an integer, so '%d' or '%i' will both work just fine. More information about format here.


Re: Get Car Pos - Stefand - 13.10.2012

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение


  1. The 'u' specifier in sscanf is for players, not for vehicles. It will check if there's someone with playerid 80, which there isn't.
  2. The '%d' specifier in format is for integers. The position and the angle of a vehicle are point numbers, or Floats. These have to be specified with '%f' instead of '%d'.
  3. It might be a good idea to check if the vehicle ID does actually exist, before you check it's position. There's a hidden native called 'IsValidVehicle'. If you want to use this, you need to add this to the top of your script:
    Код:
    native IsValidVehicle(vehicleid);
Edit: For your last question; the vehicle id it just an integer, so '%d' or '%i' will both work just fine. More information about format here.
pawn Код:
native IsValidVehicle(vehicleid);

dcmd_carpos(playerid,params[])
{
    #pragma unused params
    new string[128], CARID;
    if(IsValidVehicle(CARID))
    {
        new Float: carx, Float: cary, Float: carz;
        GetVehiclePos(CARID, carx, cary, carz);
        format(string, sizeof(string), "%i's Position: %f, %f, %f.", CARID, carx, cary, carz);
        SendClientMessage(playerid, COLOR_WHITE, string);
        new Float: carangle;
        GetVehicleZAngle(CARID, carangle);
        format(string, sizeof(string), "%i's angle: %f.", CARID, carangle);
        SendClientMessage(playerid, COLOR_WHITE, string);
    }
    return 1;
}
Should work?


Re: Get Car Pos - Basssiiie - 13.10.2012

Why did you remove sscanf? You need to extract the vehicle id from params? In that script 'CARID' will always stay 0, because there's no function that changes that.