π§βπΎAmbient NPC
Manage and spawn custom ambient NPCs (PNJ) for your RedM server, both client-side and server-side.
β‘ Getting Started
By default, everything is already set up in config.lua.
If you want to customize the NPC system integration, you can remove lines 3β11 in your config.lua and use your own logic.
Start the system:
TriggerEvent("Botiv:startPNJSystem")π¦ Client Side
Add an NPC (Event)
Create and spawn a new NPC using:
TriggerEvent("Botiv-publicnpc:insertNewNPC", "boss-1", {
model = "a_m_m_sddockworkers_02",
coords = { x = -803.6, y = -1292.98, z = 42.63 },
heading = 60.62,
anim = "WORLD_HUMAN_SIT_GROUND_READ_NEWSPAPER",
distance = 50.0,
dontreact = true,
walking = false,
walking_distance = 20.0,
weapon = ""
})Get an NPC Entity (Export)
Retrieve the entity number of a given NPC (from your config or dynamic event):
Returns: The entity ID for
"paper-1"or0if not loaded (player too far).
Example:
π§ Server Side
Insert NPC (Server Event)
To instruct a client to spawn a new NPC from the server:
βοΈ NPC Configuration Example
Hereβs a sample from your config.lua:
Key fields:
model: Model name of the NPCcoords: Position (x, y, z)heading: Direction the NPC is facinganim: Animation or scenariodistance: Distance from which NPC is loadeddontreact: NPC ignores world eventswalking: NPC will walk around (boolean)walking_distance: How far the NPC will walkweapon: Weapon (if any) to give to the NPC
π Notes
If
getNPCEntity()returns0, the NPC isn't loaded for the player (usually too far away).NPCs can be managed both through config and at runtime using events/exports.
Last updated