-
Notifications
You must be signed in to change notification settings - Fork 10
Obtaining a Placeholder's Value
skript-placeholders provides an expression to obtain the value of a placeholder from one or more players.
There are two patterns that can be used:
[the] [value of [the]] [relational] placeholder[s] [in] %strings% [(for|from|of) %-players/offlineplayers%]
[relational] placeholder[s] %strings%'[s] value [(for|from|of) %-players/offlineplayers%]
If you are unfamiliar with Skript patterns, these may not make much sense, but they can be easily simplified:
the value of the placeholder "<placeholder>" for <player>
placeholder "<placeholder>"'s value for <player>
While many placeholders require a player to use, some can have their value obtained for offline players. Additionally, some placeholders may not require a value at all. That is, they represent global values for the entire server.
Tip
The value of a placeholder is always a string (text).
If you need to use the value of a placeholder as something else, like a number or a boolean, you can use Skript's parse as
expression:
https://docs.skriptlang.org/expressions.html?search=#ExprParse
Let us say that there is a placeholder, skriptplaceholders_name
, that evaluates to the name of the player provided.
We could make a short command in Skript that makes use of this placeholder.
command /hello:
trigger:
# For MVDWPlaceholderAPI placeholders, the text must start and end with curly brackets ('{' and '})
# For example, instead of "skriptplaceholders_name" it would be "{skriptplaceholders_name}"
set {_value} to the value of the placeholder "skriptplaceholders_name" for the player
send "Hello, your name is %{_value}%" to the player
When executing this command in game, we can see it prints the expected message:
Important
At this time, the rest of this section does not apply for MVdWPlaceholderAPI placeholders.
We can take this a step further though. The expression allows us to format entire strings of text containing placeholders.
With this in mind, let us remake our /hello
command.
command /hello:
trigger:
send the value of the placeholder in "Hello, your name is %%skriptplaceholders_name%%" for the player to the player
Tip
While this line is rather long, you do not need to include all of these syntax options!
The same can be accomplished with writing:
send placeholders "Hello, your name is %%skriptplaceholders_name%%" for player
And, when executing it in game, we get the same result!
Note
Relational Placeholders are only available through PlaceholderAPI.
Important
Relational Placeholders always start with rel
.
Relational Placeholders are used to get the value of a placeholder when considering two players at the same time.
For example, let us say there is a relational placeholder, rel_skriptplaceholders_longer_name
, that evaluates to the name of the player with the longer name.
We could make a short command in Skript that makes use of this placeholder.
command /longername <player> <player>:
trigger:
set {_name} to the relational placeholder "rel_skriptplaceholders_longer_name" for arg-1 and arg-2
send "Longer Name: %{_name}%"
Unfortunately, I only have one account, so we will have to test what happens if a relational placeholder is evaluated when using the same player twice.
As you might be able to guess, the command gives this output:
There are a lot of different ways you can use placeholders in your scripts. You might send the values as messages, titles, or even use them for comparisons.
If you are looking to create your own placeholders, there is another guide linked on the main page on how to do so.