---
title: "OnPlayerStateChange | open.mp"
description: "This callback is called when a player changes state."
canonical: https://omp.itsneufox.com/th/docs/scripting/callbacks/OnPlayerStateChange
language: th
---

# OnPlayerStateChange

## คำอธิบาย

This callback is called when a player changes state. For example, when a player changes from being the driver of a vehicle to being on-foot.

| Name | Description |
| --- | --- |
| playerid | The ID of the player that changed state. |
| newstate | The player's new state. |
| oldstate | The player's previous state. |

Refer to [Player States](https://omp.itsneufox.com/th/docs/scripting/resources/playerstates) for a list of all available player states.

## ส่งคืน

มันถูกเรียกในฟิลเตอร์สคริปต์ก่อนเสมอ

## ตัวอย่าง

```c
public OnPlayerStateChange(playerid, PLAYER_STATE:newstate, PLAYER_STATE:oldstate)
{
    if (oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) // Player entered a vehicle as a driver
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        AddVehicleComponent(vehicleid, 1010); // Add NOS to the vehicle
    }
    return 1;
}
```

## บันทึก

หมายเหตุ

NPC สามารถเรียก Callback นี้ได้

## ฟังก์ชั่นที่เกี่ยวข้องกัน

-   [GetPlayerState](https://omp.itsneufox.com/th/docs/scripting/functions/GetPlayerState): Get a player's current state.
-   [GetPlayerSpecialAction](https://omp.itsneufox.com/th/docs/scripting/functions/GetPlayerSpecialAction): Get a player's current special action.
-   [SetPlayerSpecialAction](https://omp.itsneufox.com/th/docs/scripting/functions/SetPlayerSpecialAction): Set a player's special action.
