Despawn more than 1 vehicle - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Despawn more than 1 vehicle (
/showthread.php?tid=652025)
Despawn more than 1 vehicle -
MarianImmortalGod - 01.04.2018
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:
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[vDBID[PCarID]][pcStatus] = 0;
pcUpdate(vDBID[PCarID], pcStatus);
DestroyVehicle(PCarID);
vDBID[PCarID] = 0;
}
}
cache_delete®;
}
Код HTML:
stock VEHICLEFROMDB(dbid)
{
for(new i = 1; i <= GetVehiclePoolSize(); i++)
{
if(vDBID[i] == dbid) return i;
}
return 0;
}
Re: Despawn more than 1 vehicle -
Maxandmov - 02.04.2018
Код:
stock VEHICLEFROMDB(dbid)
{
for(new i = 1; i <= GetVehiclePoolSize(); i++)
{
if(vDBID[i] == dbid) return i;
}
return 0;
}
As far as I see you return first vehicle you find.
I had rather do it somehow like that (I might be wrong in what I coded, but I hope you get the general idea)
Код:
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]);
for(new i = 1; i <= GetVehiclePoolSize(); i++)
{
if(vDBID[i] == dbid)
{
if(PCarID)
{
CarInfo[vDBID[PCarID]][pcStatus] = 0;
pcUpdate(vDBID[PCarID], pcStatus);
DestroyVehicle(PCarID);
vDBID[PCarID] = 0;
}
}
}
}
cache_delete®;
}
I mean, I have to cycle through every entry there. This stock, VehicleFromDB, returns first entry which fulfills the requirement, which means it's not quite suitable for your task.
Re: Despawn more than 1 vehicle -
MarianImmortalGod - 02.04.2018
Nothing happens