Skip to content

Reference

Props, aim and placement ​

Props (objects placed for every player) ​

A prop is a networked object created by the server, frozen, unbreakable and kept: a car does not move nor break it (each client protects it as it streams in), it never despawns, and RLX puts it back within 10 s if something deletes it. Furniture, a road block, a market stall, a drug lab, map additions without an MLO.

lua
-- Server
local id, netId = RLX.AddProp({ model = "prop_barrier_work05", coords = { x = 215.0, y = -810.0, z = 29.7 }, heading = 90 })
RLX.AddProp({ id = "stall_1", model = "prop_gazebo_02", coords = c, rotation = { x = 0, y = 0, z = 45 },
  frozen = true, dimension = 0, data = { owner = xPlayer.citizenid } })

RLX.UpdateProp(id, { coords = c2, heading = 180 })   -- only what is given changes
RLX.RemoveProp(id)
  • Options: model and coords (required; the base of the model, or its origin with noOffset = true), heading or rotation, frozen (default true), breakable (default false: true lets the game break it, like a real barrier), dimension (an instance), data (yours, kept with the prop), id (yours, or one is made).
  • RLX.GetProp(id), RLX.GetProps(resource), RLX.GetPropsInRadius(coords, radius, dimension), RLX.GetPropFromEntity(netId). The entity carries the state rlx:prop (its id): with RLX.AddTarget on its model, a prop becomes usable (sit on the bench, open the stall).
  • A resource's props go when it stops. They are not saved: keep them in your database and add them again at start (RLX.AddProp with the same id replaces).
  • Events: rlx:propAdded (id, prop), rlx:propRemoved (id).

Kept across restarts: persist = true saves the prop (in the storage of rlx); it comes back by itself when the server starts, and stays when its resource stops. RLX.RemoveProp forgets it. An option of RLX.AddTarget can aim at one prop: prop = "stall_1".

Aim, entity center, outlines (client) ​

lua
local hit = RLX.RaycastCamera(10.0)   -- { hit, position, normal, entity, type, netId, model, distance }
local entity, info = RLX.GetAimedEntity(8.0, { types = { "vehicle", "object" } })   -- info = { type, netId, model, position, distance }
local center = RLX.GetEntityCenter(entity, info.model)   -- the middle of its model: a door's center, not its hinge

RLX.Highlight(entity, { color = "#3d8bff", width = 3 })   -- or mode = "fill" / "dashed"
RLX.Unhighlight(entity)
RLX.ClearHighlights()
  • The ray starts from the camera actually drawn (noclip and scripted cameras included).
  • Never call getEntityModel on a handle from a raycast: on some entities (without model information) it crashes the game, and doesEntityExist does not protect you (LS:MP documentation). Use info.model: it comes from the entity when it is networked, otherwise from the LS:MP picker, so it can be nil for one frame. RLX.GetEntityModelSafe(entity) does the same for any handle.
  • Outlines belong to the resource that draws them and go when it stops. LS:MP draws 32 at most for all resources: take them down when done.

Placement mode (client) ​

The player places an object themselves: a ghost follows the aim (green outline in range, red too far), the wheel turns it (Shift: fast), PgUp / PgDn raise or lower it, E places it, Backspace cancels.

lua
-- Client (in a thread: it waits for the player)
local spot = RLX.PlaceObject("prop_tool_bench02", { maxDistance = 6 })
if spot then lsmp.emitServer("myres:place", spot) end
lua
-- Server: check, then place it exactly where the ghost stood
RLX.RegisterNetEvent("myres:place", function(source, spot)
  local xPlayer = RLX.GetPlayer(source)
  if not xPlayer or xPlayer.getItemCount("workbench") < 1 then return end
  xPlayer.removeItem("workbench", 1)
  RLX.AddProp({ model = "prop_tool_bench02", coords = spot.coords, rotation = spot.rotation, noOffset = true })
end)
  • Options: maxDistance (8 m), heading (start), rotateStep (5°), height = false (no PgUp / PgDn), ground = false (the model's origin on the aimed point instead of its bottom).
  • Returns { model, coords, heading, rotation, noOffset = true }, or nil (cancelled, unknown model). It places nothing by itself: the ghost goes away and your resource decides (the server creates the prop with RLX.AddProp, as above). RLX.IsPlacing() tells whether a placement runs. The server always checks the distance and the item: the client is never trusted. rlx_police (F6 > Road objects) is a complete example.
  • Config.TracePlacement = true (rlx/shared/config.lua) writes each step of the placement mode in the server console ([RLX] placement #<player>: ...): if the game ever crashes, the last line says where. Leave it false otherwise.

Server: the vehicle of a player ​

local netId, seat = RLX.GetPlayerVehicle(source): the vehicle the player sits in and their seat (0 = driver); nil on foot.