Compare commits

...

5 Commits

Author SHA1 Message Date
xisd 5b7393c350 prevent texture reset if changed by other mod 2019-05-02 07:08:54 +02:00
xisd 37e78f7f86 Merge pull request #1 from Hiradur/master
update from original
2016-12-31 16:54:53 +01:00
Hiradur d8530ba1b3 Update README.txt
Arbitrary number of texture files now supported as well as the simple_skins mod
2016-10-10 11:32:43 +02:00
Hiradur 75c731179f Merge pull request #1 from xisd/patch-1
Support arbitrary number of texture files and add support for simple_skins mod
2016-10-10 11:28:26 +02:00
xisd 9f1cf8cfb2 Update init.lua 2016-10-10 00:54:25 +02:00
2 changed files with 16 additions and 9 deletions

View File

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

View File

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