---
title: "SetPlayerWeather | open.mp"
description: "设置玩家的天气。"
canonical: https://omp.itsneufox.com/zh-CN/docs/scripting/functions/SetPlayerWeather
language: zh-CN
---

# SetPlayerWeather

## 描述

设置玩家的天气。

| 参数 | 说明 |
| --- | --- |
| playerid | 要设置天气的玩家 ID |
| weather | 要设置的[天气](https://omp.itsneufox.com/zh-CN/docs/scripting/resources/weatherid) |

## 返回值

此函数不返回特定值。

## 示例

```c
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp(cmdtext, "/storm", true))
    {
        SetPlayerWeather(playerid, 8);
        return 1;
    }
    return 0;
}
```

## 注意

备注

-   若已启用[TogglePlayerClock](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/TogglePlayerClock)，天气会逐渐变化而非立即切换
-   游戏实际仅有 21 个有效天气 ID（0-20），但系统不会进行范围校验

## 相关函数

-   [GetPlayerWeather](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetPlayerWeather): 获取玩家的天气
-   [SetWeather](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/SetWeather): 设置全局天气
-   [SetGravity](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/SetGravity): 设置全局重力

## 相关资源

-   [天气 ID 列表](https://omp.itsneufox.com/zh-CN/docs/scripting/resources/weatherid)
