IsCarInUse - 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: IsCarInUse (
/showthread.php?tid=384108)
IsCarInUse -
martin149 - 10.10.2012
Is there any way to see if a car is in use or not. I want to use it to periodically delete all cars from my server except the ones in use.
Re: IsCarInUse -
Stigg - 10.10.2012
https://sampwiki.blast.hk/wiki/IsPlayerInVehicle
Re: IsCarInUse -
martin149 - 10.10.2012
The i have to brute force match all cars, but i can give it a try
Re: IsCarInUse -
Kwarde - 10.10.2012
pawn Код:
stock IsCarInUse(vehicleid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (!IsPlayerConnected(i)) continue;
if (IsPlayerInVehicle(i, vehicleid)) return true;
}
return false;
}
stock RemoveAllEmptyVehicles()
{
for (new i = 0; i < MAX_VEHICLES; i++)
if (!IsCarInUse(i)) DestroyVehicle(i);
return true;
}
With this "IsCarInUse" function, you can check if the vehicle is used. With the "RemoveAllEmptyVehicles" function, you can destroy all unused vehicles.
Re: IsCarInUse -
Kwarde - 10.10.2012
That's actually a quite good idea. I'll keep that in mind if I ever make such thing for myself.
Re: IsCarInUse -
martin149 - 10.10.2012
I was just writing code, when Kwarde posted the right code, TY. As for ******, the preformance is not a big problem, because I have a limited number of users and enough processing power