Comparing vehicle plates
#1

Hello,
I've made a command that you would input a vehicle plate, and if the vehicle is found, it will mark it in the radar.

The problem is that it always says, no matter what I put:
The vehicle has been found and been marked in the radar. [Veh: 2000].
And it marks a checkpoint in the Blueberry farms.


I do use this function to change the vehicle plates, and store them in a variable, replacing AddStaticVehicleEx with a custom function:

pawn Код:
stock AddStaticVehEx( model, Float:vx, Float:vy, Float:vz, Float:vrot, vc1, vc2, rspwn = 60000 )
{
    ScriptCars++;
    new tmp;
    tmp = AddStaticVehicleEx( model, vx, vy, vz, vrot, vc1, vc2, rspwn );
   
    new szString[128];
    format( szString, 128, "GOV-%d", 100+random( 900 ) );
   
    if ( IsAPoliceVehicle( tmp ) )
        format( szString, 128, "SFPD-%d", 100+random( 900 ) );
       
    SetVehiclePlateEx( tmp, szString );
   
    return tmp;
}
The command:
pawn Код:
CMD:trackplate( playerid, params[] )
{
    if ( isnull( params ) )
    {
        return ShowSyntaxMessage( playerid, "/trackplate [plate number]");
    }
   
    else
    {
        new found, moving, szString[128];
       
        for( new i = 1; i < MAX_VEHICLES+1; i ++ )
        {
            if ( !strcmp( VehiclePlate[i], params, true ) ){
                found = i;
            }
        }
       
        if ( found )
        {
            new Float:vehiclex, Float:vehicley, Float:vehiclez;
            if ( GetVehicleSpeed( found, true ) > 10 )
                moving = 1;
            else
                moving = 0;

            GetVehiclePos( found, vehiclex, vehicley, vehiclez );
            SetPlayerCheckpoint( playerid, vehiclex, vehicley, vehiclez, 2.0 );
           
            format( szString, 128, "The vehicle has been found and been marked in the {ff0000}radar. [Veh: %d]", found );
            SendClientMessage( playerid, -1, szString );

            if( moving == 1 ) {
                new vspeed = GetVehicleSpeed( found, true );
                new vspd = floatround( vspeed, floatround_ceil );

                format( szString, 128, "Vehicle moving speed: {ff000}%d KM/h", vspd );
                SendClientMessage( playerid, -1, szString );
            }
        }
       
        else
        {
            SendClientMessage( playerid, -1, "Vehicle has not been found.");
        }
    }
   
    return 1;
}
Assist me with help, please!
Reply
#2

bump.
Reply
#3

The problem is in here:
pawn Код:
if ( !strcmp( VehiclePlate[i], params, true ) ){
    found = i;
}
strcmp returns 0 when the strings are the same, BUT it also returns 0 if either string is empty. Add a break; statement after found = i;. If this does not fix it, then there is a problem with your VehiclePlate variable.
Reply
#4

Hello Vince,

I've added a break; statement after found = i however it returns the message:

The vehicle has been found and been marked in the radar. [Veh: 1].

Does that mean the problem is in the VehiclePlate variable? I've shown you how /every/ script vehicle has an assigned vehicle plate.

My SetVehiclePlateEx function;
pawn Код:
stock SetVehiclePlateEx( vehicleid, string[] )
{
    SetVehicleNumberPlate( vehicleid, string[] );
    format( VehiclePlate[vehicleid], 64, string );
    return VehiclePlate[vehicleid];
}
Reply
#5

Quote:
Originally Posted by admantis
Посмотреть сообщение
...
Does it happen for every vehicle? Also, note you've an unnecessary pair of brackets following "string" in your SetVehicleNumberPlate call. Further note: as per the SA-MP wiki, vehicle plates can contain only 32 characters, so "VehiclePlate" should only contain 32 cells in comparison to the 64 you currently use.

EDIT: As Vince said, also do an "isnull" check on VehiclePlate to ensure that it does in fact contain something to prevent false positives with strcmp.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)