GetNearestsVehicles without cikle. - 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: GetNearestsVehicles without cikle. (
/showthread.php?tid=604894)
GetNearestsVehicles without cikle. -
ScIrUsna - 11.04.2016
Hi,
It's possible to get nearest vehicles without doing cikle? for example i have only 20 near vehicle to player but i have in server 1800 vehicles and my max_vehicles is 2000, i have do big cikle, it's possible to make cikle including just 20 repeatings or something else?
Re: GetNearestsVehicles without cikle. -
Konstantinos - 11.04.2016
One way would be foreach/y_iterate. Add to an iterator the streamed vehicles and loop through them. You have to use the old multi-iterator method though.
An example:
pawn Код:
// global:
static
Iterator: gPlayerStreamedVehicles[MAX_PLAYERS]<MAX_VEHICLES>;
// OnGameModeInit:
Iter_Init(gPlayerStreamedVehicles);
// OnPlayerConnect:
Iter_Clear(gPlayerStreamedVehicles[playerid]);
public OnVehicleStreamIn(vehicleid, forplayerid)
{
Iter_Add(gPlayerStreamedVehicles[forplayerid], vehicleid);
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
Iter_Remove(gPlayerStreamedVehicles[forplayerid], vehicleid);
return 1;
}
// somewhere:
foreach (new v : gPlayerStreamedVehicles[playerid])
{
// "v" vehicleid is streamed in
}
Re: GetNearestsVehicles without cikle. -
ScIrUsna - 11.04.2016
Thanks it's only way or there is better way?
I could do this foreach in onplayerupdate? do some getvehiclepos and some calculations, distances
Re: GetNearestsVehicles without cikle. -
Crayder - 11.04.2016
Quote:
Originally Posted by ScIrUsna
Thanks it's only way or there is better way?
I could do this foreach in onplayerupdate? do some getvehiclepos and some calculations, distances
|
It's not the "only" way technically, but it is the best one you'll find. y_iterate is made specifically for these types of things!