Team only vehicles, Y U NO WORK!?
#1

Hey everyone, I'm trying to create vehicles that can only be entered by specific teams, it compiles with no errors, however the script doesn't work for, except for 1 car (Burrito, from Grovestreet)..

Here's the script

Код HTML:
enum TeamCars
{
Grove,
Ballas,
Vagos,
Rifa
}

new Cars[TeamCars];
Код HTML:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if (AdminDuty[playerid] == 0)
	{
		if(newstate == 2)
	    {
	        new CarCheck = GetPlayerVehicleID(playerid);
	        if(CarCheck == Cars[Grove] )
	        {
	            if(gTeam[playerid] != TEAM_GROVE)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Grovestreet members can enter this vehicle!");
	                return 1;
	            }
	        }
	        else if(CarCheck == Cars[Ballas])
	        {
	            if(gTeam[playerid] != TEAM_BALLAS)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Ballas members can enter this vehicle!");
	                return 1;
	            }
	        }
	        else if(CarCheck == Cars[Vagos])
	        {
	            if(gTeam[playerid] != TEAM_VAGOS)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Vagos members can enter this vehicle!");
	                return 1;
	            }
	        }
	        else if(CarCheck == Cars[Rifa])
	        {
	            if(gTeam[playerid] != TEAM_RIFA)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Rifa members can enter this vehicle!");
	                return 1;
	            }
	        }
			return 1;
        }
   	}
    return 1;
}
Код HTML:
	Cars[Grove] = CreateVehicle(566,2505.5374,-1679.1711,13.2399,318.4229,137,137,900); // GroveCar1
	Cars[Grove] = CreateVehicle(534,2501.8450,-1655.5796,13.1842,64.4578,137,137,30); // GroveCar2
	Cars[Grove] = CreateVehicle(567,2473.1482,-1692.2168,13.3855,359.5531,137,1,30); // GroveCar3
	Cars[Grove] = CreateVehicle(560,2468.8552,-1653.2006,13.1075,91.6074,137,137,30); // GroveCar4
	Cars[Grove] = CreateVehicle(549,2468.5483,-1670.8950,13.0936,9.6306,16,191,30); // GroveCar5
	Cars[Grove] = CreateVehicle(482,2479.6206,-1747.2933,13.6672,0.1330,137,137,30); // GroveCar6
	Cars[Ballas] = CreateVehicle(560,2186.6372,-1664.1183,14.4850,167.9805,179,179,30); // BallasCar1
	Cars[Ballas] = CreateVehicle(405,2180.9707,-1695.8414,13.5073,355.4989,179,179,30); // BallasCar2
	Cars[Ballas] = CreateVehicle(492,2179.8796,-1633.0276,14.7230,75.5031,179,242,30); // BallasCar3
	Cars[Ballas] = CreateVehicle(562,2230.5303,-1669.5588,14.6620,347.1230,179,179,30); // BallasCar4
	Cars[Ballas] = CreateVehicle(542,2172.0669,-1726.8837,13.2831,267.4980,179,179,30); // BallasCar5
	Cars[Ballas] = CreateVehicle(533,2223.2341,-1708.8572,13.2288,174.7177,179,1,30); // BallasCar6
	Cars[Vagos] = CreateVehicle(474,2796.3516,-1584.9945,10.6900,269.3987,6,228,30); // VagosCar1
	Cars[Vagos] = CreateVehicle(419,2802.8359,-1540.2955,10.7194,181.8919,6,6,30); // VagosCar2
	Cars[Vagos] = CreateVehicle(576,2796.8464,-1571.5792,10.5361,271.7090,6,1,30); // VagosCar3
	Cars[Vagos] = CreateVehicle(575,2821.9460,-1557.8423,10.5277,89.5763,6,126,30); // VagosCar4
	Cars[Vagos] = CreateVehicle(475,2851.3184,-1555.0378,10.8089,162.4337,6,5,30); // VagosCar5
	Cars[Vagos] = CreateVehicle(560,2796.2771,-1558.6921,10.6268,90.6884,6,6,30); // VagosCar6
	Cars[Rifa] = CreateVehicle(474,2656.1956,-2009.3064,13.2271,268.6646,135,1,30); // RifaCar1
	Cars[Rifa] = CreateVehicle(567,2644.8674,-2032.7892,13.4145,0.5363,135,1,30); // RifaCar2
	Cars[Rifa] = CreateVehicle(560,2684.7190,-1990.5293,13.2595,181.0272,135,1,30); // RifaCar3
	Cars[Rifa] = CreateVehicle(482,2764.7307,-2007.2057,13.6727,0.3411,135,1,30); // RifaCar4
	Cars[Rifa] = CreateVehicle(527,2788.3364,-1989.4805,13.1794,86.1457,135,1,30); // RifaCar5
	Cars[Rifa] = CreateVehicle(466,2786.8862,-1944.7605,13.2887,87.9375,135,1,30); // RifaCar6
