Despawn car
#1

Hey guys i have a personal vehicle system but i have a problem with the cars, when a player
disconnect's and his cars are spawned and let's say he has more than 1 car only first
car will despawn(destroyed) but the other one wont any idea what is wrong with this
script ?

HTML Code:
function DespawnPlayerVehicle(playerid)
{
	new gQuery[85];
    mysql_format(handle, gQuery, sizeof(gQuery),  "SELECT * FROM `personalcars` WHERE `Owner` = '%s'", GetName(playerid));
    new Cache:r = mysql_query(handle, gQuery);
    for(new i; i < cache_num_rows(); i++)
	{
	    new dbid = cache_get_value_name_int(i, "ID", CarInfo[playerid][pcID]);
   		new PCarID = VEHICLEFROMDB(dbid);
   		if(PCarID)
   		{
			CarInfo[cData[PCarID]][pcStatus] = 0;
			pcUpdate(cData[PCarID], pcStatus);

			DestroyVehicle(PCarID);
			cData[PCarID] = 0;
   		}
 	}
 	cache_delete®;
}
HTML Code:
stock VEHICLEFROMDB(dbid)
{
    for(new i = 1; i <= GetVehiclePoolSize(); i++)
	{
	    if(cData[i] == dbid) return i;
	}
	return 0;
}
Reply
#2

You using two different enum "cData" at "stock VEHICLEFROMDB" and "CarInfo" at "function DespawnPlayerVehicle". (WHY?!)

Try change like this:
Code:
enum e_vehicles
{
vUID,
vModelid,
vOwner,
vStatus
etc (..)
}
new VehicleData[MAX_VEHICLS][e_vehicles];
So, we have one enum for keep data vehicles...

Now change your functions:
Code:
stock UnspawnPlayerVehicles(playerid)
{
	new gQuery[85], vehicle_sampid, vehicle_row_uid;
    mysql_format(handle, gQuery, sizeof(gQuery),  "SELECT * FROM `personalcars` WHERE `Owner` = '%s'", GetName(playerid));
    new Cache:result = mysql_query(handle, gQuery);
   
    for(new index = 0; index != cache_num_rows(); index++)
	{
	    cache_get_value_int(index, "ID", vehicle_row_uid);
	    vehicle_sampid = GetVehicleSampidByUID(vehicle_row_uid);
   
   		if(vehicle_sampid)
   		{
   			// Unspawn, so.. we should clear vehicle data:
   			VehicleData[vehicle_sampid][vUID] = 0;
   			VehicleData[vehicle_sampid][vModelid] = 0;
   			VehicleData[vehicle_sampid][vOwner] = 0;
			VehicleData[vehicle_sampid][vStatus] = 0;
			
			DestroyVehicle(vehicle_sampid);
   		}
 	}
 	cache_delete(result);
}

stock GetVehicleSampidByUID(vehicle_uid)
{
    for(new i = 1; i <= GetVehiclePoolSize(); i++)
	{
	    if(VehicleData[i][vUID] == vehicle_uid) return i;
	}
	return 0;
}
Reply
#3

I did, is the same just the 1st car from my personal cars as a player but the other one still wont despawn.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)