Proper way to check if another player is in your vehicle? Need assistance. -
Aerotactics - 22.04.2014
I'm rewriting a script I made so long ago with my newer knowledge of SAMP and Pawn scripting. I've got it almost completely working except for one small bit of code.
The issue: When other players create a car, all works fine. When I create a car (as id 0), I get the output that there's nobody in the car, when there actually is someone in the car.
pawn Код:
if (BCDisabled[playerid] == 0)
{
for (new i=0; i<MAX_PLAYERS;i++)
{
for (new j=0;j<MAX_VEHICLES;j++)
{
if (IsPlayerInVehicle(i,BC[j]))
{
SendClientMessage(j, Yellow , "Bait-Car Disabled.");
SendClientMessage(i, Yellow , "You are locked in the Bait-Car.");
SetVehicleParamsEx(BC[j], 0, 0, 0, 0, 0, 0, 0);
BCDisabled[j] = 1;
return 1;
}
else return SendClientMessage(j, Yellow , "Nobody in Bait-Car.");
}
}
}
else
{
SendClientMessage(playerid, Yellow , "Bait-Car Enabled.");
SetVehicleParamsEx(BC[playerid], 1, 0, 0, 0, 0, 0, 0);
BCDisabled[playerid] = 0;
return 1;
}
Re: Proper way to check if another player is in your vehicle? Need assistance. -
Fel486 - 22.04.2014
The single thing I can observe is that the loop of VEHICLES goes through the loop of the PLAYERS, so to process the first one, the second must be done.
So, try that:
pawn Код:
new i = 0, j = 0;
if (BCDisabled[playerid] == 0)
{
start:
while(i < MAX_PLAYERS)
{
while(j < MAX_VEHICLES)
{
if (IsPlayerInVehicle(i,BC[j]))
{
SendClientMessage(j, Yellow , "Bait-Car Disabled.");
SendClientMessage(i, Yellow , "You are locked in the Bait-Car.");
SetVehicleParamsEx(BC[j], 0, 0, 0, 0, 0, 0, 0);
BCDisabled[j] = 1;
j++;
i++;
goto start;
}
else SendClientMessage(j, Yellow , "Nobody in Bait-Car.");
}
}
}
else
{
SendClientMessage(playerid, Yellow , "Bait-Car Enabled.");
SetVehicleParamsEx(BC[playerid], 1, 0, 0, 0, 0, 0, 0);
BCDisabled[playerid] = 0;
return 1;
}
If it's not that, sorry. I just can see that.
Re: Proper way to check if another player is in your vehicle? Need assistance. -
Aerotactics - 22.04.2014
Quote:
Originally Posted by Fel486
The single thing I can observe is that the loop of VEHICLES goes through the loop of the PLAYERS, so to process the first one, the second must be done.
So, try that:
If it's not that, sorry. I just can see that.
|
I'll definitely try it. I've never used a while loop in SAMP, but it's not too late to learn how to use it.
Re: Proper way to check if another player is in your vehicle? Need assistance. -
Konstantinos - 22.04.2014
You check if the vehicleid is one of those who have been stored in
BC array. If its size is not 2000 (which it shouldn't), you don't have to loop so many times. Also using foreach will reduce the times it loops through the players.
About this line:
pawn Код:
else return SendClientMessage(j, Yellow , "Nobody in Bait-Car.");
You use "return" so it breaks the loop. You send the message to the "j" which is the loop's variable for the vehicles and not the players.