Help with loop inside loop
#1

I have this code:
http://pastebin.com/D7VQYMJ2
The problem is in this line:
for(new v = 0; v <= 20; v++) if(!IsVehicleOccupied(MVehicle[v])) PutPlayerInVehicle(i, MVehicle[v], 0),printf("ID: %d, V: %d",i,v);

The ways its suppose to work:
looping through all players, checking if the player is in the monster activity,
then its suppose to put him inside one of the activity cars (ONLY IF ITS FREE), then to the next player ..

The way its actually working:
Its looping through all players, checking if the player is in the monster activity,
then its putting him inside one of the activity cars, and here starts the problem:
when its moving to the next player, its putting him in the same vehicle as the previous player ..
Reply
#2

Is the "IsVehicleOccupied" function working the way it should at that point? It could be that the information for the function is not updated between 2 close calls.

For testing, create another Array which saves if the Monstertrucks are occupied or not and check it that way.
Like MVehicleOccupied, setting it to 1 where PutPlayerInVehicle is called.
Reply
#3

Quote:
Originally Posted by NaS
View Post
Is the "IsVehicleOccupied" function working the way it should at that point? It could be that the information for the function is not updated between 2 close calls.

For testing, create another Array which saves if the Monstertrucks are occupied or not and check it that way.
Like MVehicleOccupied, setting it to 1 where PutPlayerInVehicle is called.
you mean something like this ?
if(!MVehicleO[v] == 0)) PutPlayerInVehicle(i, MVehicle[v], 0),MVehicleO[v] = 1;
Reply
#4

Yeah almost. Remove the ! and one ) and extend it with a break:

Code:
if(MVehicleO[v] == 0)
{
PutPlayerInVehicle(i, MVehicle[v], 0);
MVehicleO[v] = 1; 
break;
}
Without the break it would put the first player in all vehicles and set them occupied.
Put the code into the Vehicle Loop obviously.

And remember to reset the MVehicleO Array when restarting the event.
Reply
#5

Quote:
Originally Posted by NaS
View Post
Yeah almost. Remove the ! and one ) and extend it with a break:

Code:
if(MVehicleO[v] == 0)
{
PutPlayerInVehicle(i, MVehicle[v], 0);
MVehicleO[v] = 1; 
break;
}
Without the break it would put the first player in all vehicles and set them occupied.
Put the code into the Vehicle Loop obviously.

And remember to reset the MVehicleO Array when restarting the event.
thank you so much dude
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)