πŸ§‘β€πŸŒΎ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" or 0 if 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 NPC

  • coords : Position (x, y, z)

  • heading : Direction the NPC is facing

  • anim : Animation or scenario

  • distance : Distance from which NPC is loaded

  • dontreact : NPC ignores world events

  • walking : NPC will walk around (boolean)

  • walking_distance : How far the NPC will walk

  • weapon : Weapon (if any) to give to the NPC


πŸ“Œ Notes

  • If getNPCEntity() returns 0, 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