Compare commits
5 Commits
3aeb0bebbf
...
5b7393c350
Author | SHA1 | Date |
---|---|---|
|
5b7393c350 | |
|
37e78f7f86 | |
|
d8530ba1b3 | |
|
75c731179f | |
|
9f1cf8cfb2 |
|
@ -2,10 +2,7 @@ Player Hash Skin Mod for Minetest
|
|||
====================================
|
||||
|
||||
This mod calculates a hash code of a player's name and chooses a texture for him according to this hash code.
|
||||
There are 8 skins as default, you can change them by replacing player_hash_skin_<integer>.png with the skin you want.
|
||||
If you want more than 8 skins, change line 10 in init.lua:
|
||||
hash = hash%8 to hash = hash%<count of skins>
|
||||
and add additional skins to the textures folder.
|
||||
Eight default skins are shipped with the mod, you can add an arbitrary number of skins on your own by adding them to the textures folder. The simple_skins mod is supported and its skins will be used instead of the skins in the textures folder when it is detected.
|
||||
|
||||
|
||||
License of source code:
|
||||
|
|
20
init.lua
20
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 = 8
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue