Appearance & behaviour ​
exports.np_npchandler:registerNpc({
id = 'np_food:vendor',
model = 's_m_m_linecook',
coords = vector4(-1194.6, -893.4, 13.9, 300.0),
outfit = { components = { [11] = { drawable = 0, texture = 1 } }, props = { [0] = { drawable = -1 } } },
props = { { model = 'prop_cs_burger_01', bone = 57005, offset = { 0.13, 0.05, 0.02 }, rotation = { -50.0, 16.0, 60.0 } } },
patrol = { points = { p1, p2, p3 }, wait = 4000 },
speech = { greet = 'GENERIC_HI', interact = 'GENERIC_HOWS_IT_GOING' },
})
The client that controls a ped applies its look and flags once, when it creates or first controls it. Local peds are always controlled by their client. For networked peds it is the owning client; after an ownership migration the new owner re-applies the flags only.
Outfit ​
outfit = {
default = true, -- SetPedDefaultComponentVariation first
random = false, -- or SetPedRandomComponentVariation + SetPedRandomProps
components = { [11] = { drawable = 4, texture = 0, palette = 0 } }, -- or { { component = 11, drawable = 4 } }
props = { [0] = { drawable = -1 } }, -- drawable -1 clears the slot
}
| Field | Default | Notes |
|---|---|---|
default |
true |
Default component variation before the components are set |
random |
false |
Random components and props instead |
components |
none | Component 0 to 11. drawable −1 to 4096, texture 0 to 4096, palette 0 to 3. Up to 16 entries |
props |
none | Prop slot 0 to 12. drawable = -1 clears the slot. Up to 16 entries |
Without outfit, the ped gets its default variation.
Held props ​
props = {
{ model = 'prop_cs_burger_01', bone = 57005, offset = { 0.13, 0.05, 0.02 }, rotation = { -50.0, 16.0, 60.0 } },
}
| Field | Default | Notes |
|---|---|---|
model |
required | Name or hash. Checked against restrict.models |
bone |
57005 (right hand) |
Ped bone id, 0 to 65535 |
offset, rotation |
0, 0, 0 |
{ x, y, z } or a vector |
Up to 4 per NPC. Every client that renders the ped attaches its own local copy, so held props cost no network
entities and survive ownership migration. When np_prophandler runs, its attach
export is used; otherwise np_npchandler creates and attaches a local object itself.
Weapon, flags and combat ​
| Field | Default | What it does |
|---|---|---|
weapon |
none | 'WEAPON_PISTOL' or { name, ammo = 250, visible = true }. Given with GiveWeaponToPed. With visible = false the ped stays unarmed in hand |
invincible |
true |
SetEntityInvincible, and the ped does not die when injured |
frozen |
true, false with a preset |
FreezeEntityPosition |
blockEvents |
true |
SetBlockingOfNonTemporaryEvents and no flee attributes. The ped ignores gunshots and threats |
ragdoll |
false |
SetPedCanRagdoll |
collision |
true |
false turns entity collision off |
relationship |
none | 'GROUP' or { group, hates = { 'PLAYER' }, likes = {} }. The group is created when needed; hates / likes are set both ways. Up to 8 names each |
health, armor |
game | Max and current health (101 to 10000); armour (0 to 100) |
accuracy, combatAbility |
game | 0 to 100; 0 to 2 |
combatAttributes |
none | { [46] = true }, attribute 0 to 127. Up to 16 |
dropsWeapons |
false |
SetPedDropsWeaponsWhenDead |
voice |
game | SetAmbientVoiceName |
Idle and presets ​
One idle task per NPC: scenario or anim, or one of the presets wander, patrol and guard. A scenario or
anim takes priority over a preset. Combining scenario and anim is refused ('conflicting_idle'), and so is more
than one preset ('conflicting_behavior').
| Field | Shape | What it does |
|---|---|---|
scenario |
'WORLD_HUMAN_CLIPBOARD' |
TaskStartScenarioInPlace. Any native scenario name, or a v0.2.0 alias such as stand_impatient |
anim |
{ dict, clip, flag = 1 } |
TaskPlayAnim, looping with flag 1. The dict is loaded and released for you |
wander |
true or { radius = 10.0 } |
TaskWanderInArea around coords. Radius 1 to 200 |
patrol |
{ points = { … }, wait = 3000, speed = 1.0, loop = true } |
Walks the points (2 to 32) with TaskFollowNavMeshToCoord, waits wait ms (0 to 600000) at each. speed 0.5 to 3.0. loop = false walks back and forth. points can also be the list itself |
guard |
true or { radius = 8.0 } |
TaskGuardCurrentPosition. Radius 1 to 100 |
A preset makes frozen default to false. Patrol is advanced by the slow client pass, never per frame. A networked
patrol continues from the nearest point after an ownership migration.
Speech ​
speech = { greet = 'GENERIC_HI', interact = 'GENERIC_HOWS_IT_GOING', params = 'SPEECH_PARAMS_FORCE_NORMAL_CLEAR', greetDistance = 4.0 }
greetplays when the player comes withingreetDistance(0.5 to 30), at most once perinteraction.greetCooldownMs(30 s) per ped, and again only after the player has left that distance.interactplays when the player uses the NPC'sinteractoption.- Speech plays on the local client with
PlayPedAmbientSpeechNative.
Runtime control ​
client
Tasks you can give a handled ped at runtime:
| Export | What it does |
|---|---|
playAnim(target, dict, clip, { flag, duration }) |
Plays an anim. flag defaults to 0, duration to −1 (until stopped) |
playScenario(target, scenario) |
Starts a scenario (aliases work) |
speak(target, speech, params?) |
Ambient speech. Plays on this client only and needs no control |
faceEntity(target, entity, durationMs) |
Turns to an entity, default 1000 ms |
walkTo(target, coords, { speed }) |
Unfreezes the ped and walks to coords. speed up to 3.0, default 1.0 |
stopTask(target) |
Clears its tasks |
resumeBehavior(target) |
Clears its tasks, re-applies its flags and freeze, and restarts its idle task or preset. Never refills health, armour or ammo |
target is an NPC id, an immediate ped handle ('ped:<n>') or the entity of a ped the handler created. A task
pauses a patrol until resumeBehavior, or until a timed playAnim / faceEntity ends. Other idle tasks
(scenario, anim, wander, guard) come back only with resumeBehavior.
They return true, true, 'routed' (sent to the client that controls the ped) or false, reason:
'invalid_args', 'not_handled' (not a handled ped), 'not_allowed', 'face_target_not_networked'.
-- a street sale with an NPC dealer the resource registered itself
exports.np_npchandler:faceEntity('np_drugs:dealer_3', PlayerPedId(), 1500)
exports.np_npchandler:playAnim('np_drugs:dealer_3', 'mp_common', 'givetake1_b', { flag = 48, duration = 1600 })
Networked peds and allowRemoteControl ​
- Local peds and peds this client created are tasked directly.
- A networked ped this client does not control is routed: the request goes to the server, which checks it and sends it to the client that owns the ped.
- A networked ped created elsewhere (a registered NPC, or another client's or the server's immediate ped) can only be
tasked by other clients when its definition has
allowRemoteControl = true. Without it, the export returnsfalse, 'not_allowed'. The exception is a client-created ped: its creator can always task it. - A server mission ped without
allowRemoteControlcan still be tasked by itsownerSource. Only the server knows who that is, so the client export always routes these requests to the server (it returnstrue, 'routed'), and the server refuses everyone else.
The server checks every routed request:
| Check | Refused when |
|---|---|
| Rate limit | More than control.maxPerPlayer (30) requests per control.windowMs (10 s) |
| Ped | Not created by np_npchandler, or not allowed as above |
| Distance | The player is farther than control.maxDistance (60 m) from the ped |
walkTo |
The target point is farther than control.maxDistance from the ped |
speak is never routed. faceEntity on a routed ped needs a networked target entity. Tasks are presentation; keep
your own authority on the server for anything they lead to.