π Player API¶
In Pier, a "player object" finds one player and acts on them or reads about them.
Getting a player object¶
From an event¶
Subscribe to an event and take the player from its payload: the _player field holds their name, XUID and UUID. See Events and the event payload reference.
By name, XUID or UUID¶
Player::by_name(name)
levilamina.PlayerByName(name)
levilamina.Player.byName(name)
Builds a player object from what you know of the player. For an XUID or UUID, Rust has by_xuid and by_uuid, Go PlayerByXuid and PlayerByUuid, Zig byXuid and byUuid.
- Parameters:
- name : string
the player's name (or XUID, UUID)
- name : string
- Return value: a player object
- Return type:
Player- Creating the object does not check that the player is online; the calls do. To check first, see "Is the player online" below.
-
Example:
- Rust
- Go
- Zig
Identify players by XUID
After a player renames, someone else can register the old name. If permissions, money or land ownership are decided by name, whoever takes the name is treated as the player who had it. Decide those by XUID.
Every player online¶
Player::list()
levilamina.ListPlayers()
levilamina.slot("list_players")
Returns every player on the server, each with name, XUID, UUID, and dimension and position.
- Return value: the list of players online
- Return type: Rust
Vec<PlayerInfo>, Go[]PlayerInfo, Zig one SNBT per player - Slot:
list_players -
Example:
- Rust
- Go
Go - Zig
Note: don't keep player information around
A player object holds only a name, XUID or UUID, and Pier looks the player up again on every call, so keeping the object is fine. The position and dimension a call such as Player::list() returns are as they were at that moment, and go stale as the player moves; read them again when you need them.
Player object: properties¶
Level, experience, hunger, game modeβ¦ these are the player's "properties". In Go and Zig every PIER_PPROP_* (number) and PIER_PSTR_* (text) of abi.h has a method of its name, and a writable one a Setβ¦. The common ones:
| Property | Rust | Go | Zig | Type |
|---|---|---|---|---|
| Level | num(PIER_PPROP_LEVEL), set_level(n) |
Level(), SetLevel(n) |
level(), setLevel(n) |
number, writable |
| Experience progress | num(PIER_PPROP_EXPERIENCE), set_experience(p) |
Experience(), SetExperience(p) |
experience(), setExperience(p) |
0 to 1, writable |
| Game mode | game_type() |
GameType() |
gameType() |
number |
| Real name | text(PIER_PSTR_REAL_NAME) |
RealName() |
realName(allocator) |
text |
A read that fails returns an error. Slots: player_get_num, player_set_num, player_get_str.
Player object: functions¶
Every player object has these functions; steve stands for the player object you hold.
Is the player online¶
steve.is_online()
steve.IsOnline()
levilamina.slot("player_resolve")
- Return value: whether the player is online
- Return type:
bool- Every ABI v2 host provides this slot, so
falsemeans nobody online matches.
- Every ABI v2 host provides this slot, so
- Slot:
player_resolve -
Example:
- Rust
- Go
- Zig
Sending a player a message¶
steve.send_message(msg)
steve.SendMessage(msg)
levilamina.slot("player_send_message")
- Parameters:
- msg : string
the text to send
- msg : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool(success) - Slot:
player_send_message -
Example:
- Rust
Rust - Go
Go - Zig
Broadcasting a message to everyone¶
Player::broadcast(msg)
levilamina.Broadcast(msg)
levilamina.slot("broadcast_message")
- Parameters:
- msg : string
the text to broadcast
- msg : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror - Slot:
broadcast_message -
Example:
- Rust
Rust - Go
Go - Zig
Showing a title¶
steve.set_title(text)
steve.SendTitle(slot, text, fadeIn, stay, fadeOut)
levilamina.slot("player_send_title")
Shows a line in the middle of the screen. Rust also has set_subtitle, set_actionbar and clear_title; Go and Zig choose the place with the first argument.
- Parameters:
- slot : integer
(Go, Zig) 0 title, 1 subtitle, 2 action bar - text : string
the text to show - fadeIn, stay, fadeOut : integer
(Go, Zig) fade-in, stay and fade-out in game ticks
- slot : integer
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool - Slot:
player_send_title -
Example:
- Rust
- Go
Go - Zig
Teleporting a player¶
steve.teleport(dim, x, y, z)
steve.Teleport(dim, x, y, z)
levilamina.slot("player_teleport")
- Parameters:
- dim : integer
the dimension: 0 overworld, 1 nether, 2 end; a custom dimension's id comes from the dimension API - x, y, z : number
the position
- dim : integer
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool - Slot:
player_teleport -
Example:
- Rust
Rust - Go
Go - Zig
Setting a player's level¶
steve.set_level(level)
steve.SetLevel(level)
steve.setLevel(level)
- Parameters:
- level : integer (a number in Go and Zig)
the new level
- level : integer (a number in Go and Zig)
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Ziglevilamina.Error!void- The level changes through the game's own level change, as when a player levels up, so the related display and events update.
- Slot:
player_set_num -
Example:
- Rust
Rust - Go
Go - Zig
Zig
Setting a player's game mode¶
steve.set_gamemode(mode)
steve.SetGameType(mode)
levilamina.slot("player_set_gamemode")
- Parameters:
- mode : Rust
GameMode, Go and Zig an integer
0 survival, 1 creative, 2 adventure, 6 spectator
- mode : Rust
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool - Slot:
player_set_gamemode -
Example:
- Rust
Rust - Go
Go - Zig
Removing a player from the server¶
steve.disconnect(reason)
steve.Disconnect(reason)
levilamina.slot("player_disconnect")
- Parameters:
- reason : string
the reason the player sees
- reason : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool - Slot:
player_disconnect -
Example:
- Rust
Rust - Go
Go - Zig
The item in hand¶
steve.carried_item()
steve.CarriedItem()
levilamina.slot("player_get_carried_item")
- Return value: the item in the player's main hand
- Return type: Rust
Result<ItemStack>, Go(Item, error), Zig the item's SNBT- The item is a snapshot of that moment; see Items and containers.
- Slot:
player_get_carried_item -
Example:
- Rust
Rust - Go
Go - Zig
The player's inventory¶
steve.inventory()
steve.Inventory()
c.PierContainerRef{ .which = 0, ... }
The ender chest, armor and offhand: Rust has ender_chest, armor and offhand_container, Go EnderChest, Armor and Offhand.
- Return value: the inventory as a container; see Items and containers
- Return type:
Container -
Example:
- Rust
- Go
Giving a player an item¶
steve.give_item(&item)
steve.GiveItem(item.SNBT, 0, 0, 0)
steve.giveItem(allocator, snbt, 0, 0, 0)
- Parameters:
- item : item
the item to give; see Items and containers
- item : item
- Return value: nothing on success
- Return type: Rust
Result<()>, Go(string, error), Ziglevilamina.Error![]u8 - Slot:
player_action -
Example:
- Rust
- Go
Go - Zig
Zig