mirror of
https://github.com/mt-mods/homedecor_modpack.git
synced 2024-12-23 00:20:17 +01:00
load skin when player has joined the game
This commit is contained in:
parent
ac10702849
commit
cafba3bc53
@ -16,6 +16,10 @@ local armor_mod_path = minetest.get_modpath("3d_armor")
|
||||
local skins = {"male1", "male2", "male3", "male4", "male5"}
|
||||
|
||||
local function set_player_skin(player, skin)
|
||||
minetest.log("verbose",
|
||||
S("player @1 sets skin to @2", player:get_player_name(), skin) ..
|
||||
(armor_mod_path and ' [armor]' or '')
|
||||
)
|
||||
if armor_mod_path then -- if 3D_armor's installed, let it set the skin
|
||||
armor.textures[player:get_player_name()].skin = skin
|
||||
armor:update_player_visuals(player)
|
||||
@ -64,9 +68,11 @@ homedecor.register("wardrobe", {
|
||||
for i = 1,5 do
|
||||
if fields[skins[i]] then
|
||||
set_player_skin(sender, "homedecor_clothes_"..skins[i]..".png")
|
||||
sender:set_attribute("homedecor:player_skin", "homedecor_clothes_"..skins[i]..".png")
|
||||
break
|
||||
elseif fields["fe"..skins[i]] then
|
||||
set_player_skin(sender, "homedecor_clothes_fe"..skins[i]..".png")
|
||||
sender:set_attribute("homedecor:player_skin", "homedecor_clothes_fe"..skins[i]..".png")
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -75,3 +81,22 @@ homedecor.register("wardrobe", {
|
||||
|
||||
minetest.register_alias("homedecor:wardrobe_bottom", "homedecor:wardrobe")
|
||||
minetest.register_alias("homedecor:wardrobe_top", "air")
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local skin = player:get_attribute("homedecor:player_skin")
|
||||
if skin ~= nil then
|
||||
-- setting player skin on connect has no effect, so queue skin change for next game step
|
||||
table.insert(skin_updates, {player, skin})
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
-- if skin update queue is filled
|
||||
if #skin_updates > 0 then
|
||||
-- update player skins
|
||||
for _,u in pairs(skin_updates) do
|
||||
set_player_skin(u[1], u[2])
|
||||
end
|
||||
skin_updates = {} -- empty queue
|
||||
end
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user