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()| Prop | Type | Description |
|---|---|---|
model | string or integer | Model name or hash. |
coords | vector3 or vector4 | Position. w is the heading. |
heading | number | Heading, used when coords has no w. |
static | boolean | Freeze the object. |
networked | boolean | Create it as a networked object. |
distance | number | Streaming radius in meters. The entity is created when the player is closer and deleted when farther. |
attachment | table | Attach to another entity, see below. |
lifecycle | integer | Remove the object after this many milliseconds. |
onCreated | fun(entity) | Called every time the entity is created, so again after a distance respawn. |
onDeleted | fun(entity) | Called when the object is removed or despawned by distance. |
attachment fields:
| Field | Description |
|---|---|
entity | Entity to attach to. Default: the player ped. ped is accepted as the older name. |
bone / boneIndex | Bone name or index. Default: the right hand of a ped (bone 24818). |
offset | vector3 offset from the bone. Also available as offsetX, offsetY, offsetZ. Default 0.09, -0.16, 0.0. |
rotation | vector3, default 0.0, 180.0, 0.0. |
disableCollision | Turn collision off for the object. |
Object
| Field or method | Description |
|---|---|
id | Unique id. |
entity | The 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
0and one warning throughtm.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.