Skip to content

tw.entity

Side: Client + Server

Entity creation, deletion, and fade animations. Automatic cleanup on resource stop.

Client Functions

tw.entity.create(model, coords, heading?, networked?, fadeDuration?)

Creates an entity (ped, object, or vehicle) at the given position.

Supports two call signatures:

  • create(model, vec3, heading?, networked?, fadeDuration?)
  • create(model, vec4, networked?, fadeDuration?) — heading is taken from coords.w
ParameterTypeDefaultDescription
modelstringModel name
coordsvector3 or vector4World position
headingnumber?0Direction angle (only with vec3)
networkedboolean?falseWhether the entity is networked
fadeDurationinteger?0Fade-in duration in ms (0 = instant)

Returns: integer (entity handle), 0 on failure (10s model load timeout)


tw.entity.delete(entity)

Deletes an entity if it exists.

ParameterTypeDescription
entityintegerEntity handle

tw.entity.fadeAndDelete(entity, duration?)

Fades out the entity then deletes it. Runs in a separate thread so it does not block.

ParameterTypeDefaultDescription
entityintegerEntity handle
durationinteger?1000Fade-out duration in ms

tw.entity.fadeIn(entity, duration?)

Gradually shows an entity (alpha 0 to 255). Handles wagons and horse teams.

ParameterTypeDefaultDescription
entityintegerEntity handle
durationinteger?1000Fade-in duration in ms

tw.entity.fadeOut(entity, duration?)

Gradually hides an entity (alpha 255 to 0).

ParameterTypeDefaultDescription
entityintegerEntity handle
durationinteger?1000Fade-out duration in ms

tw.entity.requestControl(entity)

Requests network control of an entity. Blocks until control is obtained.

ParameterTypeDescription
entityintegerEntity handle

Server Functions

tw.entity.delete(entity)

Deletes an entity if it exists (server-side).

ParameterTypeDescription
entityintegerEntity handle

Examples

Create a ped with fade-in

lua
local ped = tw.entity.create("a_m_m_rancher_01", vec3(-301.62, 783.04, 117.75), 180.0, false, 1000)

Create using vec4 (heading from w component)

lua
local ped = tw.entity.create("a_m_m_rancher_01", vec4(-301.62, 783.04, 117.75, 180.0), false, 1000)

Delete with fade-out

lua
tw.entity.fadeAndDelete(ped, 500)

Manual fade control

lua
-- Hide an entity gradually
tw.entity.fadeOut(ped, 2000)

-- Show it again
tw.entity.fadeIn(ped, 2000)

Notes

  • All created entities are tracked and automatically deleted when the resource stops.
  • Model loading has a 10-second timeout. If the model fails to load, the function returns 0.
  • fadeAndDelete runs asynchronously in its own thread, so your code continues immediately after calling it.
  • fadeIn and fadeOut handle wagons and their attached horse teams automatically.

Premium RedM Scripts — Multi-Framework