#1

Is it possible to have MAX_PLAYERS and MAX_VEHICLE in one "for()" loop
so i want in foor lop: MAX_PLAYER to be "i" and MAX_VEHICLES to be "iv"
I hope someone understands me xD
Reply
#2

so basically what i am doing is a /rac (respawn all cars) and i want some vehicles to be destroyed and others to SetVehicleToRespawn. Admins can create cars and the id of that car is pInfo[playerid][AdminCar] - i want do destroy thoose vehicles and just respawn the others.

EDIT: this is my old /rac command:
Код:
	    	new bool:vehicleused[MAX_VEHICLES];
			for(new i=0; i < MAX_PLAYERS; i++)
			{
				if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
				{
					vehicleused[GetPlayerVehicleID(i)] = true;
				}
			}
			for(new i=1; i < MAX_VEHICLES; i++)
			{
				if(!vehicleused[i])
				{
					SetVehicleToRespawn(i);
				}
			}
Reply
#3

Yes it is but it's uneccesary, you know MAX_PLAYERS is "1000" max, and vehicle IDs go through 1..1999 so just add a check if "i" is less than MAX_PLAYERS:
pawn Код:
for (new i = 0; i < MAX_VEHICLES; i++)
{
    if (i < MAX_PLAYERS]
        // Destroy admin spawned vehicles here

    // Anything else
}
Second version with TWO loops:
pawn Код:
for (new i = 0, iv = 1; i < MAX_PLAYERS, iv < MAX_VEHICLES; i++, iv++)
{
    // Do stuff
}
Reply
#4

Can you please help me with the command ?
Can you add vehicleused and that stuff...
Reply
#5

Well that would be a 1min job for me and I would gladly do it if I were on my PC.
So here are the steps, first loop through all the vehicles, name the iterator "v", then use "foreach" and loop through connected players only, name that "i", use only GetPlayerVehicleID(i) and set your vehicleused[v] variable to true. Then make a new loop to loop through all vehicles again and do whatever you have to do.
Reply
#6

well i didn't understand that well
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)