Vehicle Plates
#1

Hello there.
In the database of vehicleinfo i have stored the vehicle plate now im trying to make a command which will read the vehicle place and show up the Vehicle informations like owner/ vehicle type etc etc.
The problem is that i dont know how to start the command, to get if the pressed text is an valid vehicle plate or it is not.Someone can give me an fast example pls i really need this.
Reply
#2

What version of MySQL are you using? Here's an example for R33 or higher.

PHP код:
CMD:checkplate(playeridparams[])
{
    new 
plate[128]; // MAX_PLATE_NUMBER
    
if (sscanf(params"s"plate)) return SendClientMessage(playerid, -1"USAGE: /checkplate (platenumber)");

    new 
query[128];
    
mysql_format(SQLquerysizeof(query), "SELECT `id` FROM `vehicles` WHERE `plate` = `%e`"plate);

    new 
Cache:result mysql_query(SQLquery);

    if (
cache_num_rows() > 0)
    {
        
// The plate number does exist
    
}
    else
    {
        
// It doesn't exist
    
}

    
cache_delete(result);

Reply
#3

Im using version R39-6
Okay so now that will get if the plate exists and if it doesnt but how can i show the vehicle owner/vehicle model from the plate that player has typed, everything is stored in same place as the "plate"? [Repped ++]
Reply
#4

Add what columns you want to retrieve in the query, for example:
Код:
SELECT owner,modelid FROM vehicles WHERE plate='%e' LIMIT 1
and if there are rows, use cache_get_field_content/cache_get_field_content_int functions to retrieve the data.

Just a side-note for sscanf. "s" specifier needs a size as "s[128]" but for single strings, use isnull + params.
Reply
#5

Use two different tables. The one for users and the other for vehicles.
Each user should have a different id (primary id). In the vehicles table create a row called ownerid which refers to the id of user.

Then you can identify the owner using this line in MySQL.

Код:
SELECT users.userid FROM users INNER JOIN vehicles ON users.userid = vehicles.ownerid
users table should look like this.

userid
username
money
...


vehicles table should look like this.

ownerid
vehicleid
color
...
Reply
#6

Thanks to you both , it worked but there is an little issue (might be because of string testing now) vehicle model shows 52 and not 411(infernus) - ill let you know if is really an issue or was string length.
Reply
#7

You know that GetVehicleModel is the right function to return vehicle model?

Some people are using GetPlayerVehicleID which is not correct.
Reply
#8

There is something wrong with this, when press to get the infos, plate works, owner works but the vehicle model shows 52 and the format isnt gettin really like it should be, i used \n but still shows in line
codes
Код:
COMMAND:checkplate(playerid, params[])
{
    new plate[128]; // MAX_PLATE_NUMBER
    if (sscanf(params, "s", plate)) return SendClientMessage(playerid, -1, "USAGE: /checkplate (platenumber)");

    new query[128];
    mysql_format(MySQLPipeline, query, sizeof(query),"SELECT Owner,Model FROM VehicleInfo WHERE Plate='%e' LIMIT 1", plate);

    new Cache:result = mysql_query(MySQLPipeline, query);
    new vehowner[80],vmodel[80];
    cache_get_field_content(0, "Owner", vehowner);
    cache_get_field_content(0, "Model", vmodel);
    if (cache_num_rows() > 0)
    {
	   new string[200];
	   format(string,sizeof(string),"Vehicle Owner: %s\nVehicle Model :%d",vehowner,vmodel);
	   SendClientMessage(playerid, -1,string);
	   SendClientMessage(playerid, -1, query);
        // The plate number does exist
    }
    else
    {
        SendClientMessage(playerid, -1, "Plate doesnt Exists");
    }
    cache_delete(result);
    return 1;
}
by the way in database the model is like vehicles id example - Infernus = 411.
Reply
#9

modelid is an integer so you should use cache_get_field_content_int function:
pawn Код:
new vmodel;

...

vmodel = cache_get_field_content_int(0, "Model");
and use the cache functions to retrieve inside the if statement otherwise if there are no rows, you'll get no active cache warnings.
Reply
#10

Thanks , ill test it now
by the way is there a faster way of loading i mean when i use the command and there is no plate it freezes the chat for like 2-3 seconds or less , or it is because it has to loop thought all plates etc etc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)