Player Utilities


These functions are helpful for dealing with player objects, and mostly cover gaps in the existing API.

MISC. FUNCTIONS

Helpers that add functionality which isn't in the Lua API but should be.

etc.get_player_range

Usage: etc.get_player_range(player)
 Returns the current interaction range of the player. This is calculated from the range property of either the player's wielded item or their hand. If neither are set, returns 4.

etc.get_player_pointed_thing

Usage: etc.get_player_pointed_thing(player, objects, liquids)
 Returns the current 'thing' the player is pointing at, using their current interaction range. objects and liquids are booleans; set them to determine if the player can point those things. The return value of this function will be equivalent to the pointed_thing provided in, for example, node callbacks.

etc.set_player_look_dir

Usage: etc.set_player_look_dir(player, dir)
 Rotate's the player's camera to look in the direction specified by dir. The direction should be a vector denoting a point on the surface of a sphere, much like the one returned by player: get_look_dir. It does not need to be a unit vector; this function will normalize its' input.

SITTING

This system allows mod developers to easily make players 'sit' at a position, which will render them unable to move until: When a player leaves the sitting state, they will return to the position they were at before they sat.
'Sitting' players will also be given the sit animation if player_api is installed.

etc.set_sitting

Usage: etc.set_sitting(player[, pos])
 If pos is a vector, the player will sit down exactly at pos. If pos is nil or false, the sitting state will be cancelled and the player will return to their original position.

etc.get_sitting

Usage: etc.get_sitting(player)
 Returns true if the player is currently sitting.