diff --git a/init.lua b/init.lua index 4684709..67dd87f 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,12 @@ -minetest.register_on_joinplayer(function(player) +minetest.register_on_newplayer(function(player) + -- Return if skin tables not defined + if not ( skins and skins.skins ) then return end local name = player:get_player_name() + -- Return if skin was already set for this player + if skins.skins[name] then return end local len = string.len(name) local hash = 0 + local max_skin_count = tonumber(minetest.settings:get("player_hash_skin.max_count")) or 200 local h = {} -- prefix of textures files @@ -10,8 +15,6 @@ minetest.register_on_joinplayer(function(player) h.smodpath = minetest.get_modpath("player_hash_skin") -- start count of texture files h.s = 0 - -- number of texture file - h.n = -1 for i = 1, len, 1 do hash = hash+(string.byte(name,i)) @@ -32,6 +35,7 @@ minetest.register_on_joinplayer(function(player) h.n = h.s local fp while true do + if h.n == max_skin_count then break end fp = io.open(h.smodpath .. "/textures/".. h.sprefix ..h.n.. ".png") if not fp then break end fp:close() @@ -53,7 +57,13 @@ minetest.register_on_joinplayer(function(player) if f then f:close() - local img = h.sprefix.."%i.png" - default.player_set_textures(player, {string.format(img, hash)}) + if skinmod then + local skin_name = h.sprefix..hash + skins.skins[name] = skin_name + player:set_attribute("simple_skins:skin", skins.skins[name]) + else + local img = h.sprefix.."%i.png" + default.player_set_textures(player, {string.format(img, hash)}) + end end end)