I think I might know what I did wrong, because it only has 1 place to store the car it only stores the latest cars, e.g. RifeCar6, VagosCar6... Not sure how to fix this. Anyone?
Reply
#2

You need a bidimensional array for this.

new Cars[TeamCars][10];

Now you have 10 cars for each faction, increase the 10 as needed.
Reply
#3

Quote:
Originally Posted by CuervO
Посмотреть сообщение
You need a bidimensional array for this.

new Cars[TeamCars][10];

Now you have 10 cars for each faction, increase the 10 as needed.
And then use

Cars[Grove][1] = CreateVehicle(566,2505.5374,-1679.1711,13.2399,318.4229,137,137,900); // GroveCar1
Cars[Grove][2] = CreateVehicle(534,2501.8450,-1655.5796,13.1842,64.4578,137,137,30); // GroveCar2

?
Reply
#4

indeed, they begin from zero though
Reply
#5

It doesn't seem to work the way I tried it.. Ballas members cannot enter Grovestreet cars, but they can access Vagos cars... Rifa members can't enter their own cars cause it says only Ballas can enter it?

Changed it, so that they start from 0 too,

Код HTML:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if (AdminDuty[playerid] == 0)
	{
		if(newstate == 2)
	    {
	        new CarCheck = GetPlayerVehicleID(playerid);
	        if(CarCheck == Cars[Grove][1] || CarCheck == Cars[Grove][2] || CarCheck == Cars[Grove][3] || CarCheck == Cars[Grove][4] || CarCheck == Cars[Grove][5] || CarCheck == Cars[Grove][6])
	        {
	            if(gTeam[playerid] != TEAM_GROVE)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Grovestreet members can enter this vehicle!");
	                return 1;
	            }
	        }
	        else if(CarCheck == Cars[Ballas][1] || Cars[Ballas][2] || Cars[Ballas][3] || Cars[Ballas][4] || Cars[Ballas][5] || Cars[Ballas][6])
	        {
	            if(gTeam[playerid] != TEAM_BALLAS)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Ballas members can enter this vehicle!");
	                return 1;
	            }
	        }
	        else if(CarCheck == Cars[Vagos][1] || Cars[Vagos][2] || Cars[Vagos][3] || Cars[Vagos][4] || Cars[Vagos][5] || Cars[Vagos][6])
	        {
	            if(gTeam[playerid] != TEAM_VAGOS)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Vagos members can enter this vehicle!");
	                return 1;
	            }
	        }
	        else if(CarCheck == Cars[Rifa][1] || Cars[Rifa][2] || Cars[Rifa][3] || Cars[Rifa][4] || Cars[Rifa][5] || Cars[Rifa][6])
	        {
	            if(gTeam[playerid] != TEAM_RIFA)
	            {
	                RemovePlayerFromVehicle(playerid);
	                SendClientMessage(playerid, COLOR_RED, "Only Rifa members can enter this vehicle!");
	                return 1;
	            }
	        }
			return 1;
        }
   	}
    return 1;
}
Reply
#6

it has to do with the way you do your checks... Cant really show you because im in the phone. Check my сatest replies, i solved tye very same thing a few hours ago, but basically you cant do
Код:
var == 1 || 2 || 3
you must do var == 1 || var == 2 ... Etc
Reply
#7

Quote:
Originally Posted by CuervO
Посмотреть сообщение
it has to do with the way you do your checks... Cant really show you because im in the phone. Check my сatest replies, i solved tye very same thing a few hours ago
Could you give me a hint where it goes wrong?

And I'm looking through your latest posts but not sure which post you mean :3
Reply
#8

edited my last reply
Reply
#9

-whoops double post-
Reply
#10

Quote:
Originally Posted by CuervO
Посмотреть сообщение
it has to do with the way you do your checks... Cant really show you because im in the phone. Check my сatest replies, i solved tye very same thing a few hours ago, but basically you cant do
Код:
var == 1 || 2 || 3
you must do var == 1 || var == 2 ... Etc
Just noticed it as you replied, seeing that one line was longer..
Seems like I only did Grovestreet right and messed up the rest

What would be the best way to make this shorter:

Код HTML:
else if(CarCheck == Cars[Rifa][0] || CarCheck == Cars[Rifa][1] || CarCheck == Cars[Rifa][2] || CarCheck == Cars[Rifa][3] || CarCheck == Cars[Rifa][4] || CarCheck == Cars[Rifa][5])
Like Cars[Rifa][0...10] or something?

Gonna try out if it works now.

EDIT: It works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)