1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-16 23:40:31 +01:00

Updated 3d_armor and added a security if statement

- Added security if statement in 3d_armor/3d_armor/armor.lua:~464 to prevent
  crash if `armor_inv` is nil (thanks crabman for reporting)
- Updated 3d_armor (better use of skin and skin mods)
This commit is contained in:
LeMagnesium 2015-03-18 18:28:56 +01:00
parent fef3b0d8c6
commit 4812003da0

View File

@ -82,6 +82,14 @@ elseif minetest.get_modpath("unified_inventory") then
}) })
end end
if minetest.get_modpath("skins") then
skin_mod = "skins"
elseif minetest.get_modpath("simple_skins") then
skin_mod = "simple_skins"
elseif minetest.get_modpath("u_skins") then
skin_mod = "u_skins"
end
armor.def = { armor.def = {
state = 0, state = 0,
count = 0, count = 0,
@ -124,7 +132,7 @@ armor.set_player_armor = function(self, player)
local textures = {} local textures = {}
local physics_o = {speed=1,gravity=1,jump=1} local physics_o = {speed=1,gravity=1,jump=1}
local material = {type=nil, count=1} local material = {type=nil, count=1}
local preview = armor:get_player_skin(name).."_preview.png" local preview = armor:get_preview(name) or "character_preview.png"
for _,v in ipairs(self.elements) do for _,v in ipairs(self.elements) do
elements[v] = false elements[v] = false
end end
@ -257,7 +265,7 @@ end
armor.get_player_skin = function(self, name) armor.get_player_skin = function(self, name)
local skin = nil local skin = nil
if skin_mod == "skins" then if skin_mod == "skins" or skin_mod == "simple_skins" then
skin = skins.skins[name] skin = skins.skins[name]
elseif skin_mod == "u_skins" then elseif skin_mod == "u_skins" then
skin = u_skins.u_skins[name] skin = u_skins.u_skins[name]
@ -265,6 +273,12 @@ armor.get_player_skin = function(self, name)
return skin or armor.default_skin return skin or armor.default_skin
end end
armor.get_preview = function(self, name)
if skin_mod == "skins" then
return armor:get_player_skin(name).."_preview.png"
end
end
armor.get_armor_formspec = function(self, name) armor.get_armor_formspec = function(self, name)
if not name then if not name then
minetest.log("error", "3d_armor: Player name is nil [get_armor_formspec]") minetest.log("error", "3d_armor: Player name is nil [get_armor_formspec]")
@ -417,20 +431,17 @@ minetest.register_on_joinplayer(function(player)
wielditem = "3d_armor_trans.png", wielditem = "3d_armor_trans.png",
preview = armor.default_skin.."_preview.png", preview = armor.default_skin.."_preview.png",
} }
if minetest.get_modpath("skins") then if skin_mod == "skins" then
skin_mod = "skins"
local skin = skins.skins[name] local skin = skins.skins[name]
if skin and skins.get_type(skin) == skins.type.MODEL then if skin and skins.get_type(skin) == skins.type.MODEL then
armor.textures[name].skin = skin..".png" armor.textures[name].skin = skin..".png"
end end
elseif minetest.get_modpath("simple_skins") then elseif skin_mod == "simple_skins" then
skin_mod = "skins"
local skin = skins.skins[name] local skin = skins.skins[name]
if skin then if skin then
armor.textures[name].skin = skin..".png" armor.textures[name].skin = skin..".png"
end end
elseif minetest.get_modpath("u_skins") then elseif skin_mod == "u_skins" then
skin_mod = "u_skins"
local skin = u_skins.u_skins[name] local skin = u_skins.u_skins[name]
if skin and u_skins.get_type(skin) == u_skins.type.MODEL then if skin and u_skins.get_type(skin) == u_skins.type.MODEL then
armor.textures[name].skin = skin..".png" armor.textures[name].skin = skin..".png"
@ -462,6 +473,8 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
local drop = {} local drop = {}
local player_inv = player:get_inventory() local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"}) local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not armor_inv then return end
-- MODIFICATION MADE FOR MFF ^
for i=1, player_inv:get_size("armor") do for i=1, player_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i) local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then if stack:get_count() > 0 then