Find Player by Number Plate?
#1

Hello guys. For past days I've got new idea for my RP server. So bassically I want to create /findcarp and then input dialog pops up, you enter the number plate and pops up dialog with player stats (name, etc.)! So my problem is, how to check for car owner? This is my Player Car System:

Код:
#define MAX_CARS 200
enum cInfo
{
	id,
	cModel,
	Float:cX,
	Float:cY,
	Float:cZ,
	Float:cFa,
	Float:cHeal,
	cFuel,
	cColors[16],
	cColor[2],
	cOwner[MAX_PLAYER_NAME],
	cLock,
	cCost,
	cVehcom[127],
	cVehcoms[15],
	cPaintjob,
	cPlate
};
new CarInfo[MAX_CARS][cInfo];
Код:
stock LoadCars() // cars
{
    new time = GetTickCount();
	mysql_query("SELECT * FROM `"TABLE_CARS"`");
	mysql_store_result();
	for(new i; i < TOTALCARS; i++)
	{
	    strmid(CarInfo[i][cOwner],"None_Nones",0,strlen("None_Nones"),32);
	}
	if(mysql_num_rows() > 0)
	{
		for(new idx = 1; idx <= mysql_num_rows(); idx++)
		{
		    mysql_fetch_row(query);
        	sscanf(query, "p<|>is[32]iffffifis[16]is[128]is[128]",
			CarInfo[idx][id],
			CarInfo[idx][cOwner],
			CarInfo[idx][cModel],
			CarInfo[idx][cX],
			CarInfo[idx][cY],
			CarInfo[idx][cZ],
			CarInfo[idx][cFa],
			CarInfo[idx][cFuel],
			CarInfo[idx][cHeal],
			CarInfo[idx][cCost],
			CarInfo[idx][cColors],
			CarInfo[idx][cLock],
			CarInfo[idx][cVehcom],
			CarInfo[idx][cPaintjob],
			CarInfo[idx][cPlate]);
			sscanf(CarInfo[idx][cColors], "p<,>a<i>[2]",CarInfo[idx][cColor]);
			sscanf(CarInfo[idx][cVehcom], "p<,>a<i>[14]",CarInfo[idx][cVehcoms]);
			TOTALCARS++;
		}
	}
 	mysql_free_result();
    printf(" [Masinas]: Tika ieladetas - %d speletaju auto %d (ms)", TOTALCARS,GetTickCount() - time);
    return 1;
}
Код:
stock LoadMyCar(playerid)
{
	if(GetPlayerHouse(playerid) == 0) return 1;
	if(GetPlayerCar(playerid) == 0) return 1;
 	new c = GetPVarInt(playerid, "PlayerCars");
	new carid = CreateVehicle(CarInfo[c][cModel], CarInfo[c][cX], CarInfo[c][cY], CarInfo[c][cZ], CarInfo[c][cFa], CarInfo[c][cColor][0], CarInfo[c][cColor][1], 90000);
 	CarDoors(carid, CarInfo[c][cLock]);
 	Fuel[carid] = CarInfo[c][cFuel];
 	SetVehicleNumberPlate(carid, CarInfo[c][cPlate]);
 	SetVehicleHealth(carid, CarInfo[c][cHeal]);
	Engine[carid] = false;
	Lights[carid] = false;
	switch(CarInfo[c][cLock])
	{
 		case 0: IsLocked[carid] = false;
 		case 1: IsLocked[carid] = true;
	}
	SetPVarInt(playerid,"CREVEH",carid);
	if(CarInfo[c][cVehcoms][0]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][0]);
	if(CarInfo[c][cVehcoms][1]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][1]);
	if(CarInfo[c][cVehcoms][2]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][2]);
	if(CarInfo[c][cVehcoms][3]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][3]);
	if(CarInfo[c][cVehcoms][4]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][4]);
	if(CarInfo[c][cVehcoms][5]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][5]);
	if(CarInfo[c][cVehcoms][6]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][6]);
	if(CarInfo[c][cVehcoms][7]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][7]);
	if(CarInfo[c][cVehcoms][8]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][8]);
	if(CarInfo[c][cVehcoms][9]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][9]);
	if(CarInfo[c][cVehcoms][10]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][10]);
	if(CarInfo[c][cVehcoms][11]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][11]);
	if(CarInfo[c][cVehcoms][12]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][12]);
	if(CarInfo[c][cVehcoms][13]!=0) AddVehicleComponent(carid,CarInfo[c][cVehcoms][13]);
	if(CarInfo[c][cVehcoms][14]!=0) AddVehicleComponent(carid,CarInfo[c][cVehcoms][14]);
	if(CarInfo[c][cPaintjob]!=0) ChangeVehiclePaintjob(carid, CarInfo[c][cPaintjob]);
	return true;
}
Bassically, I don't know how to get the vehicle ID and then the cOwner...

P.S The vehicle number plate is stored at cPlate, it's completely working and randomized, saved.
Reply
#2

I've made some pseudo code for you here that might help you in figuring it out, it's got a bit of an explanation:

pawn Код:
Command findcarp
{
    Do checks if they are a cop or whatever you want to check here before they can use the command
    Show the dialog here asking the user to enter the car plate
}

Dialog response
{
    Check if the dialog is equal to the dialog ID that you used for the command
    {
        Create a variable that will store the ID of the vehicle (e.g. new vehid;)
        Set vehid to -1, you will understand why later
        Create a loop that will go through all the vehicle information (CarInfo)
        {
            Use strcmp (compares if two strings are equal) to check if the inputtext is equal to the plate on the vehicle
            {
                If so, set vehid to the variable used by the loop (like, for(new i = ...), the variable used by the loop is i)
                break the loop here to avoid lag and waste of time
            }
        }
        Remember when we set the vehid to -1? Check if the vehid variable is still equal to -1
        {
            Tell the user that no vehicle exists with that ID
        }
        Otherwise, if it is not equal to -1 anymore (i.e. a vehicle has been found)
        {
            You can simply use vehid as you have done for "idx" in LoadCars, "c" in LoadMyCar, just as what the vehicle ID is
            Here is a quick example that might help you:
            Send a client a message with cOwner by using: CarInfo[vehid][cOwner];
            On your LoadMyCar stock it would have been used as: CarInfo[c][cOwner]; as c is what determines the record if you will
            Notice how I used vehid there.
            Do whatever you want here (right after the last { and the next }), add dialogs blabla using the vehid
        }
    }
}
strcmp documentation: https://sampwiki.blast.hk/wiki/Strcmp

Fun fact: I had this idea too back in the day for police members, such as enabling an ANPR system (Automatic Number Plate Recognition) on specific police vehicles with objects such as cameras all around the vehicle and if anyone was to drive past (or even if the car was empty and was not in a garage or a secure location) something like this would appear (of course not fully on the screen, but a little less details and some information regarding the problem): http://www.radcommuk.co.uk/images/an...r-software.jpg

I completely forgot about this idea, if you wanna use it feel free, I'll probably think of a new one and implement it on my server a little later. Can't be bothered using this now.
Reply
#3

I don't know what command processor you use, I just used YCMD for demonstration purposes.

pawn Код:
#define DIALOG_GET_OWNER 150
//The command
YCMD:ownerbyplate(playerid, params[], help) { //Assuming you use YCMD.
    if(help) {
        SendClientMessage(playerid, X11_WHITE, "Allows you to find the owner of a vehicle by plate.");
        return 1;
    }
    ShowPlayerDialog(playerid, DIALOG_GET_OWNER, DIALOG_STYLE_INPUT, "Plate System","Enter the plate number to check","Check", "Cancel");
    return 1;
}

stock findCarOwnerByPlate(platenr) { //Pass the platenr as a function argument
    new xret[32];
    for(new i=0;i<sizeof(CarInfo);i++) {
        if(CarInfo[i][cPlate] == platenr) { //If it matches any plate in the array
            strcpy(xret, CarInfo[i][cOwner]); //copy it
        }
    }
    return strlen(xret) != 0 ? (xret) : ("None"); //Ternary ops: If the strlen is not 0, return the owner, otherwise, return none
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    new msg[128];
    if(dialogid == DIALOG_GET_OWNER) {
        if(!response) {
            SendClientMessage(playerid, COLOR_WHITE, "You closed the dialog.");
            return 1;
        }
        format(msg, sizeof(msg), "The car owner is %s", findCarOwnerByPlate(strval(inputtext)));
        SendClientMessage(playerid, COLOR_WHITE, msg);
        return 1;
    }
}
Reply
#4

Thank you guys! +REP for both, for helping me out! It's late, I will see if I can figure something out tomorrow!
Reply
#5

BUMP! @IngleWoodRolePlay I'm sorry, I implemented the code into the gamemode, but it's not working... Always returning car owner as "None"!
Reply
#6

In enum you have cPlate as integer, but in sscanf function you use s[128] for returning number plate. Maybe here is problem. SetVehicleNumberPlate needs string, not integer. Also try to print vehicle's number plate to be sure it's loaded good.
Reply
#7

BUMP! Anyone?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)