2017-06-15 14:16:11 +02:00
|
|
|
-- get current skin
|
|
|
|
skins.get_player_skin = function(player)
|
|
|
|
local skin = player:get_attribute("skin")
|
2017-06-16 23:00:36 +02:00
|
|
|
return skins.get(skin) or skins.get(skins.default)
|
2014-03-17 06:26:58 +01:00
|
|
|
end
|
2014-07-23 13:46:42 +02:00
|
|
|
|
2017-06-15 14:16:11 +02:00
|
|
|
-- Set skin
|
|
|
|
skins.set_player_skin = function(player, skin)
|
2017-06-16 23:00:36 +02:00
|
|
|
local skin_obj
|
|
|
|
local skin_key
|
|
|
|
if type(skin) == "string" then
|
|
|
|
skin_obj = skins.get(skin) or skins.get(skins.default)
|
|
|
|
else
|
|
|
|
skin_obj = skin
|
|
|
|
end
|
|
|
|
skin_key = skin:get_meta("_key")
|
|
|
|
|
|
|
|
if skin_key == skins.default then
|
|
|
|
skin_key = ""
|
2014-07-23 13:46:42 +02:00
|
|
|
end
|
2017-06-16 23:00:36 +02:00
|
|
|
|
|
|
|
player:set_attribute("skin", skin_key)
|
2017-06-15 14:16:11 +02:00
|
|
|
skins.update_player_skin(player)
|
|
|
|
end
|
2014-03-17 06:26:58 +01:00
|
|
|
|
2017-06-15 14:16:11 +02:00
|
|
|
-- update visuals
|
|
|
|
skins.update_player_skin = function(player)
|
|
|
|
local skin = skins.get_player_skin(player)
|
|
|
|
player:set_properties({
|
2017-06-16 23:00:36 +02:00
|
|
|
textures = {skin:get_texture()},
|
2017-06-15 14:16:11 +02:00
|
|
|
})
|
2014-03-17 06:26:58 +01:00
|
|
|
end
|
|
|
|
|
2017-06-15 14:16:11 +02:00
|
|
|
-- Update skin on join
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
skins.update_player_skin(player)
|
|
|
|
end)
|