You need to create an array to hold the owner's name inside your vehicle's enumerator.
Example:
Код:
enum E_VEHICLEDATA
{
Owner[24],
other data...
}
g_VehicleInfo[MAX_VEHICLE][E_VEHICLEDATA];
Then, once player buys a vehicle, save owner's name in the file as well as other data. Also format the name to make sure that the array has owner's name stored
Example:
Код:
new name[24];
GetPlayerName(playerid, name, sizeof(name));
format(g_VehicleInfo[vehicleid][Owner], 24, name);
// Saving process ...
And under OnPlayerStateChange callback, check if the vehicle owner's name is matching to the name of the player that entered the vehicle
Example:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if (newstate == PLAYER_STATE_DRIVER:
{
new vehicleid, name[24], string[64];
GetPlayerName(playerid, name, sizeof(name));
vehicleid = GetPlayerVehicleID(playerid);
if (g_VehicleInfo[vehicleid][Owned] == 1)
{
if (strcmp(g_VehicleInfo[vehicleid][Owner], name) != 0) // name didn't match
{
RemovePlayerFromVehicle(playerid);
format(string, sizeof(string), "This vehicle is owned by %s", g_VehicleInfo[vehicleid][Owner]);
SendClientMessage(playerid, -1, string);
}
}
}
return 1;
}