Vehicle and Control Structure bug.
#1

Hi there. I am having this bug where I can't find a solution for it. Here is the code:

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		if(GetPlayerVehicleID(playerid) == VMManana1 || VMManana2 || VMManana3 || VMManana4 || VMManana5 || VMManana6 || VMManana7 || VMManana8)
		{
                      Something...
		}
        }
        return 1;
}
And This one:

Код:
new VMManana1, VMManana2, VMManana3, VMManana4, VMManana5, VMManana6, VMManana7, VMManana8;

public OnGameModeInit()
{
	VMManana1 = CreateVehicle(410, 50.6609, -246.2147, 1.1500, -362.8800, -1, -1, 100);
	VMManana2 = CreateVehicle(410, 54.8561, -246.3267, 1.1500, -361.1999, -1, -1, 100);
	VMManana3 = CreateVehicle(410, 59.0317, -246.3769, 1.1500, -361.9201, -1, -1, 100);
	VMManana4 = CreateVehicle(410, 63.2701, -246.5288, 1.1500, -361.5000, -1, -1, 100);
	VMManana5 = CreateVehicle(410, 67.5284, -246.6424, 1.1500, -361.8001, -1, -1, 100);
	VMManana6 = CreateVehicle(410, 71.7640, -246.7473, 1.1500, -361.8599, -1, -1, 100);
	VMManana7 = CreateVehicle(410, 75.9283, -246.8683, 1.1500, -361.7397, -1, -1, 100);
	VMManana8 = CreateVehicle(410, 80.2232, -246.9288, 1.1500, -361.9799, -1, -1, 100);
}
So first of all when I get on my server and get in any car in my gamemode (including the Manana's AND any other car), I get that "Something..." executed. Even if it's any car. Althoug when I change this:

Код:
if(GetPlayerVehicleID(playerid) == VMManana1 || VMManana2 || VMManana3 || VMManana4 || VMManana5 || VMManana6 || VMManana7 || VMManana8)
Into this for example:

Код:
if(GetPlayerVehicleID(playerid) == VMManana1)
Then I simply don't have a problem. "Something..." is executed only when I enter that car. I tested it. So it's a Control Structure problem. The "||" (or) are supposed to mean "execute Something... when I enter VMManana1 or VMManana2 or VMManana3..." and so on. But why does it execute on ALL cars?

Also another thing: I have a seperate filterscript where I have stored all the vehicles, except I used the Manana's in my Gamemode. But somehow when I arrive near the Manana's I see them duplicated. I swear there is no more CreateVehicle's for Manana's found in my Gamemode or the filterscript. I am ABSOLUTELY sure about it. Why are there 16 Manana's instead of 8? What is duplicating them?

P.S. I had those Manana's in my filterscript before I created the code above, but I deleted them out of the filterscript (and compiled it) and added them in the Gamemode as well as imported them into Variables. Then the Manana's still keep duplicating.
Reply
#2

With
pawn Код:
if(GetPlayerVehicleID(playerid) == VMManana1 || VMManana2 || VMManana3 || VMManana4 || VMManana5 || VMManana6 || VMManana7 || VMManana8)
you are actually doing this check:
pawn Код:
if( GetPlayerVehicleID( playerid ) == VMManana1 || VMManana2 != 0 || VMManana3 != 0 || VMManana4 != 0 || VMManana5 != 0 || VMManana6 != 0 || VMManana7 != 0 || VMManana8 != 0 )
which is always 1 because vehicle IDs start from 1, and a check like 0 || VEHICLEID || VEHICLEID || VEHICLEID is always 1 because it's an OR.

what you actually want is this:
pawn Код:
if(GetPlayerVehicleID(playerid) == VMManana1 || GetPlayerVehicleID(playerid) == VMManana2 || GetPlayerVehicleID(playerid) == VMManana3 || GetPlayerVehicleID(playerid) == VMManana4 || GetPlayerVehicleID(playerid) == VMManana5 || GetPlayerVehicleID(playerid) == VMManana6 || GetPlayerVehicleID(playerid) == VMManana7 || GetPlayerVehicleID(playerid) == VMManana8)
Reply
#3

Many thanks friend. Seems it was just another non-experienced mistake. Have a good day!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)