add player skins and use new npc textures
This commit is contained in:
parent
788698d229
commit
3ba2eaea20
@ -18,11 +18,14 @@ movement_liquid_sink = 11.0
|
|||||||
movement_gravity = 9.4
|
movement_gravity = 9.4
|
||||||
|
|
||||||
# privs
|
# 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
|
# if you're given the inital stuff; a stone pick and 10 torches
|
||||||
give_initial_stuff = false
|
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
|
# if you drop items in your inventory when you die
|
||||||
drop_items_on_die = true
|
drop_items_on_die = true
|
||||||
|
|
||||||
|
@ -44,6 +44,14 @@ function armor.is_slot(itemname, slot)
|
|||||||
return matchbool
|
return matchbool
|
||||||
end
|
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)
|
function armor.get_texture(player, base)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
@ -121,7 +129,7 @@ function armor.update(player)
|
|||||||
local groups = armor.get_groups(player)
|
local groups = armor.get_groups(player)
|
||||||
player:set_armor_groups({fleshy = groups.fleshy})
|
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
|
if image ~= default.player_get_textures(player)[1] then
|
||||||
default.player_set_textures(player, {image})
|
default.player_set_textures(player, {image})
|
||||||
end
|
end
|
||||||
|
@ -72,7 +72,7 @@ function default.player_get_textures(player)
|
|||||||
if player.get_properties ~= nil then
|
if player.get_properties ~= nil then
|
||||||
return player:get_properties().textures
|
return player:get_properties().textures
|
||||||
else
|
else
|
||||||
return {"character.png"} -- less efficient but will work
|
return player_textures[player:get_player_name()]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ minetest.register_chatcommand(
|
|||||||
{
|
{
|
||||||
params = "[on|off|cinematic]",
|
params = "[on|off|cinematic]",
|
||||||
description = "Set Uberspeed",
|
description = "Set Uberspeed",
|
||||||
privs = {weather = true},
|
privs = {uberspeed = true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player=minetest.get_player_by_name(name)
|
local player=minetest.get_player_by_name(name)
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
8
mods/player_skins/README.txt
Normal file
8
mods/player_skins/README.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Player skins mod
|
||||||
|
================
|
||||||
|
By Kaadmy, for Pixture
|
||||||
|
|
||||||
|
Adds changeable player skins
|
||||||
|
|
||||||
|
Asset license: WTFPL
|
||||||
|
Source license: WTFPL
|
2
mods/player_skins/depends.txt
Normal file
2
mods/player_skins/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
default
|
||||||
|
util
|
134
mods/player_skins/init.lua
Normal file
134
mods/player_skins/init.lua
Normal file
@ -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)
|
BIN
mods/player_skins/textures/player_skins_female.png
Normal file
BIN
mods/player_skins/textures/player_skins_female.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
mods/player_skins/textures/player_skins_female.xcf
Normal file
BIN
mods/player_skins/textures/player_skins_female.xcf
Normal file
Binary file not shown.
BIN
mods/player_skins/textures/player_skins_male.png
Normal file
BIN
mods/player_skins/textures/player_skins_male.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
mods/player_skins/textures/player_skins_male.xcf
Normal file
BIN
mods/player_skins/textures/player_skins_male.xcf
Normal file
Binary file not shown.
@ -167,3 +167,23 @@ function util.choice_element(tab, pr)
|
|||||||
end
|
end
|
||||||
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
|
Loading…
Reference in New Issue
Block a user