SA-MP Forums Archive
Help - 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: Help (/showthread.php?tid=531462)



Help - Fjclip99 - 12.08.2014

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



Re: Help - Fjclip99 - 12.08.2014

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);
				}
			}



Re: Help - Virtual1ty - 12.08.2014

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
}



Re: Help - Fjclip99 - 12.08.2014

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


Re: Help - Virtual1ty - 12.08.2014

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.


Re: Help - Fjclip99 - 13.08.2014

well i didn't understand that well