Preskoči na vsebino

NPC Constants

This page lists all constants specific to NPC functions in open.mp.

Limits

ValueConstantDescription
1000MAX_NPCSMaximum number of NPCs
64NPC_MAX_NODESMaximum number of nodes

Invalid Constants

ValueConstantDescription
-1INVALID_NPC_IDInvalid NPC ID
-1INVALID_PATH_IDInvalid path ID
-1INVALID_NODE_IDInvalid node ID
-1INVALID_RECORD_IDInvalid recording ID

Movement Types

Used by functions like NPC_Move, NPC_MoveByPath, NPC_EnterVehicle, and NPC_PlayNode.

ValueConstantDescription
-1UNKNOWN_NPC_MOVE_TYPEUnknown movement type
0NPC_MOVE_TYPE_NONENo movement
1NPC_MOVE_TYPE_WALKNPC walks to destination
2NPC_MOVE_TYPE_JOGNPC jogs to destination (default for most functions)
3NPC_MOVE_TYPE_SPRINTNPC sprints to destination
4NPC_MOVE_TYPE_DRIVENPC drives to destination (vehicle movement)
5NPC_MOVE_TYPE_AUTOAutomatic movement type

Movement Speed

Used by movement functions to control NPC speed.

ValueConstantDescription
-1.0NPC_MOVE_SPEED_AUTOAutomatic speed based on movement type
0.1552086NPC_MOVE_SPEED_WALKWalking speed
0.56444NPC_MOVE_SPEED_JOGJogging speed
0.926784NPC_MOVE_SPEED_SPRINTSprinting speed

Entity Check Flags

Used by NPC_AimAt, NPC_AimAtPlayer, and NPC_Shoot for collision detection.

ValueConstantDescription
0NPC_ENTITY_CHECK_NONENo collision checking
1NPC_ENTITY_CHECK_PLAYERCheck collisions with players
2NPC_ENTITY_CHECK_NPCCheck collisions with NPCs
4NPC_ENTITY_CHECK_ACTORCheck collisions with actors
8NPC_ENTITY_CHECK_VEHICLECheck collisions with vehicles
16NPC_ENTITY_CHECK_OBJECTCheck collisions with objects
32NPC_ENTITY_CHECK_POBJECT_ORIGCheck collisions with player objects (original)
64NPC_ENTITY_CHECK_POBJECT_TARGCheck collisions with player objects (target)
128NPC_ENTITY_CHECK_MAPCheck collisions with map
255NPC_ENTITY_CHECK_ALLCheck collisions with all entities

Bullet Hit Types

Used by NPC_Shoot to specify what type of target is being hit.

ConstantDescription
BULLET_HIT_TYPE_NONENo specific target
BULLET_HIT_TYPE_PLAYERPlayer 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);
}
}