Skin¶
Represents the skin of a player, as the game draws it: the look of one Minecraft account at one moment.
A skin stays what it is. It shows the picture the account had when the skin was taken, whatever that account wears later. So a spell can keep a skin, in a variable or in a file, and put it on any player or bot any time later, at once and without asking Mojang again.
-
Look up the skin of an account with
Skin:lookup. -
Take the skin a player wears from
Player.skin, and put one on by assigning it there. -
Give a bot a skin with the option
skinofBot:spawn. -
Save a skin to a file with
save, and load it later withSkin:load.
A default skin, like Steve or Alex, is no Skin: the game draws one for a player who has no
skin of their own, and picks which by the player's UUID. Player.skin is nil then.
A skin can't be made from a picture: it is signed by Mojang, and the game ignores a skin without that signature. To get a picture of your own as a skin, wear it with a Minecraft account first, and look it up from there. The players still need internet access to see a skin: the game loads its picture from Mojang, as it does for every skin.
Example: Keep a skin, and give it to a bot later
local skin = Skin:lookup("jeb_")
if skin then
skin:save("skin/guard.json")
end
-- Later, or in another spell:
local guard = Skin:load("skin/guard.json")
local bot = Bot:spawn("Guard", spell.pos, { skin = guard })
Fields¶
account: string? — Read-Only¶
The name of the account the skin comes from, spelled as that account spells it.
Methods¶
load(path: string) → skin: Skin¶
Loads a skin from a file that save wrote. Call it on the class: Skin:load(path). Raises an
error if there is no such file, or it holds no skin.
Example: Load a skin and put it on
Parameters
- path: string — The path of the file, relative to the world folder, like "skin/guard.json".
Returns
- skin: Skin — The loaded skin.
lookup(account: string, timeout?: number) → skin: Skin?, reason: SkinReason?¶
Looks up the skin that the account with the given name wears now, at Mojang. Call it on the
class: Skin:lookup(account).
This needs internet access, and the function waits until the answer arrives, usually less than a second, or until the timeout. Because it waits, it can't be called in an event interceptor. Answers are remembered for some minutes, so the same account again comes at once.
Example
local skin, reason = Skin:lookup("jeb_")
if skin then
spell.owner.skin = skin
else
print("No skin: " .. reason)
end
Parameters
- account: string — The name of the account, like "jeb_". Upper and lower case make no difference.
- timeout?: number — The most ticks to wait, an integer. Defaults to waiting until the lookup ends.
Returns
- skin: Skin? — The skin, or
nilif there is none. - reason: SkinReason? — Why there is no skin.
save(path: string)¶
Saves the skin to a file, replacing a file that is there already, and makes the folders the
path names. Skin:load loads it again, also after a restart of the server.
The path is relative to the world folder, as for the spell's io functions, and must stay
inside it. Any path will do; "skin/guard.json" is a good choice.
Example: Save the skin a player wears
Parameters
- path: string — The path of the file, relative to the world folder.