diff --git a/minetest.conf b/minetest.conf index 77e19f0..cbcc860 100644 --- a/minetest.conf +++ b/minetest.conf @@ -18,11 +18,14 @@ movement_liquid_sink = 11.0 movement_gravity = 9.4 # privs -default_privs = interact, shout, spawn, fast +default_privs = interact, shout, spawn, fast, player_skin # if you're given the inital stuff; a stone pick and 10 torches give_initial_stuff = false +# possible player skins; make sure they exist in the form "player_skins_[skin].png"! +player_skins_names = male,female + # if you drop items in your inventory when you die drop_items_on_die = true diff --git a/mods/armor/init.lua b/mods/armor/init.lua index 4f4807c..7b1c43c 100644 --- a/mods/armor/init.lua +++ b/mods/armor/init.lua @@ -44,6 +44,14 @@ function armor.is_slot(itemname, slot) return matchbool end +function armor.get_base_skin(player) + if minetest.get_modpath("player_skins") ~= nil then + return player_skins.get_skin(player:get_player_name()) + else + return armor.player_skin + end +end + function armor.get_texture(player, base) local inv = player:get_inventory() @@ -121,7 +129,7 @@ function armor.update(player) local groups = armor.get_groups(player) player:set_armor_groups({fleshy = groups.fleshy}) - local image = armor.get_texture(player, armor.player_skin) + local image = armor.get_texture(player, armor.get_base_skin(player)) if image ~= default.player_get_textures(player)[1] then default.player_set_textures(player, {image}) end diff --git a/mods/default/model.lua b/mods/default/model.lua index f49d29a..ae61ec2 100644 --- a/mods/default/model.lua +++ b/mods/default/model.lua @@ -72,7 +72,7 @@ function default.player_get_textures(player) if player.get_properties ~= nil then return player:get_properties().textures else - return {"character.png"} -- less efficient but will work + return player_textures[player:get_player_name()] end end diff --git a/mods/default/player.lua b/mods/default/player.lua index 1705e18..b8d3e71 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -128,7 +128,7 @@ minetest.register_chatcommand( { params = "[on|off|cinematic]", description = "Set Uberspeed", - privs = {weather = true}, + privs = {uberspeed = true}, func = function(name, param) local player=minetest.get_player_by_name(name) diff --git a/mods/mobs/textures/mobs_npc1.png b/mods/mobs/textures/mobs_npc1.png index cd6d1d1..afacd03 100644 Binary files a/mods/mobs/textures/mobs_npc1.png and b/mods/mobs/textures/mobs_npc1.png differ diff --git a/mods/mobs/textures/mobs_npc1.xcf b/mods/mobs/textures/mobs_npc1.xcf index 2860c55..e9199a0 100644 Binary files a/mods/mobs/textures/mobs_npc1.xcf and b/mods/mobs/textures/mobs_npc1.xcf differ diff --git a/mods/mobs/textures/mobs_npc2.png b/mods/mobs/textures/mobs_npc2.png index a1e4046..6c29a63 100644 Binary files a/mods/mobs/textures/mobs_npc2.png and b/mods/mobs/textures/mobs_npc2.png differ diff --git a/mods/mobs/textures/mobs_npc2.xcf b/mods/mobs/textures/mobs_npc2.xcf index b877950..b182ca6 100644 Binary files a/mods/mobs/textures/mobs_npc2.xcf and b/mods/mobs/textures/mobs_npc2.xcf differ diff --git a/mods/player_skins/README.txt b/mods/player_skins/README.txt new file mode 100644 index 0000000..78c7c73 --- /dev/null +++ b/mods/player_skins/README.txt @@ -0,0 +1,8 @@ +Player skins mod +================ +By Kaadmy, for Pixture + +Adds changeable player skins + +Asset license: WTFPL +Source license: WTFPL diff --git a/mods/player_skins/depends.txt b/mods/player_skins/depends.txt new file mode 100644 index 0000000..b7cc57f --- /dev/null +++ b/mods/player_skins/depends.txt @@ -0,0 +1,2 @@ +default +util diff --git a/mods/player_skins/init.lua b/mods/player_skins/init.lua new file mode 100644 index 0000000..52cee43 --- /dev/null +++ b/mods/player_skins/init.lua @@ -0,0 +1,134 @@ +-- +-- Player skins mod +-- By Kaadmy, for Pixture +-- + +player_skins = {} + +player_skins.skin_names = {"male", "female"} +if minetest.setting_get("player_skins_names") then + player_skins.skin_names = util.split(minetest.setting_get("player_skins_names"), ",") +end + +player_skins.old_skins = {} +player_skins.skins = {} + +local update_time = 1 +local timer = 10 +local skins_file = minetest.get_worldpath() .. "/player_skins" + +local function save_skins() + local f = io.open(skins_file, "w") + + for name, tex in pairs(player_skins.skins) do + f:write(name .. " " .. tex .. "\n") + end + + io.close(f) +end + +local function load_skins() + local f = io.open(skins_file, "r") + + if f then + repeat + local l = f:read("*l") + if l == nil then break end + + for name, tex in string.gfind(l, "(.+) (.+)") do + player_skins.skins[name] = tex + end + until f:read(0) == nil + + io.close(f) + else + save_skins() + end +end + +local function is_valid_skin(tex) + for _, n in pairs(player_skins.skin_names) do + if n == tex then + return true + end + end + + return false +end + +function player_skins.get_skin(name) + return "player_skins_" .. player_skins.skins[name] .. ".png" +end + +function player_skins.set_skin(name, tex) + if minetest.check_player_privs(name, {player_skin = true}) then + if is_valid_skin(tex) then + player_skins.skins[name] = tex + save_skins() + else + minetest.chat_send_player(name, "Invalid skin") + end + else + minetest.chat_send_player(name, "You do not have the privilege to change your skin.") + end +end + +local function step(dtime) + timer = timer + dtime + if timer > update_time then + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + + if player_skins.skins[name] ~= player_skins.old_skins[name] then + default.player_set_textures(player, {"player_skins_" .. player_skins.skins[name] .. ".png"}) + player_skins.old_skins[name] = player_skins.skins[name] + end + end + timer = 0 + end +end + +local function on_joinplayer(player) + local name = player:get_player_name() + + if player_skins.skins[name] == nil then + player_skins.skins[name] = "male" + end +end + +minetest.register_globalstep(step) +minetest.register_on_joinplayer(on_joinplayer) + +local function get_chatparams() + local s = "[" + + for _, n in pairs(player_skins.skin_names) do + if s == "[" then + s = s .. n + else + s = s .. "|" .. n + end + end + + return s .. "]" +end + +minetest.register_privilege("player_skin", "Can change player skin") +minetest.register_chatcommand( + "player_skin", + { + params = get_chatparams(), + description = "Set your player skin", + privs = {player_skin = true}, + func = function(name, param) + if is_valid_skin(param) then + player_skins.set_skin(name, param) + elseif param == "" then + minetest.chat_send_player(name, "Current player skin: " .. player_skins.skins[name]) + else + minetest.chat_send_player(name, "Bad param for /player_skin; type /help player_skin") + end + end + }) + +minetest.after(1.0, load_skins) \ No newline at end of file diff --git a/mods/player_skins/textures/player_skins_female.png b/mods/player_skins/textures/player_skins_female.png new file mode 100644 index 0000000..6c29a63 Binary files /dev/null and b/mods/player_skins/textures/player_skins_female.png differ diff --git a/mods/player_skins/textures/player_skins_female.xcf b/mods/player_skins/textures/player_skins_female.xcf new file mode 100644 index 0000000..b182ca6 Binary files /dev/null and b/mods/player_skins/textures/player_skins_female.xcf differ diff --git a/mods/player_skins/textures/player_skins_male.png b/mods/player_skins/textures/player_skins_male.png new file mode 100644 index 0000000..afacd03 Binary files /dev/null and b/mods/player_skins/textures/player_skins_male.png differ diff --git a/mods/player_skins/textures/player_skins_male.xcf b/mods/player_skins/textures/player_skins_male.xcf new file mode 100644 index 0000000..e9199a0 Binary files /dev/null and b/mods/player_skins/textures/player_skins_male.xcf differ diff --git a/mods/util/init.lua b/mods/util/init.lua index 4c67b6b..bec25ea 100644 --- a/mods/util/init.lua +++ b/mods/util/init.lua @@ -167,3 +167,23 @@ function util.choice_element(tab, pr) end end +-- util.split function taken from a StackOverflow answer. +-- http://stackoverflow.com/questions/12709205/split-a-string-and-store-in-an-array-in-lua +function util.split(str, tok) + -- Source: http://lua-users.org/wiki/MakingLuaLikePhp + -- Credit: http://richard.warburton.it/ + + if not tok then return {} end + + local pos = 0 + local arr = {} + + for st, sp in function() return string.find(str, tok, pos, true) end do + table.insert(arr, string.sub(str, pos, st - 1)) + pos = sp + 1 + end + + table.insert(arr, string.sub(str, pos)) + + return arr +end \ No newline at end of file