CarOwner
#1

I have a simple script, where gonna show the owner of a vehicle, by your ID.

Example:

/checkplate 212
"The owner of this car is : My name is Jeff"

The problem, isn't on the command, and yes, on the SQL.
I found something on my database.
Instead show the car owner name, show he's ID on the database.
Example:

CarID | CarOwner | ...
212 4

I want to convert the ID, for the player name. It's possible?
Instead show the ID of the car owner, show he's name.

CarData Enum:
PHP код:
enum carData {
    
carID,
    
carExists,
    
carModel,
    
carOwner,
    
Float:carPos[4],
    
carColor1,
    
carColor2,
    
carPaintjob,
    
carLocked,
    
carMods[14],
    
carImpounded,
    
carImpoundPrice,
    
carFaction,
    
carWeapons[5],
    
carAmmo[5],
    
carVehicle
}; 
CarOwner SQL example(s)
The examples it's biggest, then i uploaded her on pastebin

1ST Example
2ND Example

Command:
PHP код:
CMD:verifyplate(playeridparams[])
{
    new
        
id 0,
        
fabrication random(2016);
    if (
GetFactionType(playerid) != FACTION_POLICE)
        return 
SendErrorMessage(playerid"You need's be a cop.");
    if (
sscanf(params"d"id))
        return 
SendSyntaxMessage(playerid"/verifyplate [vehicleid]");
    if (!
IsValidVehicle(id) || Car_GetID(id) == -1)
        return 
SendErrorMessage(playerid"You specified a invalid vehicle ID.");
    
Owner cache_get_field_content(id"carOwner"CarData[id][carOwner], g_iHandleMAX_PLAYER_NAME);
    
Dialog_Show(playeridInfoPMESPDIALOG_STYLE_MSGBOX"MDC""Vehicle Model: %s\nYear of Fabrication: %i\nOwner: %s.""Fechar"""ReturnVehicleName(id), FabricationOwner);
    return 
1;

I guess, if I create ownerName on the enum, and create a sql table with this, I can create the command, but i don't know how do this.
Reply
#2

Automatically assuming that carOwner is a foreign key of some kind of player/account table in your database. Upon spawning the vehicle you also load the owner information.
Код:
format(query, sizeof(query), "SELECT PlayerName FROM playerTable WHERE ID=%i", CarData[id][carOwner]);
mysql_tquery(connection, query, "OnPlayerLoadForVehicles", "i", CarData[id][carOwner]);
Creating the function:
Код:
forward OnPlayerLoadForVehicles(vID);
public OnPlayerLoadForVehicles(vID)
{
     new rows = cache_get_row_count(connection);
     if (rows == 1)
    {
           cache_get_field_content(0, "PlayerName", CarData[vID][carOwnerName]); //select first row (0) and take out whatever is stated in it  and place it into the enum
    }
    return 1;
}
Add carOwnerName as a string into your CarData enum (carOwnerName[MAX_PLAYER_NAME]). Note, this is only a template of an example and not the actual answer, you cannot just copy-paste this expecting it will work.
Reply
#3

I have said this once already:
Quote:
Originally Posted by Vince
Посмотреть сообщение
The function cache_get_field_content() itself doesn't return anything, except perhaps 1 or 0 to denote success or failure. The actual string value is being stored in "CarData[id][carOwner]".
Yet you're STILL doing it wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)