Wizards of Lua

The Art of Spell Crafting


Player - Controlling the Player

An instance of the Player class represents a specific player who is currently logged into the world.

The Player class is a subtype of the Entity class and inherits all its properties and functions.

Here is an overview of the Player properties:

Property Type read / write
gamemode string r/w
health number (float) r/w
mainhand Item r/w
offhand Item r/w
operator boolean r
team string r/w

Properties

Below you find short descriptions about each of the properties and some examples about how to use them in your spells.


gamemode : string

This is this player’s game mode. It can be one of ‘survival’, ‘adventure’, ‘creative’, ‘spectator’.

Example

Setting the gamemode of this spell’s owner to ‘adventure’.

spell.owner.gamemode = "adventure"

health : number (float)

The ‘health’ is the energy of this entity. When it falls to zero this entity dies.


mainhand : Item

This is the item this entity is holding in its main hand.


offhand : Item

This is the item this entity is holding in his off hand.


operator : boolean

This is true if this player has operator privileges.


team : string

The ‘team’ is the name of the team this player belongs to, or nil if he is not a member of any team.

Example

Adding the wizard to the ‘rogues’ team.

spell.owner.team = "rogues"

To make this work, don’t forget to create the ‘rogues’ team first:

/scoreboard teams add rogues

Example

Printing the wizard’s team name.

print( spell.owner.team)