Vehicles
#1

Hi,

How do i put vehicles to interior with playerid to be visible

I have like this

Код:
Event[0] = AddStaticVehicleEx(532, -5488.4324, 950.3213, 1036.5260, 322.9614, -1, -1, 100);
	Event[1] = AddStaticVehicleEx(532, -5512.9443, 973.5475, 1037.0670, 102.1026, -1, -1, 100);
x10 vehicles
Reply
#2

LinkVehicleToInterior
Reply
#3

But if i have more vehicle example 30 how i can do something instead of repeating

LinkVehicleToInterior(vehicle1, 6);
LinkVehicleToInterior(vehicle2, 6);
LinkVehicleToInterior(vehicle3, 6);

etc...
Reply
#4

Well, you have 3 options.

Create a loop.
Create a loop after all vehicles have been created, and link the vehicles in the array 'Event' to a certain interior.
PHP код:
    Event[0] = AddStaticVehicleEx(...
    
Event[1] = AddStaticVehicleEx(...
    
// ...
    
Event[29] = AddStaticVehicleEx(...
    for(new 
0!= sizeof(Event); i++)
    {
        if(
Event[i] != 0// if the vehicle was created and has a value
        
{
            
LinkVehicleToInterior(Event[i], 5); // This will link the vehicle to interior 5.
        
}
    } 
Assign the vehicle IDs to a variable as you go.
This involves creating a new variable before you create the vehicle, and it assigns the vehicle IDs to the variable as you go.
PHP код:
    new vehicle_id 0;
    
Event[0] = vehicle_id AddStaticVehicleEx(...
    
LinkVehicleToInterior(vehicle_id5); // This will link the vehicle to interior 5.
    
Event[1] = vehicle_id AddStaticVehicleEx(...
    
LinkVehicleToInterior(vehicle_id5);
    
// ...
    
Event[29] = vehicle_id AddStaticVehicleEx(...
    
LinkVehicleToInterior(vehicle_id5); 
Note that you don't NEED to create a new variable for this. You can always replace 'vehicle_id' with Event[0], Event[1] etc., but from this post, I gather this is exactly what you're trying to avoid.

Combine the second method by using 1 line.
This basically combines the second method into one line without the use of a variable. As AddStaticVehicleEx returns the created vehicle ID, there's no real need for a variable, you can simply plug and play with a function such as LinkVehicleToInterior.
PHP код:
    LinkVehicleToInterior((Event[0] = AddStaticVehicleEx(...)), 5); // This will link the vehicle to interior 5.
    
LinkVehicleToInterior((Event[1] = AddStaticVehicleEx(...)), 5);
    
// ...
    
LinkVehicleToInterior((Event[20] = AddStaticVehicleEx(...)), 5); 
The easiest method to understand would be the second method. The first method is the most preferred and widely used version, and saves a lot of time in scripting but isn't necessarily the most efficient. I would personally use the third method, as it saves having to use unnecessary variables and lines. (Though there's nothing wrong with having more lines to achieve a neat code, it's merely personal preference)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)