SA-MP Forums Archive
Plate Check - 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: Plate Check (/showthread.php?tid=604422)



Plate Check - McGuiness - 04.04.2016

Hey guys,

So I was working on my plate check system for LEO factions and I stumbled upon a problem, sure the system complies correctly but the only problem I have with it is that I made some test vehicles to test it, but when I type in the plate I want to check, it comes up with the first vehicle that was spawned with its plate and owner information and won't find the plate that matches to the text someone had typed into the command, I don't know what the problem is so I was wondering if any of you experts know whats wrong with the command.

Here is the code:
Код:
CMD:sdpc(playerid, params[])
{
	new string[128];
	if(isnull(params)) return SendClientMessage(playerid, COLOUR_WHITE, "SYNTAX: /sdpc [Plate]");
	new vehid = FindVehicleByPlate(params);
	if(vehid == 0) return SendClientMessage(playerid, COLOUR_WHITE, "Invaild Plate");
	SendClientMessage(playerid, COLOUR_WHITE, "Bone County Dept. of Motor Vehicles");
	format(string, sizeof(string), "Owner: %s", CarInfo[vehid][cOwner]);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	format(string, sizeof(string), "Plate: %s", CarInfo[vehid][cPlate]);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	return 1;
}

stock FindVehicleByPlate(plate[])
{
	for(new i = 1; i < MAX_VEHICLES; i++)
	{
	    if(strcmp(CarInfo[i][cPlate], plate, true))
	    {
	        return i;
	    }
	}
	return 0;
}



Re: Plate Check - Lucky13 - 04.04.2016

Try this:

Код:
CMD:sdpc(playerid, params[])
{
	new string[128];
	if(isnull(params)) return SendClientMessage(playerid, COLOUR_WHITE, "SYNTAX: /sdpc [Plate]");
	new vehid = FindVehicleByPlate(params);
	if(vehid == INVALID_VEHICLE_ID) return SendClientMessage(playerid, COLOUR_WHITE, "Invaild Plate");
	SendClientMessage(playerid, COLOUR_WHITE, "Bone County Dept. of Motor Vehicles");
	format(string, sizeof(string), "Owner: %s", CarInfo[vehid][cOwner]);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	format(string, sizeof(string), "Plate: %s", CarInfo[vehid][cPlate]);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	return 1;
}
stock FindVehicleByPlate(plate[])
{
	for(new i = 1; i < MAX_VEHICLES; i++)
	{
	    if(strcmp(CarInfo[i][cPlate], plate, true) == 0)
	    {
	        return i;
	    }
	}
	return INVALID_VEHICLE_ID;
}
I bold and colored what I've added extra.


Re: Plate Check - McGuiness - 04.04.2016

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

Код:
CMD:sdpc(playerid, params[])
{
	new string[128];
	if(isnull(params)) return SendClientMessage(playerid, COLOUR_WHITE, "SYNTAX: /sdpc [Plate]");
	new vehid = FindVehicleByPlate(params);
	if(vehid == INVALID_VEHICLE_ID) return SendClientMessage(playerid, COLOUR_WHITE, "Invaild Plate");
	SendClientMessage(playerid, COLOUR_WHITE, "Bone County Dept. of Motor Vehicles");
	format(string, sizeof(string), "Owner: %s", CarInfo[vehid][cOwner]);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	format(string, sizeof(string), "Plate: %s", CarInfo[vehid][cPlate]);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	return 1;
}
stock FindVehicleByPlate(plate[])
{
	for(new i = 1; i < MAX_VEHICLES; i++)
	{
	    if(strcmp(CarInfo[i][cPlate], plate, true) == 0)
	    {
	        return i;
	    }
	}
	return INVALID_VEHICLE_ID;
}
I bold and colored what I've added extra.
I just tried it, good news is it doesn't show the first vehicle created's info, but now it won't show any information at all! When I use the command, the text comes back with the plate and owner being blank! .-.


Re: Plate Check - Lucky13 - 04.04.2016

Hmm try to use printf("%d",vehid); in your command and tell me the result in console


Re: Plate Check - McGuiness - 04.04.2016

The results from the console for that command come back as the vehid being 1


Re: Plate Check - Lucky13 - 04.04.2016

And the plate you inserted was the first vehicle plate? ( plate you inserted = first added vehicle plate )


Re: Plate Check - McGuiness - 04.04.2016

BCFDVehicles[0] = CreateVehicle(407, -96.7046, 1173.1196, 19.9583, 0.0000, 194, 13, 100);

format(CarInfo[BCFDVehicles[0]][cPlate], 32, "Y45DMR");
format(CarInfo[BCFDVehicles[0]][cOwner], 32, "Bone County Fire Dept.");
SetVehicleNumberPlate(BCFDVehicles[0], "{68C24F}Y45DMR");

This is the info


Re: Plate Check - Lucky13 - 04.04.2016

I think if you remove all what's infront of the = and replace CreateVehicle with AddStaticVehicleEx, it will work. You are risking to mix the vehicle ids there


Re: Plate Check - Konstantinos - 04.04.2016

It returns 0 when 2 strings are same. It also returns 0 when one of them is NULL/empty.

pawn Код:
FindVehicleByPlate(const plate[])
{
    for (new i = 1; i < MAX_VEHICLES; i++)
    {
        if (!GetVehicleModel(i)) continue; // vehicles does not exist, skip
        if (isnull(CarInfo[i][cPlate])) continue; // plate is not set to that vehicle, skip
        if (!strcmp(CarInfo[i][cPlate], plate, true)) return i; // returns 0 when 2 strings are same
    }
    return 0;
}



Re: Plate Check - McGuiness - 04.04.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It returns 0 when 2 strings are same. It also returns 0 when one of them is NULL/empty.

pawn Код:
FindVehicleByPlate(const plate[])
{
    for (new i = 1; i < MAX_VEHICLES; i++)
    {
        if (!GetVehicleModel(i)) continue; // vehicles does not exist, skip
        if (isnull(CarInfo[i][cPlate])) continue; // plate is not set to that vehicle, skip
        if (!strcmp(CarInfo[i][cPlate], plate, true)) return i; // returns 0 when 2 strings are same
    }
    return 0;
}
Thank you so much! it works perfectly, and thank you Lucky13 for trying to help me fix the system!