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 21:40:54 +02:00
|
|
|
if not skins.textures[skin] then
|
2017-06-15 14:16:11 +02:00
|
|
|
skin = skins.default
|
2014-03-17 06:26:58 +01:00
|
|
|
end
|
2017-06-15 14:16:11 +02:00
|
|
|
return skin
|
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)
|
|
|
|
if skin == skins.default then
|
|
|
|
skin = ""
|
2014-07-23 13:46:42 +02:00
|
|
|
end
|
2017-06-15 14:16:11 +02:00
|
|
|
player:set_attribute("skin", skin)
|
|
|
|
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-15 16:16:57 +02:00
|
|
|
textures = {skins.textures[skin]},
|
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)
|
2017-06-15 16:37:43 +02:00
|
|
|
|
|
|
|
-- 3d_armor compatibility
|
|
|
|
if minetest.global_exists("armor") then
|
|
|
|
armor.get_player_skin = function(self, name)
|
|
|
|
return skins.get_player_skin(minetest.get_player_by_name(name))
|
|
|
|
end
|
|
|
|
armor.get_preview = function(self, name)
|
|
|
|
return skins.preview[skins.get_player_skin(minetest.get_player_by_name(name))]
|
|
|
|
end
|
|
|
|
end
|