Get Car Pos
#1

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
Reply
#2

Make sure the vehicle id exist.

Something like this.

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

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.
Reply
#4

Let me test it
Reply
#5

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



I use that DL ID and it sais Wrong ID
Reply
#7

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



  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.
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)