Vehicle passenger iterator
#1

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?
Reply
#2

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.
Reply
#3

Quote:
Originally Posted by Crayder
View Post
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;
}
Reply
#4

Quote:
Originally Posted by m4karow
View Post
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?
Reply
#5

Init only once under ongamemodeinit (without vehicleid parameter).
Reply
#6

Quote:
Originally Posted by raydx
View Post
Init only once under ongamemodeinit (without vehicleid parameter).
Oh I corrected, thanks
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
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_VEHICLESMAX_PLAYERS>;
foreach (new 
playerid Passenger<vehicleid>)
{

Basically just replace [vehicleid] with <vehicleid>.
Alright
Thanks for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)