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 |
Below you find short descriptions about each of the properties and some examples about how to use them in your spells.
This is this player’s game mode. It can be one of ‘survival’, ‘adventure’, ‘creative’, ‘spectator’.
Setting the gamemode of this spell’s owner to ‘adventure’.
spell.owner.gamemode = "adventure"
The ‘health’ is the energy of this entity. When it falls to zero this entity dies.
This is the item this entity is holding in its main hand.
This is the item this entity is holding in his off hand.
This is true if this player has operator privileges.
The ‘team’ is the name of the team this player belongs to, or nil if he is not a member of any team.
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
Printing the wizard’s team name.
print( spell.owner.team)