> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-traffic-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gley.gitbook.io/mobile-traffic-system/complete-api/adddrivingaction.md).

# AddDrivingAction

### Description

Add an external driving action to a traffic vehicle to customize its behavior. The added action will be added inside the vehicle's actions queue and executed accordingly.

The complete list of actions is available here: [DriveActions](/mobile-traffic-system/complete-api/driveactions.md)

### Declaration&#x20;

```csharp
public static void AddDrivingAction(int vehicleIndex, DriveActions action, bool force)
```

### Parameters

<table><thead><tr><th width="188">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>vehicleIndex</strong></td><td>Index of the excluded vehicle.</td></tr><tr><td><strong>action</strong></td><td>The <a data-mention href="/mobile-traffic-system/complete-api/driveactions.md">DriveActions</a>action to be added.</td></tr><tr><td><strong>force</strong></td><td>If true, all the preexisting actions for that vehicle will be cleared and just the current one will be added.</td></tr></tbody></table>

### Example

```csharp
using Gley.TrafficSystem;
using UnityEngine;
public class Test : MonoBehaviour
{
    //a reference to vehicle pool and player assigned in inspector
    public VehiclePool vehiclePool;
    public Transform player;

    void Start()
    {
        API.Initialize(player, 20, vehiclePool);
    }

    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Alpha1))
        {
            //If 1 is pressed the vehicle will stop.
            API.AddDrivingAction(0, DriveActions.Stop, true);
        }

        if(Input.GetKeyDown(KeyCode.Alpha2))
        {
            //If 2 is pressed the vehicle will continue its previous behavior.
            API.RemoveDrivingAction(0, DriveActions.Stop);
        }
    }
}

```
