Skip to content

Object (tm.object) ​

World objects (props). Available on the client and on the server, with different feature sets.

Client ​

tm.object.create(props) ​

Creates an object on this client. The props table becomes the returned object, with id, entity and remove added. Passing something that is not a table, or props without model and coords, raises an error.

lua
local obj = tm.object.create({
    model = 'prop_bench_01a',
    coords = vector4(100.0, 200.0, 30.0, 90.0), -- w is the heading
    static = true,       -- freeze the object
    distance = 150.0,    -- only exists while the player is closer than this
    lifecycle = 60000,   -- removed after a minute

    onCreated = function(entity) print('spawned', entity) end,
    onDeleted = function(entity) print('removed', entity) end,
})

obj:remove()
PropTypeDescription
modelstring or integerModel name or hash.
coordsvector3 or vector4Position. w is the heading.
headingnumberHeading, used when coords has no w.
staticbooleanFreeze the object.
networkedbooleanCreate it as a networked object.
distancenumberStreaming radius in meters. The entity is created when the player is closer and deleted when farther.
attachmenttableAttach to another entity, see below.
lifecycleintegerRemove the object after this many milliseconds.
onCreatedfun(entity)Called every time the entity is created, so again after a distance respawn.
onDeletedfun(entity)Called when the object is removed or despawned by distance.

attachment fields:

FieldDescription
entityEntity to attach to. Default: the player ped. ped is accepted as the older name.
bone / boneIndexBone name or index. Default: the right hand of a ped (bone 24818).
offsetvector3 offset from the bone. Also available as offsetX, offsetY, offsetZ. Default 0.09, -0.16, 0.0.
rotationvector3, default 0.0, 180.0, 0.0.
disableCollisionTurn collision off for the object.

Object ​

Field or methodDescription
idUnique id.
entityThe entity handle, 0 while a distance object is despawned or its model could not load.
remove()Deletes the entity and forgets the object. Safe to call more than once.

Behavior ​

  • A distance object is checked every 5 seconds. The checking thread only exists while at least one distance object does. An object that is already in range at creation spawns immediately.
  • If something else deletes the entity, a distance object is created again the next time it is in range.
  • A model that does not load within 5 seconds gives entity 0 and one warning through tm.log.
  • Objects are deleted when the resource stops.

Server ​

tm.object.create(props) ​

Creates a networked object visible to every player. The props table becomes the returned object, with id, entity and remove added. Returns nil and a reason when the game could not create the entity.

lua
local obj = tm.object.create({
    model = 'prop_bench_01a',
    coords = vector4(100.0, 200.0, 30.0, 0.0),
    static = true,
    routingBucket = 2,
    onCreated = function(entity) print('created', entity) end,
})

Props: model, coords, heading, static, routingBucket and onCreated, as above. remove() deletes the entity. Server objects are deleted when the resource stops.