diff --git a/init.lua b/init.lua index a454d4c..9593fd6 100644 --- a/init.lua +++ b/init.lua @@ -27,6 +27,9 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_papi.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_tug.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_repair.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lua") +if player_api then + dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "pilot_skin_manager.lua") +end function airutils.remove(pos) local meta = core.get_meta(pos) diff --git a/mod.conf b/mod.conf index d0059ee..d8fb960 100644 --- a/mod.conf +++ b/mod.conf @@ -2,3 +2,4 @@ name = airutils title=AirUtils description=A lib for airplanes and some useful tools author=apercy +optional_depends=player_api diff --git a/pilot_skin_manager.lua b/pilot_skin_manager.lua new file mode 100644 index 0000000..bb1100e --- /dev/null +++ b/pilot_skin_manager.lua @@ -0,0 +1,98 @@ + +airutils.pilot_textures = {"pilot_clothes1.png","pilot_clothes2.png",} + +minetest.register_chatcommand("au_uniform", { + func = function(name, param) + if minetest.check_player_privs(name, {server=true}) then + local player = minetest.get_player_by_name(name) + if player then + airutils.uniform_formspec(name) + else + minetest.chat_send_player(name, "Something isn't working...") + end + end + end, +}) + +local set_player_textures = + minetest.get_modpath("player_api") and player_api.set_textures + or default.player_set_textures + +function airutils.set_player_skin(player, skin) + local backup = "airutils:bcp_last_skin" + local player_proterties = player:get_properties() + local texture = player_proterties.textures + local name = player:get_player_name() + if texture then + if skin then + texture = texture[1] + if player:get_attribute(backup) == nil or player:get_attribute(backup) == "" then + player:set_attribute(backup, texture) --texture backup + --minetest.chat_send_all(dump(player:get_attribute(backup))) + end + texture = texture.."^"..skin + if texture ~= nil and texture ~= "" then + set_player_textures(player, { texture }) + end + else + local old_texture = player:get_attribute(backup) + if set_skin then + if player:get_attribute("set_skin:player_skin") ~= nil then + old_texture = player:get_attribute("set_skin:player_skin") + end + elseif skins then + if skins.skins[name] ~= nil then + old_texture = skins.skins[name] + end + elseif u_skins then + if u_skins.u_skins[name] ~= nil then + old_texture = u_skins.u_skins[name] + end + elseif wardrobe then + if wardrobe.playerSkins then + if wardrobe.playerSkins[name] ~= nil then + old_texture = wardrobe.playerSkins[name] + end + end + end + --minetest.chat_send_all(dump(old_texture)) + if old_texture ~= nil and old_texture ~= "" then + set_player_textures(player, { old_texture }) + end + player:set_attribute(backup, nil) + end + end +end + +function airutils.uniform_formspec(name) + local basic_form = table.concat({ + "formspec_version[5]", + "size[5,2.9]", + }, "") + + --minetest.chat_send_all(dump(airutils.pilot_textures)) + + local textures = "" + if airutils.pilot_textures then + for k, v in pairs( airutils.pilot_textures ) do + textures = textures .. v .. "," + end + + basic_form = basic_form.."dropdown[0.5,0.5;4,0.8;textures;".. textures ..";0;false]" + basic_form = basic_form.."button[0.5,1.6;4,0.8;set_texture;Set Player Texture]" + + minetest.show_formspec(name, "airutils:change", basic_form) + else + minetest.chat_send_player(name, "The isn't activated as secure. Aborting") + end +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "airutils:change" then + local name = player:get_player_name() + if fields.textures or fields.set_texture then + airutils.set_player_skin(player, fields.textures) + end + minetest.close_formspec(name, "airutils:change") + end +end) diff --git a/textures/pilot_clothes1.png b/textures/pilot_clothes1.png new file mode 100755 index 0000000..034be20 Binary files /dev/null and b/textures/pilot_clothes1.png differ diff --git a/textures/pilot_clothes2.png b/textures/pilot_clothes2.png new file mode 100755 index 0000000..aa7f7fd Binary files /dev/null and b/textures/pilot_clothes2.png differ diff --git a/textures/pilot_phones.png b/textures/pilot_phones.png new file mode 100755 index 0000000..4b11e72 Binary files /dev/null and b/textures/pilot_phones.png differ