Skip to content

Commit fe30cc8

Browse files
committed
Add documentation for NPC_SetAngleToPlayer and NPC_SetAngleToPos functions
1 parent 546f156 commit fe30cc8

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: NPC_SetAngleToPlayer
3+
sidebar_label: NPC_SetAngleToPlayer
4+
description: Rotates an NPC to face a specific player.
5+
tags: ["npc", "angle", "player"]
6+
---
7+
8+
<VersionWarn version='omp v1.1.0.changemelater' />
9+
10+
## Description
11+
12+
Rotates an NPC to face a specific player by using the player's current position.
13+
14+
| Name | Description |
15+
| -------- | ----------- |
16+
| npcid | The ID of the NPC. |
17+
| playerid | The ID of the player that the NPC should face. |
18+
19+
## Returns
20+
21+
Returns `true` if the NPC was rotated successfully, `false` otherwise.
22+
23+
## Examples
24+
25+
```c
26+
public OnPlayerCommandText(playerid, cmdtext[])
27+
{
28+
if (!strcmp(cmdtext, "/lookatme", true))
29+
{
30+
new npcid = PlayerNPC[playerid];
31+
if (npcid == INVALID_NPC_ID)
32+
return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC.");
33+
34+
if (!NPC_IsValid(npcid))
35+
return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC.");
36+
37+
if (!IsPlayerConnected(playerid))
38+
return SendClientMessage(playerid, 0xFF0000FF, "Invalid player.");
39+
40+
NPC_SetAngleToPlayer(npcid, playerid);
41+
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now facing you.", npcid);
42+
return 1;
43+
}
44+
return 0;
45+
}
46+
```
47+
48+
## Notes
49+
50+
:::warning
51+
52+
- This function performs a single rotation; call it again to keep the NPC facing a moving player.
53+
- The player must be connected, otherwise the NPC will not rotate.
54+
- Internally uses [NPC_SetAngleToPos](NPC_SetAngleToPos) with the player's current position.
55+
56+
:::
57+
58+
## Related Functions
59+
60+
- [NPC_SetAngleToPos](NPC_SetAngleToPos): Face a specific position.
61+
- [NPC_SetFacingAngle](NPC_SetFacingAngle): Set a numeric angle.
62+
- [NPC_GetFacingAngle](NPC_GetFacingAngle): Get the NPC's facing angle.
63+
- [NPC_MoveToPlayer](NPC_MoveToPlayer): Move the NPC toward a player.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: NPC_SetAngleToPos
3+
sidebar_label: NPC_SetAngleToPos
4+
description: Rotates an NPC so it faces a specific world position.
5+
tags: ["npc", "angle", "position"]
6+
---
7+
8+
<VersionWarn version='omp v1.1.0.changemelater' />
9+
10+
## Description
11+
12+
Rotates an NPC so it faces a specific world position.
13+
14+
| Name | Description |
15+
| ------ | ----------- |
16+
| npcid | The ID of the NPC. |
17+
| Float:x | X coordinate of the target position. |
18+
| Float:y | Y coordinate of the target position. |
19+
| Float:z | Z coordinate of the target position. |
20+
21+
## Returns
22+
23+
Returns `true` if the NPC was rotated successfully, `false` otherwise.
24+
25+
## Examples
26+
27+
```c
28+
public OnPlayerCommandText(playerid, cmdtext[])
29+
{
30+
if (!strcmp(cmdtext, "/lookatpos", true))
31+
{
32+
new npcid = PlayerNPC[playerid];
33+
if (npcid == INVALID_NPC_ID)
34+
return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC.");
35+
36+
if (!NPC_IsValid(npcid))
37+
return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC.");
38+
39+
new Float:x, Float:y, Float:z;
40+
GetPlayerPos(playerid, x, y, z);
41+
42+
NPC_SetAngleToPos(npcid, x + 3.0, y, z);
43+
SendClientMessage(playerid, 0x00FF00FF, "NPC %d now faces %.2f, %.2f, %.2f", npcid, x + 3.0, y, z);
44+
return 1;
45+
}
46+
return 0;
47+
}
48+
```
49+
50+
## Notes
51+
52+
:::warning
53+
54+
- Only the horizontal plane (X/Y) is considered when calculating the facing angle.
55+
- The NPC will not move; it only rotates to face the position.
56+
57+
:::
58+
59+
## Related Functions
60+
61+
- [NPC_SetFacingAngle](NPC_SetFacingAngle): Set an exact angle value.
62+
- [NPC_SetAngleToPlayer](NPC_SetAngleToPlayer): Face a player automatically.
63+
- [NPC_GetFacingAngle](NPC_GetFacingAngle): Get the NPC's current facing.
64+
- [NPC_Move](NPC_Move): Move the NPC toward a position.

0 commit comments

Comments
 (0)