Skip to content

tw.player

Side: Client | Alias: tw.pl

Auto-updated player information, refreshed every 100ms. Provides quick access to the local player's ped, coordinates, and identity.

Properties

PropertyTypeDescription
tw.player.pedintegerCurrent player ped handle
tw.player.coordsvector3Current player world coordinates
tw.player.player_idintegerLocal player ID
tw.player.server_idintegerServer-side player ID (source)
tw.player.is_malebooleanWhether the player model is male

Callable

tw.player() can be called directly as a function. It returns tw.player.ped.

lua
local ped = tw.player()
-- equivalent to tw.player.ped

Functions

tw.player.force_update()

Forces an immediate refresh of all player properties. Fires the twinded_libs:player:update event after updating.

lua
tw.player.force_update()
-- tw.player.coords is now guaranteed up-to-date

tw.player.move(callback, interval?)

Registers a callback that fires when the player moves. The callback is called immediately on first registration with the current position. Multiple callbacks can be registered.

ParameterTypeDefaultDescription
callbackfunctionCalled with updated player data on movement
intervalinteger?Custom poll interval in ms
lua
tw.player.move(function()
    print("Player moved to", tw.player.coords)
end)

tw.player.did_move_since(id) -> boolean

Checks whether the player has moved since the last time this function was called with the given id. Each id tracks its own position independently.

ParameterTypeDescription
idstringUnique identifier for this movement check

Returns: booleantrue if the player moved since the last call with this id.

lua
if tw.player.did_move_since("my_feature") then
    print("Player moved since last check")
end

Examples

Access player info

lua
tw.ready(function()
    print("Server ID:", tw.player.server_id)
    print("Position:", tw.player.coords)
    print("Is male:", tw.player.is_male)
end)

React to player movement

lua
tw.player.move(function()
    -- Update nearby markers, refresh UI, etc.
    local pos = tw.player.coords
    -- ...
end)

Use as function shorthand

lua
local ped = tw.player()
SetEntityHeading(ped, 180.0)

Events

EventDescription
twinded_libs:player:updateFired after force_update() completes

Notes

  • Properties are updated automatically every 100ms in a background thread.
  • tw.player() is a shorthand for tw.player.ped and can be used anywhere a ped handle is expected.
  • did_move_since is useful for throttling expensive operations that only need to run when the player changes position.

Premium RedM Scripts — Multi-Framework