---
title: "GetObjectMaterial | open.mp"
description: "从物体的材质索引获取材质数据"
canonical: https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetObjectMaterial
language: zh-CN
---

# GetObjectMaterial

注意

这个函数是在omp v1.1.0.2612中添加的，在以前的版本中不起作用！

## 描述

从物体的材质索引获取材质数据。

| 参数 | 说明 |
| --- | --- |
| objectid | 物体 ID |
| materialIndex | 物体的材质索引 (0 至 15) |
| &modelid | 存储模型 ID 的变量，通过引用传递 |
| textureLibrary\[\] | 存储纹理库名称的数组，通过引用传递 |
| textureLibrarySize | 纹理库数组的尺寸 |
| textureName\[\] | 存储纹理名称的数组，通过引用传递 |
| textureNameSize | 纹理名称数组的尺寸 |
| &materialColour | 存储材质颜色的变量，通过引用传递 |

## 返回值

`true` - 函数执行成功

`false` - 函数执行失败（指定物体不存在或使用无效的材质索引）

## 示例代码

```c
new objectid = CreateObject(19371, 978.71143, -925.25708, 42.63720,   0.00000, 0.00000, 2.00000);
SetObjectMaterial(objectid, 0, 19341, "egg_texts", "easter_egg01", 0xFFFFFFFF);

new
    modelid,
    textureLibrary[16],
    textureName[16],
    materialColour;

GetObjectMaterial(objectid, 0, modelid, textureLibrary, sizeof(textureLibrary), textureName, sizeof(textureName), materialColour);
// modelid = 19341
// textureLibrary = "egg_texts"
// textureName = "easter_egg01"
// materialColour = 0xFFFFFFFF
```

## 相关函数

-   [SetObjectMaterial](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/SetObjectMaterial): 用游戏中其他模型的纹理替换物体的材质
-   [SetObjectMaterialText](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/SetObjectMaterialText): 使用文本替换物体的材质纹理
-   [IsObjectMaterialSlotUsed](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/IsObjectMaterialSlotUsed): 检查物体材质槽位是否被使用
-   [GetObjectMaterialText](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetObjectMaterialText): 从物体的材质索引获取文本材质数据
-   [GetPlayerObjectMaterial](https://omp.itsneufox.com/zh-CN/docs/scripting/functions/GetPlayerObjectMaterial): 从玩家物体的材质索引获取材质数据
