summaryrefslogtreecommitdiff
path: root/players.lua
blob: 5b161bd443de4d4598f64d518ef0cf337f84d112 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- get current skin
skins.get_player_skin = function(player)
	local skin = player:get_attribute("skin")
	if not skins.is_skin(skin) then
		skin = skins.default
	end
	return skin
end

-- Set skin
skins.set_player_skin = function(player, skin)
	if skin == skins.default then
		skin = ""
	end
	player:set_attribute("skin", skin)
	skins.update_player_skin(player)
end

-- update visuals
skins.update_player_skin = function(player)
	local skin = skins.get_player_skin(player)
	player:set_properties({
		textures = {skins.textures[skin]},
	})
end

-- Update skin on join
minetest.register_on_joinplayer(function(player)
	skins.update_player_skin(player)
end)

-- 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