command(lastdriver, playerid, params[])
{
new vehicleid;
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new query[500], data_value[50], name[24], string[500];
format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE `LastDriver` = '%s' AND `VehicleID` = sha1('%s')", vehicleid);
mysql_query(query);
mysql_store_result();
while(mysql_retrieve_row())
{
mysql_fetch_field_row(data_value, "LastDriver"); format(name, sizeof(name), "%s", data_value);
}
format(string, sizeof(string), "The last driver of this %s was {FF0000}%s{FFFFFF}", GetVehicleName(GetPlayerVehicleID(playerid)), name);
SendClientMessage(playerid, WHITE, string);
mysql_free_result();
}
else return SCM(playerid, WHITE, "You are not in a vehicle.");
return 1;
}
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
{
new query[512], vehicleid2;
format(query, sizeof(query), "UPDATE `vehicles` SET `LastDriver`=%s WHERE `VehicleID`=%d", pName(playerid), vehicleid2);
mysql_query(query);
mysql_free_result();
}
if(newstate == PLAYER_STATE_DRIVER)
{
new query[512], vehicleid2;
format(query, sizeof(query), "UPDATE `vehicles` SET `LastDriver`=%s WHERE `VehicleID`=%d", pName(playerid), vehicleid2);
mysql_query(query);
}
format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE `LastDriver` = '%s' AND `VehicleID` = sha1('%s')", vehicleid);
mysql_query(query);
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
{
new query[512],vehicleid2;
vehicleid2 = vSQLID[vehicleid]; // Wherever you store the SQL ID
format(query,sizeof(query),"UPDATE `vehicles` SET `LastDriver` = '%s' WHERE `VehicleID` = '%d'",pName(playerid),vehicleid2);
mysql_query(query);
mysql_free_result();
}
new lastDriver[MAX_VEHICLES] = {INVALID_PLAYER_ID,..};
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
{
lastDriver[vehicleid] = playerid;
}
// onVehicleDeath
lastDriver[vehicleid] = INVALID_PLAYER_ID;
command(lastdriver, playerid, params[])
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new name[24], string[500]; GetPlayerName(lastDriver[GetPlayerVehicleID(playerid)],name,sizeof(name));
format(string, sizeof(string), "The last driver of this %s was {FF0000}%s{FFFFFF}", GetVehicleName(GetPlayerVehicleID(playerid)), (isnull(name) ? "Unknown" : name));
SendClientMessage(playerid, WHITE, string);
}
else return SCM(playerid, WHITE, "You are not in a vehicle.");
return 1;
}
But why to use mysql?
Just use new LastDriver[MAX_VEHICLES]; OnPlayersStateChange().. if( newstate == DRIVER) { LastDriver[GetPlayerVehicleID(playerid)] = playerid; |