[HELP] Private Cars Overall?!
#1

Hello SA-MP scripters. I need some help with the private vehicle code I made. I've been seriously trying to figure it out for 2 days but no result. Here is my code:

pawn Код:
enum TeamCars
{
    saints1,
    saints2,
    saints3,
    saints4,
    saints5,
    saints6,
    saints7,
    saints8,
    saints9,
    saints10
}
new Cars[TeamCars];

//-------VEHICLES SAINTS-------
    Cars[saints1] = SetVehicleNumberPlate(CreateVehicle(560,-2644.8789,1376.7103,6.9458,181.3955,22,22,120),"Saints"); // Saints Sultan 1
    Cars[saints2] = SetVehicleNumberPlate(CreateVehicle(560,-2638.9302,1376.3307,6.9202,180.5883,22,22,120),"Saints"); // Saints Sultan 1
    Cars[saints3] = SetVehicleNumberPlate(CreateVehicle(560,-2632.6096,1376.6050,6.9095,180.1853,22,22,120),"Saints"); // Saints Sultan
    Cars[saints4] = SetVehicleNumberPlate(CreateVehicle(560,-2626.3423,1377.5211,6.9178,178.9595,22,22,120),"Saints"); // Saints Sultan
    Cars[saints5] = SetVehicleNumberPlate(CreateVehicle(560,-2620.1167,1377.8539,6.9195,180.6810,22,22,120),"Saints"); // Saints Sultan
    Cars[saints6] = SetVehicleNumberPlate(CreateVehicle(451,-2644.5520,1362.3519,6.9440,269.8624,22,22,120),"Saints"); // Saints Turismo
    Cars[saints7] = SetVehicleNumberPlate(CreateVehicle(522,-2645.0708,1350.9330,6.9445,271.4766,22,22,120),"Saints"); // Saints NRG 1
    Cars[saints8] = SetVehicleNumberPlate(CreateVehicle(522,-2646.3582,1347.0519,6.9502,270.3860,22,22,120),"Saints"); // Saints NRG 2
    Cars[saints9] = SetVehicleNumberPlate(CreateVehicle(520,-2640.5837,1418.0747,23.8984,199.6787,22,22,120),"Saints"); // Saints Hydra
    Cars[saints10] = SetVehicleNumberPlate(CreateVehicle(487,-2657.3650,1400.7468,23.8984,293.9929,22,22,120),"Saints"); // Saints Heli

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
        {
        new CarCheck = GetPlayerVehicleID(playerid);
        if(CarCheck == Cars[saints1] || Cars[saints2] || Cars[saints3] || Cars[saints4] || Cars[saints5] || Cars[saints6] || Cars[saints7] || Cars[saints8] || Cars[saints9] || Cars[saints10] )
        {
            if(pTeam[playerid] != team_saints)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_RED, "You Don't have the keys for this car!");
                return 1;
            }
            else if(pTeam[playerid] == team_saints){SendClientMessage(playerid, COLOR_YELLOW, "You passed the Saints Exam!");}
        }
        return 1;
        }
//------------------------------------------------------------------------------
    return 1;
}
PROBLEM: If I am team saints, I can enter the saints cars successfully with the message "You passed the Saints Exam!". If I am another class it removes me from the car exactly like it was intended. BUT! If with another class I enter ANY OTHER car spawned it ejects me as if it were a saints car. I can't figure it out. Thanks for reading and helping me
Reply
#2

BUMP, it's been like 3 hours -__-
Reply
#3

Here's the problem:
Код:
if(CarCheck == Cars[saints1] || Cars[saints2] || Cars[saints3] || Cars[saints4] || Cars[saints5] || Cars[saints6] || Cars[saints7] || Cars[saints8] || Cars[saints9] || Cars[saints10] )
It needs to be this:
Код:
if(CarCheck == Cars[saints1] || CarCheck == Cars[saints2] || CarCheck == Cars[saints3] || CarCheck == Cars[saints4] || CarCheck == Cars[saints5] || CarCheck == Cars[saints6] || CarCheck == Cars[saints7] || CarCheck == Cars[saints8] || CarCheck == Cars[saints9] || CarCheck == Cars[saints10] )
Don't worry, I remember making this mistake too.
Reply
#4

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
Here's the problem:
Код:
if(CarCheck == Cars[saints1] || Cars[saints2] || Cars[saints3] || Cars[saints4] || Cars[saints5] || Cars[saints6] || Cars[saints7] || Cars[saints8] || Cars[saints9] || Cars[saints10] )
It needs to be this:
Код:
if(CarCheck == Cars[saints1] || CarCheck == Cars[saints2] || CarCheck == Cars[saints3] || CarCheck == Cars[saints4] || CarCheck == Cars[saints5] || CarCheck == Cars[saints6] || CarCheck == Cars[saints7] || CarCheck == Cars[saints8] || CarCheck == Cars[saints9] || CarCheck == Cars[saints10] )
Don't worry, I remember making this mistake too.
Thanks but It doesn't work With your code it complete disable the entire code. Everyone can enter saints cars and no message received. Meaning it didn't reached the else and the if.
Reply
#5

Try using "&&" instead of "||".
Reply
#6

&& doesn't work. The player can't be in 10 cars at the same time.

I just noticed this:
Код:
Cars[saints1] = SetVehicleNumberPlate(CreateVehicle(487,-2657.3650,1400.7468,23.8984,293.9929,22,22,120),"Saints"); // Saints Heli
I don't know what SetVehicleNumberPlate returns, but I guess it isn't the vehicle id.

Change it to this:
Код:
SetVehicleNumberPlate(Cars[saints1] = CreateVehicle(560,-2644.8789,1376.7103,6.9458,181.3955,22,22,120),"Saints"); // Saints Sultan 1
If that doesn't work either, change it to this:
Код:
Cars[saints1] = CreateVehicle(560,-2644.8789,1376.7103,6.9458,181.3955,22,22,120);
SetVehicleNumberPlate(Cars[saints1], "Saints"); // Saints Sultan 1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)