Vehicle passenger iterator - 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: Vehicle passenger iterator (
/showthread.php?tid=665327)
Vehicle passenger iterator -
m4karow - 30.03.2019
Hey
Is it a good idea to save the passengers to an iterator for faster loop through passengers or finding the vehicle driver? I'll have about 1700 vehicles.
Code:
static Iterator:VehiclePassengers[MAX_VEHICLES]<MAX_PLAYERS>;
and under OnPlayerStateChange add-remove them.
What is your advice?
Re: Vehicle passenger iterator -
Crayder - 31.03.2019
Yeah this is actually exactly what you probably want to do! Nice usage of an iterator... however, you may want to use "multi-iterators" instead of an array of iterators.
See
here for more info, check the first part under "New Features".
This will do the same thing, but much more efficiently and with less usage.
Re: Vehicle passenger iterator -
m4karow - 31.03.2019
Quote:
Originally Posted by Crayder
Yeah this is actually exactly what you probably want to do! Nice usage of an iterator... however, you may want to use "multi-iterators" instead of an array of iterators.
See here for more info, check the first part under "New Features".
This will do the same thing, but much more efficiently and with less usage.
|
I'm using it like that.
Code:
foreach(new passenger : VehiclePassengers[vehicleid])
{
}
Code:
Iter_Add(VehiclePassengers[vehicleid], playerid);
Code:
Iter_Remove(VehiclePassengers[vehicleid], playerid);
Code:
hook OnVehicleCreated(vehicleid)
{
Iter_Init(VehiclePassengers[vehicleid]);
return Y_HOOKS_CONTINUE_RETURN_1;
}
Re: Vehicle passenger iterator -
m4karow - 31.03.2019
Quote:
Originally Posted by m4karow
I'm using it like that.
Code:
foreach(new passenger : VehiclePassengers[vehicleid])
{
}
Code:
Iter_Add(VehiclePassengers[vehicleid], playerid);
Code:
Iter_Remove(VehiclePassengers[vehicleid], playerid);
Code:
hook OnVehicleCreated(vehicleid)
{
Iter_Init(VehiclePassengers[vehicleid]);
return Y_HOOKS_CONTINUE_RETURN_1;
}
|
Or the init isn't correct? Should init that under OnScriptInit?
Re: Vehicle passenger iterator -
raydx - 31.03.2019
Init only once under ongamemodeinit (without vehicleid parameter).
Re: Vehicle passenger iterator -
m4karow - 31.03.2019
Quote:
Originally Posted by raydx
Init only once under ongamemodeinit (without vehicleid parameter).
|
Oh
I corrected, thanks
Re: Vehicle passenger iterator -
m4karow - 31.03.2019
Quote:
Originally Posted by Y_Less
The multi iterator version Crayder mentioned would be better. Your code could have a player in multiple vehicles at once, which can't happen. Instead:
PHP Code:
new Iterator:Passenger<MAX_VEHICLES, MAX_PLAYERS>;
foreach (new playerid : Passenger<vehicleid>)
{
}
Basically just replace [vehicleid] with <vehicleid>.
|
Alright
Thanks for your help