Skip to content

Commit a668c4a

Browse files
AmyrAhmadyedgyafdockfries
authored
NPC Component Documentation (#1137)
* NPC Callbacks * Wrong bold format * Mark ConnectNPC function as deprecated * One Big Beautiful Commit for NPCs * - begone magic numbers (thx TommyB) - better comments in some things * Add npc-constants.md * remove nonexisting npc callbacks * grammatical changes, example fixes, content changes * NPC node docs * add GetVehicleRotation * Remove reference to non-existing NPC callback in NPC_SetRot documentation * Remove references to non-existing NPC callbacks in NPC_SetFacingAngle and NPC_SetSpecialAction documentation * Remove references to non-existing NPC callbacks in various documentation files * Remove references to non-existing NPC callbacks in NPC_IsStreamedIn and NPC_SetSkin documentation thanks eggy * Fix param names and other small stuff * Remove note about NPC pathfinding * NPC gear docs were more confused than a pilot trying to land without landing gear * - Teach NPCs that INVALID_VEHICLE_ID exists - Add correct seat maps * streamline example code for path creation * add INVALID_OBJECT_ID to object related functions * Update NPC_GetVehicle and NPC_GetVehicleID documentation and example code * add INVALID_RECORD_ID * mistake 🔏 * Add section for invalid constants, including INVALID_RECORD_ID * General NPC docs improvements * Add documentation for Path Nodes * fix npc related callbacks and functions * fix GetVehicleRotation related link GetVehicleRotationQuat * fix npc_isValid, remove related OnNPCConnect/Disconnect * maybe fix npc recording path * npc and more docs prettier format * replace OnNPCEnterVehicle with OnPlayerEnterVehicle * deprecate or delete the following files? * Make better snippets, fix some of the texts * get all npcs, npc destroy, paths and enter/exit vehicles * GetAmmo, GetAmmoInClip, GetAnimation, GetArmour * GetArmout and GetCurrentPathPointIndex * fix some stuff and add more documentation * fix some issues * add GetRot, GetSpecialAction, GetSurfingObject, GetSurfingOffsets, GetSurfingPlayerObject, GetSurfingVehicle, GetVehicle, GetVehicleGearState * update Related Functions * removed: NPC_SetSurfingOffset.md added: NPC_SetSurfingOffsets.md NPC_IsMovingToPlayer.md NPC_IsSpawned.md NPC_SetWeaponSkillLevel.md NPC_GetPlayerAimingAt.md NPC_GetPlayerMovingTo.md NPC_GetSkin.md NPC_GetVelocity.md NPC_GetWeaponSkillLevel.md NPC_Kill.md NPC_SetVelocity.md NPC_SetWeaponState.md OnNPCFinishMovePathPoint.md * finish all Get funcs * going thru some more documentation * almost there!!! * fix mixed up examples * all funcs done * That's all Folks! * forgor this file too * fix some stuff i found while re-reading the docs * NPC_GetCustomSkin.md * NPC_GetPosMovingTo.md * improve fcnpc warnings, add missing frontmatter and also fix the linux guide * wtf moment * Add documentation for NPC_SetAngleToPlayer and NPC_SetAngleToPos functions --------- Co-authored-by: iAmir <[email protected]> Co-authored-by: edgy <[email protected]> Co-authored-by: dockfries <[email protected]>
2 parents f95d8cd + fe30cc8 commit a668c4a

File tree

487 files changed

+12761
-888
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

487 files changed

+12761
-888
lines changed

frontend/docs/scripting/callbacks/OnClientMessage.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ description: This callback gets called whenever the NPC sees a ClientMessage.
55
tags: []
66
---
77

8+
:::warning
9+
10+
This callback is deprecated.
11+
12+
:::
13+
814
## Description
915

1016
This callback gets called whenever the NPC sees a ClientMessage. This will be everytime a [SendClientMessageToAll](../functions/SendClientMessageToAll) function is used and everytime a [SendClientMessage](../functions/SendClientMessage) function is sent towards the NPC. This callback won't be called when someone says something. For a version of this with player text, see [NPC:OnPlayerText](OnPlayerText).
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: OnNPCChangeNode
3+
sidebar_label: OnNPCChangeNode
4+
description: This callback is called when an NPC attempts to change from one navigation node to another during node-based movement.
5+
tags: ["npc", "node", "navigation"]
6+
---
7+
8+
<VersionWarn version='omp v1.1.0.changemelater' />
9+
10+
## Description
11+
12+
This callback is called when an NPC attempts to change from one navigation node to another during node-based movement. This allows you to control whether the node change should be allowed or denied.
13+
14+
| Name | Description |
15+
| --------- | ----------------------------------------------- |
16+
| npcid | The ID of the NPC attempting to change nodes |
17+
| newnodeid | The ID of the new node the NPC wants to move to |
18+
| oldnodeid | The ID of the current node the NPC is on |
19+
20+
## Returns
21+
22+
Return `true` to allow the node change, or `false` to deny it.
23+
24+
## Examples
25+
26+
```c
27+
public OnNPCChangeNode(npcid, newnodeid, oldnodeid)
28+
{
29+
printf("[NPC] NPC %d changed from node %d to node %d", npcid, oldnodeid, newnodeid);
30+
31+
// Notify players tracking this NPC
32+
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
33+
{
34+
if (!IsPlayerConnected(playerid))
35+
continue;
36+
37+
if (PlayerNPC[playerid] == npcid)
38+
{
39+
SendClientMessage(playerid, 0x00FF00FF, "NPC %d changed from node %d to node %d", npcid, oldnodeid, newnodeid);
40+
}
41+
}
42+
return 1;
43+
}
44+
```
45+
46+
## Notes
47+
48+
- This callback is only called when NPCs are using node-based navigation via `NPC_PlayNode`
49+
- Returning `false` will prevent the NPC from changing nodes and may cause it to stop navigation
50+
- Node files must be loaded using `NPC_OpenNode` before NPCs can navigate between them
51+
52+
## Related Functions
53+
54+
The following functions might be useful, as they're related to this callback in one way or another.
55+
56+
- [NPC_PlayNode](../functions/NPC_PlayNode): Start NPC node-based navigation
57+
- [NPC_OpenNode](../functions/NPC_OpenNode): Open a navigation node file
58+
- [NPC_CloseNode](../functions/NPC_CloseNode): Close a navigation node file
59+
- [NPC_StopPlayingNode](../functions/NPC_StopPlayingNode): Stop NPC node navigation
60+
61+
## Related Callbacks
62+
63+
- [OnNPCFinishNode](OnNPCFinishNode): Called when NPC finishes navigating a complete node
64+
- [OnNPCFinishNodePoint](OnNPCFinishNodePoint): Called when NPC reaches a specific point in a node

frontend/docs/scripting/callbacks/OnNPCConnect.md

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: OnNPCCreate
3+
sidebar_label: OnNPCCreate
4+
description: This callback is called when an NPC is successfully created.
5+
tags: ["npc"]
6+
---
7+
8+
<VersionWarn version='omp v1.1.0.changemelater' />
9+
10+
## Description
11+
12+
This callback is called when an NPC is successfully created and added to the server.
13+
14+
| Name | Description |
15+
| ----- | ---------------------------------- |
16+
| npcid | The ID of the NPC that was created |
17+
18+
## Examples
19+
20+
```c
21+
public OnNPCCreate(npcid)
22+
{
23+
printf("[NPC] NPC %d has been created", npcid);
24+
25+
// Notify all connected players
26+
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
27+
{
28+
if (!IsPlayerConnected(playerid))
29+
continue;
30+
31+
SendClientMessage(playerid, 0x00FF00FF, "NPC %d has been created", npcid);
32+
}
33+
return 1;
34+
}
35+
```
36+
37+
## Notes
38+
39+
- This callback is called immediately after the NPC is created but before it's spawned
40+
- The NPC will need to be spawned using `NPC_Spawn` to become visible in the game world
41+
42+
## Related Functions
43+
44+
The following functions might be useful, as they're related to this callback in one way or another.
45+
46+
- [NPC_Create](../functions/NPC_Create): Create a new NPC
47+
- [NPC_Destroy](../functions/NPC_Destroy): Destroy an existing NPC
48+
- [NPC_Spawn](../functions/NPC_Spawn): Spawn the NPC in the game world
49+
50+
## Related Callbacks
51+
52+
- [OnNPCDestroy](OnNPCDestroy): Called when an NPC is destroyed
53+
- [OnNPCSpawn](OnNPCSpawn): Called when an NPC is spawned
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: OnNPCDeath
3+
sidebar_label: OnNPCDeath
4+
description: This callback is called when an NPC dies.
5+
tags: ["npc"]
6+
---
7+
8+
<VersionWarn version='omp v1.1.0.changemelater' />
9+
10+
## Description
11+
12+
This callback is called when an NPC dies.
13+
14+
| Name | Description |
15+
| -------- | --------------------------------------------------------------------------- |
16+
| npcid | The ID of the NPC that died |
17+
| killerid | The ID of the player/NPC that killed the NPC (or INVALID_PLAYER_ID if none) |
18+
| reason | The reason for death (weapon ID or death cause) |
19+
20+
## Examples
21+
22+
```c
23+
public OnNPCDeath(npcid, killerid, WEAPON:reason)
24+
{
25+
printf("[NPC] NPC %d died (killer: %d, weapon: %d)", npcid, killerid, _:reason);
26+
27+
// Notify players tracking this NPC
28+
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
29+
{
30+
if (!IsPlayerConnected(playerid))
31+
continue;
32+
33+
if (PlayerNPC[playerid] == npcid)
34+
{
35+
if (killerid == INVALID_PLAYER_ID)
36+
{
37+
SendClientMessage(playerid, 0xFF0000FF, "Your tracked NPC %d died (weapon: %d)", npcid, _:reason);
38+
}
39+
else
40+
{
41+
SendClientMessage(playerid, 0xFF0000FF, "Your tracked NPC %d was killed by player %d (weapon: %d)", npcid, killerid, _:reason);
42+
}
43+
}
44+
}
45+
return 1;
46+
}
47+
```
48+
49+
## Notes
50+
51+
- The `killerid` parameter will be `INVALID_PLAYER_ID` if the NPC death was not player inflicted
52+
- The `reason` parameter contains the weapon ID that caused the death (255 for unknown/other causes)
53+
54+
## Related Functions
55+
56+
The following functions might be useful, as they're related to this callback in one way or another.
57+
58+
- [NPC_Kill](../functions/NPC_Kill): Kill an NPC
59+
- [NPC_Respawn](../functions/NPC_Respawn): Respawn a dead NPC
60+
- [NPC_GetHealth](../functions/NPC_GetHealth): Get NPC's health
61+
- [NPC_SetHealth](../functions/NPC_SetHealth): Set NPC's health
62+
63+
## Related Callbacks
64+
65+
- [OnNPCSpawn](OnNPCSpawn): Called when an NPC spawns
66+
- [OnNPCRespawn](OnNPCRespawn): Called when an NPC respawns
67+
- [OnNPCTakeDamage](OnNPCTakeDamage): Called when an NPC takes damage
68+
- [OnPlayerDeath](OnPlayerDeath): Called when a player dies
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: OnNPCDestroy
3+
sidebar_label: OnNPCDestroy
4+
description: This callback is called when an NPC is destroyed.
5+
tags: ["npc"]
6+
---
7+
8+
<VersionWarn version='omp v1.1.0.changemelater' />
9+
10+
## Description
11+
12+
This callback is called when an NPC is destroyed and removed from the server.
13+
14+
| Name | Description |
15+
| ----- | ------------------------------------ |
16+
| npcid | The ID of the NPC that was destroyed |
17+
18+
## Examples
19+
20+
```c
21+
public OnNPCDestroy(npcid)
22+
{
23+
printf("[NPC] NPC %d has been destroyed", npcid);
24+
25+
// Clear any player tracking this NPC and notify
26+
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
27+
{
28+
if (!IsPlayerConnected(playerid))
29+
continue;
30+
31+
if (PlayerNPC[playerid] == npcid)
32+
{
33+
PlayerNPC[playerid] = INVALID_NPC_ID;
34+
SendClientMessage(playerid, 0xFF0000FF, "Your tracked NPC %d has been destroyed", npcid);
35+
}
36+
else
37+
{
38+
SendClientMessage(playerid, 0xFFFF00FF, "NPC %d has been destroyed", npcid);
39+
}
40+
}
41+
return 1;
42+
}
43+
44+
```
45+
46+
## Notes
47+
48+
- This callback is called immediately before the NPC is removed from the server
49+
- The NPC will be disconnected and its player slot freed after this callback
50+
51+
## Related Functions
52+
53+
The following functions might be useful, as they're related to this callback in one way or another.
54+
55+
- [NPC_Create](../functions/NPC_Create): Create a new NPC
56+
- [NPC_Destroy](../functions/NPC_Destroy): Destroy an existing NPC
57+
- [NPC_IsValid](../functions/NPC_IsValid): Check if NPC ID is valid
58+
59+
## Related Callbacks
60+
61+
- [OnNPCCreate](OnNPCCreate): Called when an NPC is created

frontend/docs/scripting/callbacks/OnNPCDisconnect.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

frontend/docs/scripting/callbacks/OnNPCEnterVehicle.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

frontend/docs/scripting/callbacks/OnNPCExitVehicle.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)