Skip to content

ReferenceStates, zones, net events, instances, decals

NPCs, held objects, effects and sounds ​

lua
-- A persistent NPC (put back if deleted). Its behavior is an LS:MP AI intent:
-- kept by the server, applied again by whoever simulates the NPC.
local id = RLX.AddPed({
  model = "s_m_m_doctor_01", coords = { x = 308.0, y = -595.0, z = 43.3 }, heading = 70,
  behavior = "idle",                       -- idle, wander, guard, follow, flee, combat
  scenario = "WORLD_HUMAN_CLIPBOARD",      -- or anim = { dict, clip, flag }
  radius = 10, invincible = true, calm = true, frozen = false, weapon = nil,
})
RLX.UpdatePed(id, { behavior = "wander", radius = 20 })   RLX.PlayPedAnim(id, "mp_common", "givetake1_a")
RLX.RemovePed(id)   RLX.GetPed(id)   RLX.GetPeds(resource)   RLX.GetPedFromEntity(netId)

-- An object in a player's hand, seen by everyone, following their ped (8 at most per player).
local box = RLX.AttachObject(source, { model = "prop_cs_cardbox_01", bone = 28422, offset = { x = 0, y = 0.1, z = 0 }, rotation = { x = 0, y = 0, z = 0 } })
RLX.DetachObject(box)   RLX.DetachAllObjects(source)   RLX.GetAttachedObjects(source)

-- Particles and sounds for the players near (range in meters).
RLX.PlayEffect({ coords = c, asset = "core", name = "exp_grd_grenade_smoke", scale = 1.0, duration = 6000, range = 120 })
RLX.PlayEffect({ entity = netId, name = "ent_brk_sparking_wires", duration = 3000 })   -- on an entity
RLX.PlaySoundAt({ coords = c, name = "Bed", set = "WastedSounds", range = 40 })
RLX.PlaySoundFor(source, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET")              -- -1: everyone
RLX.SetWaypoint(source, { x = 215.0, y = -810.0, z = 30.7 })

NPC options: invincible (default true), calm (ignores shots and shoves, default true), frozen, accuracy, hatesPlayers, run, target (follow, flee, combat: a netId or "nearestPlayer"), dimension, data. On the entity: state rlx:ped = the id (an option of RLX.AddTarget can aim at one NPC: ped = id). A resource's NPCs and held objects go with it.

A held object is not a network entity: the server keeps the list on the player (meta rlx:held), and every player near creates the object in their own game and attaches it to the holder's hand once the game has fully built it (attaching a networked object could crash the game). Nothing to stream or to sync; the objects go when the player changes character or leaves.