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 fromcoords.w
| Parameter | Type | Default | Description |
|---|---|---|---|
model | string | — | Model name |
coords | vector3 or vector4 | — | World position |
heading | number? | 0 | Direction angle (only with vec3) |
networked | boolean? | false | Whether the entity is networked |
fadeDuration | integer? | 0 | Fade-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.
| Parameter | Type | Description |
|---|---|---|
entity | integer | Entity handle |
tw.entity.fadeAndDelete(entity, duration?)
Fades out the entity then deletes it. Runs in a separate thread so it does not block.
| Parameter | Type | Default | Description |
|---|---|---|---|
entity | integer | — | Entity handle |
duration | integer? | 1000 | Fade-out duration in ms |
tw.entity.fadeIn(entity, duration?)
Gradually shows an entity (alpha 0 to 255). Handles wagons and horse teams.
| Parameter | Type | Default | Description |
|---|---|---|---|
entity | integer | — | Entity handle |
duration | integer? | 1000 | Fade-in duration in ms |
tw.entity.fadeOut(entity, duration?)
Gradually hides an entity (alpha 255 to 0).
| Parameter | Type | Default | Description |
|---|---|---|---|
entity | integer | — | Entity handle |
duration | integer? | 1000 | Fade-out duration in ms |
tw.entity.requestControl(entity)
Requests network control of an entity. Blocks until control is obtained.
| Parameter | Type | Description |
|---|---|---|
entity | integer | Entity handle |
Server Functions
tw.entity.delete(entity)
Deletes an entity if it exists (server-side).
| Parameter | Type | Description |
|---|---|---|
entity | integer | Entity 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. fadeAndDeleteruns asynchronously in its own thread, so your code continues immediately after calling it.fadeInandfadeOuthandle wagons and their attached horse teams automatically.

