---
title: "NPC_SetVehicleTrainSpeed | open.mp"
description: "Sets the speed of an NPC's train vehicle."
canonical: https://omp.itsneufox.com/docs/scripting/functions/NPC_SetVehicleTrainSpeed
language: en
---

# NPC\_SetVehicleTrainSpeed

warning

This function was added in omp v1.5.8.3079 and will not work in earlier versions!

## Description

Sets the speed of an NPC's train vehicle.

| Name | Description |
| --- | --- |
| npcid | The ID of the NPC |
| speed | The train speed to set |

## Returns

Returns `true` if the operation was successful, `false` otherwise.

## Examples

```c
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/settrainspeed ", true, 15))
    {
        new npcid = PlayerNPC[playerid];
        if (npcid == INVALID_NPC_ID)
            return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC.");

        if (!NPC_IsValid(npcid))
            return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC.");

        new Float:speed = floatstr(cmdtext[15]);

        NPC_SetVehicleTrainSpeed(npcid, speed);
        SendClientMessage(playerid, 0x00FF00FF, "NPC %d train speed set to %.2f", npcid, speed);

        return 1;
    }
    return 0;
}
```

## Notes

-   Only works with train vehicles (models 537, 538)
-   Use NPC\_GetVehicleTrainSpeed to check current speed
-   Setting speed to 0 stops the train

## Related Functions

-   [NPC\_GetVehicleTrainSpeed](https://omp.itsneufox.com/docs/scripting/functions/NPC_GetVehicleTrainSpeed): Get train speed
-   [NPC\_GetVehicleID](https://omp.itsneufox.com/docs/scripting/functions/NPC_GetVehicleID): Get NPC's vehicle
-   [NPC\_PutInVehicle](https://omp.itsneufox.com/docs/scripting/functions/NPC_PutInVehicle): Put NPC in vehicle
-   [GetVehicleModel](https://omp.itsneufox.com/docs/scripting/functions/GetVehicleModel): Get vehicle model

## Related Callbacks

_No specific callbacks are triggered by this function._
