NPC Constants
This page lists all constants specific to NPC functions in open.mp.
Limits
| Value | Constant | Description |
|---|---|---|
| 1000 | MAX_NPCS | Maximum number of NPCs |
| 64 | NPC_MAX_NODES | Maximum number of nodes |
Invalid Constants
| Value | Constant | Description |
|---|---|---|
| -1 | INVALID_NPC_ID | Invalid NPC ID |
| -1 | INVALID_PATH_ID | Invalid path ID |
| -1 | INVALID_NODE_ID | Invalid node ID |
| -1 | INVALID_RECORD_ID | Invalid recording ID |
Movement Types
Used by functions like NPC_Move, NPC_MoveByPath, NPC_EnterVehicle, and NPC_PlayNode.
| Value | Constant | Description |
|---|---|---|
| -1 | UNKNOWN_NPC_MOVE_TYPE | Unknown movement type |
| 0 | NPC_MOVE_TYPE_NONE | No movement |
| 1 | NPC_MOVE_TYPE_WALK | NPC walks to destination |
| 2 | NPC_MOVE_TYPE_JOG | NPC jogs to destination (default for most functions) |
| 3 | NPC_MOVE_TYPE_SPRINT | NPC sprints to destination |
| 4 | NPC_MOVE_TYPE_DRIVE | NPC drives to destination (vehicle movement) |
| 5 | NPC_MOVE_TYPE_AUTO | Automatic movement type |
Movement Speed
Used by movement functions to control NPC speed.
| Value | Constant | Description |
|---|---|---|
| -1.0 | NPC_MOVE_SPEED_AUTO | Automatic speed based on movement type |
| 0.1552086 | NPC_MOVE_SPEED_WALK | Walking speed |
| 0.56444 | NPC_MOVE_SPEED_JOG | Jogging speed |
| 0.926784 | NPC_MOVE_SPEED_SPRINT | Sprinting speed |
Entity Check Flags
Used by NPC_AimAt, NPC_AimAtPlayer, and NPC_Shoot for collision detection.
| Value | Constant | Description |
|---|---|---|
| 0 | NPC_ENTITY_CHECK_NONE | No collision checking |
| 1 | NPC_ENTITY_CHECK_PLAYER | Check collisions with players |
| 2 | NPC_ENTITY_CHECK_NPC | Check collisions with NPCs |
| 4 | NPC_ENTITY_CHECK_ACTOR | Check collisions with actors |
| 8 | NPC_ENTITY_CHECK_VEHICLE | Check collisions with vehicles |
| 16 | NPC_ENTITY_CHECK_OBJECT | Check collisions with objects |
| 32 | NPC_ENTITY_CHECK_POBJECT_ORIG | Check collisions with player objects (original) |
| 64 | NPC_ENTITY_CHECK_POBJECT_TARG | Check collisions with player objects (target) |
| 128 | NPC_ENTITY_CHECK_MAP | Check collisions with map |
| 255 | NPC_ENTITY_CHECK_ALL | Check collisions with all entities |
Bullet Hit Types
Used by NPC_Shoot to specify what type of target is being hit.
| Constant | Description |
|---|---|
| BULLET_HIT_TYPE_NONE | No specific target |
| BULLET_HIT_TYPE_PLAYER | Player target |
Examples
Movement Types
// Make NPC walk slowly
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_WALK);
// Make NPC jog (default speed)
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_JOG);
// Make NPC sprint quickly
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_SPRINT);
// Make NPC drive to location
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_DRIVE);
// Use automatic movement type
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_AUTO);
Movement Speed
// Use automatic speed
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_WALK, NPC_MOVE_SPEED_AUTO);
// Use specific walking speed
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_WALK, NPC_MOVE_SPEED_WALK);
// Use specific jogging speed
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_JOG, NPC_MOVE_SPEED_JOG);
// Use specific sprinting speed
NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_SPRINT, NPC_MOVE_SPEED_SPRINT);
Entity Check Flags
// Aim with no collision checking
NPC_AimAt(npcid, x, y, z, true, 1000, true, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_NONE);
// Aim with full collision checking
NPC_AimAt(npcid, x, y, z, true, 1000, true, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_ALL);
// Only check collisions with players
NPC_AimAt(npcid, x, y, z, true, 1000, true, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER);
// Check collisions with players and vehicles
NPC_AimAt(npcid, x, y, z, true, 1000, true, 0.0, 0.0, 0.6,
NPC_ENTITY_CHECK_PLAYER | NPC_ENTITY_CHECK_VEHICLE);
// Check collisions with objects only
NPC_AimAt(npcid, x, y, z, true, 1000, true, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_OBJECT);
Bullet Hit Types
// Shoot at a specific location (no target)
NPC_Shoot(npcid, INVALID_PLAYER_ID, BULLET_HIT_TYPE_NONE, WEAPON_SNIPER,
x, y, z, 0.0, 0.0, 0.0, false);
// Shoot at a player
NPC_Shoot(npcid, playerid, BULLET_HIT_TYPE_PLAYER, WEAPON_M4,
x, y, z, 0.0, 0.0, 0.0, true);
Invalid Constants
// Check if NPC ID is valid
new npcid = NPC_Create("Bot");
if (npcid != INVALID_NPC_ID)
{
// NPC was created successfully
NPC_Spawn(npcid);
}
// Check if path ID is valid
new pathid = NPC_CreatePath();
if (pathid != INVALID_PATH_ID)
{
// Path was created successfully
NPC_AddPointToPath(pathid, 0.0, 0.0, 3.0, 0.2);
}
// Check for invalid player in NPC_Kill
NPC_Kill(npcid, INVALID_PLAYER_ID, REASON_SUICIDE);
Limits
// Loop through all possible NPCs
for (new i = 0; i < MAX_NPCS; i++)
{
if (NPC_IsValid(i))
{
// Process valid NPC
}
}
// Example using NPC_MAX_NODES
for (new i = 0; i < NPC_MAX_NODES; i++)
{
if (NPC_IsNodeOpen(i))
{
// Process open node
NPC_CloseNode(i);
}
}
Related Pages
- Weapon Constants - For weapon IDs used with NPCs
- Player States - For player state constants that may apply to NPCs
- Vehicle IDs - For vehicle model IDs used in NPC vehicle functions