Multiple vehicles in 1 variable
#1

Hi guys.
Is it possible to make multiple vehicles in 1 variable?
i did like this, but it doesnt work:
pawn Код:
new truck = {
AddStaticVehicle(403,1697.2108,1057.6760,11.4450,180.6527,25,1), // Truck1
AddStaticVehicle(514,1692.2650,1056.6304,11.4086,180.6328,36,1), // Truck2
AddStaticVehicle(514,1687.1963,1056.7150,11.4078,179.3409,113,1), // Truck3
AddStaticVehicle(403,1671.1423,1085.4607,11.4273,180.2388,30,1), // Truck4
AddStaticVehicle(514,1665.7838,1084.3821,11.4078,180.4213,25,1), // Truck5
AddStaticVehicle(515,1659.8749,1084.6716,11.8436,179.6213,54,77), // Truck6
AddStaticVehicle(403,1631.0760,1057.6670,11.4274,269.9039,36,1), // Truck7
AddStaticVehicle(515,1631.3705,1051.0710,11.8374,270.0173,11,76), // Truck8
AddStaticVehicle(515,1631.9513,1025.4581,11.8431,268.3826,13,76) // Truck9
};
Hope someone can help me. Thanks.
Reply
#2

use Array
Reply
#3

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
Hi guys.
Is it possible to make multiple vehicles in 1 variable?
i did like this, but it doesnt work:
pawn Код:
new truck = {
AddStaticVehicle(403,1697.2108,1057.6760,11.4450,180.6527,25,1), // Truck1
AddStaticVehicle(514,1692.2650,1056.6304,11.4086,180.6328,36,1), // Truck2
AddStaticVehicle(514,1687.1963,1056.7150,11.4078,179.3409,113,1), // Truck3
AddStaticVehicle(403,1671.1423,1085.4607,11.4273,180.2388,30,1), // Truck4
AddStaticVehicle(514,1665.7838,1084.3821,11.4078,180.4213,25,1), // Truck5
AddStaticVehicle(515,1659.8749,1084.6716,11.8436,179.6213,54,77), // Truck6
AddStaticVehicle(403,1631.0760,1057.6670,11.4274,269.9039,36,1), // Truck7
AddStaticVehicle(515,1631.3705,1051.0710,11.8374,270.0173,11,76), // Truck8
AddStaticVehicle(515,1631.9513,1025.4581,11.8431,268.3826,13,76) // Truck9
};
Hope someone can help me. Thanks.
pawn Код:
new Vehicle[10];

Vehicle[0] = AddStaticVehicle(whatever you wish);
Vehicle[1] = AddStaticVehicle(whatever you wish);
Vehicle[2] = AddStaticVehicle(whatever you wish);
//Ect...
Reply
#4

Quote:
Originally Posted by Stigg
Посмотреть сообщение
pawn Код:
new Vehicle[10]

Vehicle[0] = AddStaticVehicle(whatever you wish);
Vehicle[1] = AddStaticVehicle(whatever you wish);
Vehicle[2] = AddStaticVehicle(whatever you wish);
//Ect...
A semi-colon is required after 'Vehicle[10]', so:

pawn Код:
new Vehicle[10];
Note, you can change 10 to the amount of vehicles you plan to create.
Reply
#5

Thank you. But if i want, lets say, 15 vehicles in the same variable, then i have to make array 15 cells big?
like "new truck[15];"??
Reply
#6

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
Thank you. But if i want, lets say, 15 vehicles in the same variable, then i have to make array 15 cells big?
like "new truck[15];"??
yeah
Reply
#7

Ok. Now i did that. But when im doing like this:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(pJob[playerid][trucker] == 0)
    {
        if(vehicleid == truck)
        {
            SendClientMessage(playerid, COLOR_NORMALRED, "( ! ) Only Truckers can use this vehicle!");
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
it gives me this error:
Код:
C:\Users\Simon\Desktop\Untitled.pwn(129) : error 017: undefined symbol "truck"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#8

How do i refer to all of them in the "if(vehicleid == truck)"??
Reply
#9

Make a loop:
pawn Код:
for(new i = 0; i < sizeof(truck); ++i)
{
    if(vehicleid == i)
    {
        // Code
    }
}
Reply
#10

Quote:
Originally Posted by [L3th4l]
Посмотреть сообщение
Make a loop:
pawn Код:
for(new i = 0; i < sizeof(truck); ++i)
{
    if(vehicleid == i)
    {
        // Code
    }
}
yeah that would be the best way to do it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)