User

User

The User entity Each player who connects to a Foundry Virtual Tabletop session is a User. Users represent human beings (or possibly programmatic players) and are the cornerstone of identity in Foundry VTT.

Constructor

new User(data, options)

Source:
Parameters:
Name Type Description
data Object

The source data for the User entity, usually retrieved from the database.

Properties
Name Type Description
_id string

The Entity ID, automatically generated by the Database when a new User is created.

password string

An access key for the Entity.

role number

The role level for the User, from CONST.USER_ROLES

permissions Object

An object of key-value permissions for the User which extend the default functionality of the User's role.

avatar string

A web-accessible file path to an avatar image used to represent the User.

character string

The _id of the Actor entity that the User has chosen as their primary character.

color string

A color string which represents the visual color associated with this particular User.

flags Object

A free-form object of key-value pairs which allows modules and systems the ability to store arbitrary data as part of the User object.

options Object

Initialization options which modify the construction of a User entity. See the Entity class for more detail.

Members

(static) config

Source:

active :boolean

Source:

Track whether the user is currently active in the game

Type:
  • boolean

avatar :String

Source:

Return the User avatar icon or the controlled actor's image

Type:

character :Actor

Source:

Return the Actor instance of the user's impersonated character (or undefined)

Type:

isGM

Source:

A flag for whether the current User has Assistant GameMaster or full GameMaster role

isSelf

Source:

A flag for whether this User is the connected client

isTrusted

Source:

A flag for whether the current User is a Trusted Player

permission

Source:
Deprecated:
  • Yes

permissions :Object

Source:

A convenience shortcut for the permissions object of the current User

Type:
  • Object

targets :Set.<Token>

Source:

Track references to the current set of Tokens which are targeted by the User

Type:

viewedScene :string|null

Source:

Track the ID of the Scene that is currently being viewed by the User

Type:
  • string | null

Methods

_onCreate()

Source:

(async) assignHotbarMacro(macro, slot, fromSlotopt) → {Promise}

Source:

Assign a Macro to a numbered hotbar slot between 1 and 50

Parameters:
Name Type Attributes Description
macro Macro | null

The Macro entity to assign

slot number

The integer Hotbar slot to fill

fromSlot number <optional>

An optional origin slot from which the Macro is being shifted

Returns:

A Promise which resolves once the User update is complete

Type
Promise

broadcastActivity(activityData)

Source:

Submit User activity data to the server for broadcast to other players. This type of data is transient, persisting only for the duration of the session and not saved to any database.

Parameters:
Name Type Description
activityData Object

An object of User activity data to submit to the server for broadcast.

Properties
Name Type Description
cursor Object

The coordinates of the user's cursor

focus boolean

Is the user pulling focus to the cursor coordinates?

ping boolean

Is the user emitting a ping at the cursor coordinates?

ruler string

Serialized Ruler coordinate data in JSON format

sceneId string

The id of the Scene currently being viewed by the User

targets Array

An id of Token ids which are targeted by the User

getHotbarMacros(page) → {Array.<Object>}

Source:

Get an Array of Macro Entities on this User's Hotbar by page

Parameters:
Name Type Default Description
page number 1

The hotbar page number

Returns:
Type
Array.<Object>

hasPermission(permissionName) → {boolean}

Source:

Test whether the User has at least a specific permission

Parameters:
Name Type Description
permissionName string

The permission name from USER_PERMISSIONS to test

Returns:

Does the user have at least this permission

Type
boolean

hasRole(role) → {boolean}

Source:

Test whether the User has at least the permission level of a certain role

Parameters:
Name Type Description
role string | number

The role name from USER_ROLES to test

Returns:

Does the user have at least this role level?

Type
boolean

isRole(role) → {boolean}

Source:

Test whether the User has exactly the permission level of a certain role

Parameters:
Name Type Description
role string | number

The role name from USER_ROLES to test

Returns:

Does the user have exactly this role level?

Type
boolean

setPermission(permission, allowed)

Source:

Sets a user's permission Modifies the user permissions to grant or restrict access to a feature.

Parameters:
Name Type Description
permission String

The permission name from USER_PERMISSIONS

allowed Boolean

Whether to allow or restrict the permission