Skip to main content

Player

Gaming

A player reference is typically obtained by:

  • Scene:get_all_players()
  • Scene:get_player()

Input

All input is handled with the Player API.

Below is a list of the keycodes you can use in functions like key_pressed. Many other keys are supported but omitted from this list for brevity.

  • `
  • \
  • [
  • ]
  • ,
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • =
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • I
  • J
  • K
  • L
  • M
  • N
  • O
  • P
  • Q
  • R
  • S
  • T
  • U
  • V
  • W
  • X
  • Y
  • Z
  • -
  • .
  • '
  • ;
  • /
  • AltLeft
  • AltRight
  • Backspace
  • CapsLock
  • ContextMenu
  • ControlLeft
  • ControlRight
  • Enter
  • SuperLeft
  • SuperRight
  • ShiftLeft
  • ShiftRight
  •  
  • Tab
  • Delete
  • End
  • Home
  • Insert
  • PageDown
  • PageUp
  • ArrowDown
  • ArrowLeft
  • ArrowRight
  • ArrowUp
  • NumLock
  • Numpad0
  • Numpad1
  • Numpad2
  • Numpad3
  • Numpad4
  • Numpad5
  • Numpad6
  • Numpad7
  • Numpad8
  • Numpad9
  • NumpadAdd
  • NumpadBackspace
  • NumpadClear
  • NumpadClearEntry
  • NumpadComma
  • NumpadDecimal
  • NumpadDivide
  • NumpadEnter
  • NumpadEqual
  • NumpadHash
  • NumpadMemoryAdd
  • NumpadMemoryClear
  • NumpadMemoryRecall
  • NumpadMemoryStore
  • NumpadMemorySubtract
  • NumpadMultiply
  • NumpadParenLeft
  • NumpadParenRight
  • NumpadStar
  • NumpadSubtract
  • Escape
  • Fn
  • Meta
  • Hyper
  • Turbo

Fields


.id

Identifier for the player. Is a number.

Functions

note

Make sure to use :function() and not .function(), or you'll get an error


:pointer_pos()

Get the position of the player's cursor in world coordinates.


:grid_pointer_pos()

Gets the position of the player's cursor in world coordinates, snapped to the grid.


:grid_enabled()

Gets whether or not the player has grid enabled.


:grid_multiplier()

Gets the grid multiplier the player has configured.


:grid_size()

Gets the grid size the player has configured.


:set_camera_position()

Sets the position of the player's camera.


:set_camera_zoom()

Sets the zoom of the player's camera.


:key_just_pressed()

Returns whether or not a specified key was just pressed.

Example

if player:key_just_pressed("W") then
-- do something
end;

:key_just_released()

Returns whether or not a specified key was just released.

Example

if player:key_just_released("W") then
-- do something
end;

:key_pressed()

Returns whether or not a specified key is currently pressed.

Example

if player:key_pressed("W") then
-- do something
end;

:pointer_just_pressed()

Returns whether or not the user just left clicked on the world.

Example

if player:pointer_just_pressed() then
-- do something
end;

:pointer_just_released()

Returns whether or not the user just released left click from the world.

Example

if player:pointer_just_released() then
-- do something
end;

:pointer_pressed()

Returns whether or not the user is holding down left click on the world.

Example

if player:pointer_pressed() then
-- do something
end;

:pointer_locked()

Returns whether or not the user's pointer has been locked.

Example

if player:pointer_locked() then
-- do something
end;

:preferred_pointer_pos()

If grid is enabled, this returns the grid pointer pos. If CTRL is held, it'll invert the grid setting.

  • Grid On and CTRL not held → Snapped
  • Grid Off and CTRL not held → Normal
  • Grid On and CTRL held → Normal
  • Grid Off and CTRL held → Snapped

Example

if player:preferred_pointer_pos() then
-- do something
end;

:snap_if_preferred()

If grid is enabled, this returns the snapped position. If CTRL is held, it'll invert the grid setting.

  • Grid On and CTRL not held → Snapped
  • Grid Off and CTRL not held → Normal
  • Grid On and CTRL held → Normal
  • Grid Off and CTRL held → Snapped

Example

local snapped = player:snap_if_preferred(vec2(math.pi, 942.140513));

:snap_pointer_pos()

Snaps the provided position to the player's grid, regardless of whether or not grid is enabled.

Example

local snapped = player:snap_pointer_pos(vec2(math.pi, 942.140513));

:set_cursor()

Give it a string like umm these

  • "default"
  • "none"
  • "help"
  • "pointer"
  • "crosshair"
  • "move"
  • "grab"
  • "grabbing"

:get_selected_objects()

returns the umm


:get_selected_attachments()

gets umm


:set_selected_objects()

Replaces the reals


:set_selected_attachments()

Updates the fake


:clear_selection()

gone


:add_client_component()

Add a client component to the player? What?

These are NOT normal components like what we put on objects or attachments. These are sent to the player and they run on their device like tool code. This can be used to show UI to players.

-- no add_component_def or similar first, you just immediately add something
player:add_client_component({
id = "@handle/your_package/component_name_here",
name = "Component Name Here",

});

No return value for nows, imagine