Skip to content

Instantly share code, notes, and snippets.

@indriApollo
Created June 30, 2015 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indriApollo/600e12cd54d5a5f8623b to your computer and use it in GitHub Desktop.
Save indriApollo/600e12cd54d5a5f8623b to your computer and use it in GitHub Desktop.
Adds multiskin support for wardrobe (replace existing init.lua with this code)
local MOD_NAME = minetest.get_current_modname();
local MOD_PATH = minetest.get_modpath(MOD_NAME);
local WORLD_PATH = minetest.get_worldpath();
if MOD_NAME ~= "wardrobe" then
error("mod directory must be named 'wardrobe'");
end
local armor_mod = false;
if minetest.get_modpath("3d_armor") then armor_mod = true; end;
wardrobe = {};
dofile(MOD_PATH.."/storage.lua");
dofile(MOD_PATH.."/wardrobe.lua");
wardrobe.storage.loadSkins();
wardrobe.storage.loadPlayerSkins();
local playerMesh = "character.b3d";
-- autodetect version of player mesh used by default
do
if default and default.registered_player_models then
local haveCharName = false; -- 'character.*' has priority
local name = nil;
local nNames = 0;
for k in pairs(default.registered_player_models) do
if string.find(k, "^character\\.[^\\.]+$") then
if haveCharName then nNames = 2; break; end;
name = k;
nNames = 1;
haveCharName = true;
elseif not haveCharName then
name = k;
nNames = nNames + 1;
end;
end;
if nNames == 1 then playerMesh = name; end;
end;
end;
function wardrobe.setPlayerSkin(player)
-- If 3d_armor is installed, let him set the model and textures
if armor_mod then return end
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end;
local skin = wardrobe.playerSkins[playerName];
if not skin or not wardrobe.skinNames[skin] then return; end;
player:set_properties(
{
visual = "mesh",
visual_size = { x = 1, y = 1 },
mesh = playerMesh,
textures = { skin }
});
end
function wardrobe.changePlayerSkin(playerName, skin)
local player = minetest.get_player_by_name(playerName);
if not player then
error("unknown player '"..playerName.."'");
return;
end
if skin and not wardrobe.skinNames[skin] then
error("unknown skin '"..skin.."'");
return;
end
wardrobe.playerSkins[playerName] = skin;
wardrobe.storage.savePlayerSkins();
-- If 3d_armor is installed, update the skin texture and the armor
if armor_mod then
if multiskin then --check if multiskin has been loaded by 3d_armor
--there should be a way to register a skin change instead of this hack
multiskin[playerName].skin = skin;
multiskin:update_player_visuals(player);
else
armor.textures[playerName].skin = skin;
armor:update_player_visuals(player);
end
else wardrobe.setPlayerSkin(player) end
end
minetest.register_on_joinplayer(
function(player)
minetest.after(1,
function(player)
wardrobe.setPlayerSkin(player);
end,
player);
end);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment