Skip to content

Migrating from CreatePed ​

Most np_* resources create their NPCs themselves: RequestModel, CreatePed, a handful of flags, a scenario, a distance loop and their own DeleteEntity. This page maps those patterns onto np_npchandler, and lists what the np_* resources register with it. The handler owns the model loading, the distance loop, the ped flags and the clean-up.

Patterns ​

You do today Use instead
CreatePed near the player in a distance loop, delete when far Server registerNpc or client addLocalNpc. See Local NPCs
A networked CreatePed so everyone sees the same ped mode = 'networked' in registerNpc. See Networked NPCs
SetEntityInvincible, SetBlockingOfNonTemporaryEvents, FreezeEntityPosition Nothing: invincible, blockEvents and frozen are on by default
TaskStartScenarioInPlace after spawning scenario = '…' in the definition
An E-key loop, ShowPrompt, ox_target or qb-target per ped The interact option, or a list of up to six
A state check before showing a prompt (dead, cuffed, menu open) A client predicate: canInteract or setCanInteract
ClonePed(PlayerPedId(), …) for a body left behind createNetworkedPed({ clone = 'player', … }) or createLocalPed. See Clone a ped
Adding client NPCs again on onClientResourceStart of np_npchandler np_npchandler:ready, which now fires on the client too
A preview ped in a scene, deleted with the scene createLocalPed / deleteLocalPed
A ped that walks somewhere, then leaves createLocalPed + walkTo + dismissPed
A networked ped the client tasks (k9) createNetworkedPed; its net id arrives in the callback
CreatePedInsideVehicle for mission drivers Client createNetworkedPedInVehicle or server spawnPedInVehicle
SetPedRelationshipGroupHash, SetPedAccuracy, SetPedCombatAttributes relationship, accuracy, combatAbility, combatAttributes in the definition
CreateObject + AttachEntityToEntity for a prop in the ped's hand props = { { model, bone, offset, rotation } }. See Held props
SetPedDensityMultiplierThisFrame in a loop setPopulation
Deleting everything on onResourceStop Nothing. Everything a resource registered or created is removed when it stops

How the np_* resources use it ​

These resources list np_npchandler in their dependencies. They create no peds of their own and have no fallback.

Resource What goes through np_npchandler
np_banking Client addLocalNpc: the branch teller (np_banking:branch:<locId>), removed while a player teller is on duty
np_character createLocalPed / deleteLocalPed: the preview peds of the character select scene (placeOnGround)
np_clothing Server registerNpc: store clerks (np_clothing:clerk:<id>, local, decoration only). createLocalPed: the hidden peds of the catalogue scan
np_darts createLocalPed: the house regular you play against
np_drugs Client addLocalNpc: rehab doctors (np_drugs:rehab:<clinicId>, event np_drugs:rehab:desk), added on the client np_npchandler:ready. createNetworkedPed: the k9 dog, its net id sent to the server from the callback. Street sales still task ambient peds np_drugs did not create
np_environmental Server registerNpcs: scene peds (np_environmental:<scene>:<obj>), animals with pedType = 28 and wander. createLocalPed: the editor's preview peds
np_farming Server registerNpc: market buyers (np_farming:market:<buyer>, hours, event np_farming:npc:interact), hidden with setCanInteract while the player cannot act. Client addLocalNpc: pen animals with wander. createLocalPed: crows and the truffle pig
np_fishing Server registerNpcs: buyers and shop keepers (np_fishing:buyer_<id>, np_fishing:shop_<id>, event np_fishing:economy:interact)
np_gangs Client addLocalNpc: Lester (np_gangs:lester, event np_gangs:lester:open), with a canInteract that shows him only when he has an option for the player. Corner customers with createLocalPed, walkTo and dismissPed. Trial drivers and patrol cops with createNetworkedPedInVehicle, gunmen with createNetworkedPed
np_golf createLocalPed: the NPC caddie, with the golf bag as a held prop
np_identification Client addLocalNpc: desk clerks and the forger (np_identification:<pointId>, event np_identification:npc:use with data.point), with a canInteract that hides the prompt while a view is open or the player is dead or cuffed
np_metal-scanner Server registerNpc: gate guards, enabled with setNpcEnabled while no operator is on duty, and ground buyers (event np_metal-scanner:ground:buyer)
np_prison Server registerNpcs: guard posts (np_prison:npcguard:<facility>:<i>), switched with setNpcEnabled by duty. Client addLocalNpc on np_npchandler:ready: Sight posts and the plug (event np_prison:plug:talk, shown only while jailed through canInteract). createNetworkedPedInVehicle: the intake bus driver
np_shops Server registerNpc: networked, always spawned clerks (np_shops:<shopId>:clerk) with policies, interaction handlers and np_npchandler:incident for the robbery alarm. Hands up and calm through playAnim, stopTask and resumeBehavior
np_spy-pigeon createNetworkedPed({ clone = 'player' }): the body left behind during a flight, removed with deleteNetworkedPed. createLocalPed: the attacking hawk

Server and client registrations are sent again on np_npchandler:ready, which fires on both sides after a restart of np_npchandler. np_tattoos creates no ped of its own.

coords is the position given to CreatePed. Code that subtracted 1.0 from a standing player's position keeps doing that, or uses placeOnGround = true.

Example: a desk clerk ​

Before:

lua
-- client
CreateThread(function()
  local ped
  while true do
    local near = #(GetEntityCoords(PlayerPedId()) - desk.coords.xyz) < 60.0
    if near and not ped then
      RequestModel(desk.model)
      while not HasModelLoaded(desk.model) do Wait(0) end
      ped = CreatePed(4, desk.model, desk.coords.x, desk.coords.y, desk.coords.z - 1.0, desk.coords.w, false, true)
      SetEntityInvincible(ped, true)
      SetBlockingOfNonTemporaryEvents(ped, true)
      FreezeEntityPosition(ped, true)
      TaskStartScenarioInPlace(ped, 'WORLD_HUMAN_CLIPBOARD', 0, true)
    elseif not near and ped then
      DeleteEntity(ped)
      ped = nil
    end
    Wait(1000)
  end
end)

After:

lua
-- client
exports.np_npchandler:addLocalNpc({
  id = 'np_identification:desk_' .. id,
  model = desk.model,
  coords = vector4(desk.coords.x, desk.coords.y, desk.coords.z - 1.0, desk.coords.w),
  spawnDistance = 60.0,
  scenario = 'WORLD_HUMAN_CLIPBOARD',
  interact = { label = desk.label, icon = desk.icon, distance = 2.0, event = 'np_identification:npc:use' },
  data = { point = 'desk_' .. id },
})

AddEventHandler('np_identification:npc:use', function(npcId, entity, data)
  OpenDesk(data.point)
end)