mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
Update 3d_armor
This commit is contained in:
parent
f2124cb34c
commit
ba155c770a
@ -26,7 +26,7 @@ ARMOR_LEVEL_MULTIPLIER = 1
|
||||
|
||||
-- You can use this to increase or decrease overall armor healing,
|
||||
-- eg: ARMOR_HEAL_MULTIPLIER = 0 will disable healing altogether.
|
||||
ARMOR_HEAL_MULTIPLIER = 0.5
|
||||
ARMOR_HEAL_MULTIPLIER = 1
|
||||
|
||||
-- You can also use this file to execute arbitary lua code
|
||||
-- eg: Dumb the armor down if using Simple Mobs
|
||||
|
@ -7,6 +7,9 @@ ARMOR_DESTROY = false
|
||||
ARMOR_LEVEL_MULTIPLIER = 1
|
||||
ARMOR_HEAL_MULTIPLIER = 1
|
||||
|
||||
local skin_mod = nil
|
||||
local inv_mod = nil
|
||||
|
||||
local modpath = minetest.get_modpath(ARMOR_MOD_NAME)
|
||||
local worldpath = minetest.get_worldpath()
|
||||
local input = io.open(modpath.."/armor.conf", "r")
|
||||
@ -37,14 +40,16 @@ armor = {
|
||||
default_skin = "character",
|
||||
}
|
||||
|
||||
if inventory_plus then
|
||||
if minetest.get_modpath("inventory_plus") then
|
||||
inv_mod = "inventory_plus"
|
||||
armor.formspec = "size[8,8.5]button[0,0;2,0.5;main;Back]"
|
||||
.."list[detached:player_name_armor;armor;0,1;2,3;]"
|
||||
.."image[2.5,0.75;2,4;armor_preview]"
|
||||
.."label[5,1;Level: armor_level]"
|
||||
.."label[5,1.5;Heal: armor_heal]"
|
||||
.."list[current_player;main;0,4.5;8,4;]"
|
||||
elseif unified_inventory then
|
||||
+elseif minetest.get_modpath("unified_inventory") then
|
||||
inv_mod = "unified_inventory"
|
||||
unified_inventory.register_button("armor", {
|
||||
type = "image",
|
||||
image = "inventory_plus_armor.png",
|
||||
@ -86,15 +91,16 @@ armor.set_player_armor = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local player_inv = player:get_inventory()
|
||||
if not name then
|
||||
minetest.log("error", "Failed to read player name")
|
||||
return
|
||||
elseif not player_inv then
|
||||
minetest.log("error", "Failed to read player inventory")
|
||||
return
|
||||
local name = player:get_player_name()
|
||||
if not name then
|
||||
minetest.log("error", "3d_armor: Player name is nil [set_player_armor]")
|
||||
return
|
||||
end
|
||||
local player_inv = player:get_inventory()
|
||||
if not player_inv then
|
||||
minetest.log("error", "3d_armor: Player inventory is nil [set_player_armor]")
|
||||
return
|
||||
end
|
||||
local armor_texture = "3d_armor_trans.png"
|
||||
local armor_level = 0
|
||||
local armor_heal = 0
|
||||
@ -176,10 +182,15 @@ armor.set_player_armor = function(self, player)
|
||||
end
|
||||
|
||||
armor.update_armor = function(self, player)
|
||||
if not player then
|
||||
if not player then
|
||||
minetest.log("error", "3d_armor: Player reference is nil [update_armor]")
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
if not name then
|
||||
minetest.log("error", "3d_armor: Player name is nil[update_armor]")
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local hp = player:get_hp() or 0
|
||||
if hp == 0 or hp == self.player_hp[name] then
|
||||
return
|
||||
@ -188,12 +199,12 @@ armor.update_armor = function(self, player)
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
||||
if not player_inv then
|
||||
minetest.log("error", "Failed to read player inventory")
|
||||
return
|
||||
elseif not armor_inv then
|
||||
minetest.log("error", "Failed to read detached inventory")
|
||||
return
|
||||
end
|
||||
minetest.log("error", "3d_armor: Player inventory is nil [update_armor]")
|
||||
return
|
||||
elseif not armor_inv then
|
||||
minetest.log("error", "3d_armor: Detached inventory is nil [update_armor]")
|
||||
return
|
||||
end
|
||||
local heal_max = 0
|
||||
local state = 0
|
||||
local items = 0
|
||||
@ -232,15 +243,27 @@ end
|
||||
|
||||
armor.get_player_skin = function(self, name)
|
||||
local skin = nil
|
||||
if skins then
|
||||
if skin_mod == "skins" then
|
||||
skin = skins.skins[name]
|
||||
elseif u_skins then
|
||||
elseif skin_mod == "u_skins" then
|
||||
skin = u_skins.u_skins[name]
|
||||
end
|
||||
return skin or armor.default_skin
|
||||
end
|
||||
|
||||
armor.get_armor_formspec = function(self, name)
|
||||
if not name then
|
||||
minetest.log("error", "3d_armor: Player name is nil [get_armor_formspec]")
|
||||
return ""
|
||||
end
|
||||
if not armor.textures[name] then
|
||||
minetest.log("error", "3d_armor: Player texture["..name.."] is nil [get_armor_formspec]")
|
||||
return ""
|
||||
end
|
||||
if not armor.def[name] then
|
||||
minetest.log("error", "3d_armor: Armor def["..name.."] is nil [get_armor_formspec]")
|
||||
return ""
|
||||
end
|
||||
local formspec = armor.formspec:gsub("player_name", name)
|
||||
formspec = formspec:gsub("armor_preview", armor.textures[name].preview)
|
||||
formspec = formspec:gsub("armor_level", armor.def[name].level)
|
||||
@ -248,15 +271,23 @@ armor.get_armor_formspec = function(self, name)
|
||||
end
|
||||
|
||||
armor.update_inventory = function(self, player)
|
||||
if not player then
|
||||
minetest.log("error", "3d_armor: Player reference is nil [update_inventory]")
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
if unified_inventory then
|
||||
if unified_inventory.current_page[name] == "armor" then
|
||||
unified_inventory.set_inventory_formspec(player, "armor")
|
||||
end
|
||||
else
|
||||
local formspec = armor:get_armor_formspec(name)
|
||||
if inventory_plus then
|
||||
local page = player:get_inventory_formspec()
|
||||
if not name then
|
||||
minetest.log("error", "3d_armor: Player name is nil [update_inventory]")
|
||||
return
|
||||
end
|
||||
if inv_mod == "unified_inventory" then
|
||||
if unified_inventory.current_page[name] == "armor" then
|
||||
unified_inventory.set_inventory_formspec(player, "armor")
|
||||
end
|
||||
else
|
||||
local formspec = armor:get_armor_formspec(name)
|
||||
if inv_mod == "inventory_plus" then
|
||||
local page = player:get_inventory_formspec()
|
||||
if page:find("detached:"..name.."_armor") then
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
end
|
||||
@ -289,13 +320,13 @@ default.player_register_model("3d_armor_character.x", {
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
if inventory_plus and fields.armor then
|
||||
if inv_mod == "inventory_plus" and fields.armor then
|
||||
local formspec = armor:get_armor_formspec(name)
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
return
|
||||
end
|
||||
for field, _ in pairs(fields) do
|
||||
if string.find(field, "skins_set_") then
|
||||
if string.find(field, "skins_set") then
|
||||
minetest.after(0, function(player)
|
||||
local skin = armor:get_player_skin(name)
|
||||
armor.textures[name].skin = skin..".png"
|
||||
@ -338,7 +369,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
return count
|
||||
end,
|
||||
})
|
||||
if inventory_plus then
|
||||
if inv_mod == "inventory_plus" then
|
||||
inventory_plus.register_button(player,"armor", "Armor")
|
||||
end
|
||||
armor_inv:set_size("armor", 6)
|
||||
@ -354,7 +385,8 @@ minetest.register_on_joinplayer(function(player)
|
||||
armor_inv:add_item("armor", player_inv:get_stack(list, 1))
|
||||
player_inv:set_stack(list, 1, nil)
|
||||
end
|
||||
|
||||
-- TODO Remove this on the next version upate
|
||||
|
||||
armor.player_hp[name] = 0
|
||||
armor.def[name] = {
|
||||
state = 0,
|
||||
@ -372,16 +404,19 @@ minetest.register_on_joinplayer(function(player)
|
||||
preview = armor.default_skin.."_preview.png",
|
||||
}
|
||||
if minetest.get_modpath("skins") then
|
||||
skin_mod = "skins"
|
||||
local skin = skins.skins[name]
|
||||
if skin and skins.get_type(skin) == skins.type.MODEL then
|
||||
armor.textures[name].skin = skin..".png"
|
||||
end
|
||||
elseif minetest.get_modpath("simple_skins") then
|
||||
skin_mod = "skins"
|
||||
local skin = skins.skins[name]
|
||||
if skin then
|
||||
armor.textures[name].skin = skin..".png"
|
||||
end
|
||||
elseif minetest.get_modpath("u_skins") then
|
||||
skin_mod = "u_skins"
|
||||
local skin = u_skins.u_skins[name]
|
||||
if skin and u_skins.get_type(skin) == u_skins.type.MODEL then
|
||||
armor.textures[name].skin = skin..".png"
|
||||
@ -398,7 +433,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
for i=1, ARMOR_INIT_TIMES do
|
||||
minetest.after(ARMOR_INIT_DELAY * i, function(player)
|
||||
armor:set_player_armor(player)
|
||||
if inventory_plus == nil and unified_inventory == nil then
|
||||
if not inv_mod then
|
||||
armor:update_inventory(player)
|
||||
end
|
||||
end, player)
|
||||
@ -422,9 +457,9 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
|
||||
end
|
||||
end
|
||||
armor:set_player_armor(player)
|
||||
if unified_inventory then
|
||||
unified_inventory.set_inventory_formspec(player, "craft")
|
||||
elseif inventory_plus then
|
||||
if inv_mod == "unified_inventory" then
|
||||
unified_inventory.set_inventory_formspec(player, "craft")
|
||||
elseif inv_mod == "inventory_plus" then
|
||||
local formspec = inventory_plus.get_formspec(player,"main")
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
else
|
||||
|
@ -15,7 +15,7 @@ Helmets:
|
||||
[3d_armor:helmet_steel] X = [default:steel_ingot]
|
||||
[3d_armor:helmet_bronze] X = [default:bronze_ingot]
|
||||
[3d_armor:helmet_diamond] X = [default:diamond]
|
||||
[3d_armor:helmet_diamond] X = [default:gold_ingot]
|
||||
[3d_armor:helmet_gold] X = [default:gold_ingot]
|
||||
[3d_armor:helmet_mithril] X = [moreores:mithril_ingot] *
|
||||
|
||||
Chestplates:
|
||||
@ -32,7 +32,7 @@ Chestplates:
|
||||
[3d_armor:chestplate_steel] X = [default:steel_ingot]
|
||||
[3d_armor:chestplate_bronze] X = [default:bronze_ingot]
|
||||
[3d_armor:chestplate_diamond] X = [default:diamond]
|
||||
[3d_armor:chestplate_diamond] X = [default:gold_ingot]
|
||||
[3d_armor:chestplate_gold] X = [default:gold_ingot]
|
||||
[3d_armor:chestplate_mithril] X = [moreores:mithril_ingot] *
|
||||
|
||||
Leggings:
|
||||
@ -49,7 +49,7 @@ Leggings:
|
||||
[3d_armor:leggings_steel] X = [default:steel_ingot]
|
||||
[3d_armor:leggings_bronze] X = [default:bronze_ingot]
|
||||
[3d_armor:leggings_diamond] X = [default:diamond]
|
||||
[3d_armor:leggings_diamond] X = [default:gold_ingot]
|
||||
[3d_armor:leggings_gold] X = [default:gold_ingot]
|
||||
[3d_armor:leggings_mithril] X = [moreores:mithril_ingot] *
|
||||
|
||||
Boots:
|
||||
@ -64,7 +64,7 @@ Boots:
|
||||
[3d_armor:boots_steel] X = [default:steel_ingot]
|
||||
[3d_armor:boots_bronze] X = [default:bronze_ingot
|
||||
[3d_armor:boots_diamond] X = [default:diamond]
|
||||
[3d_armor:boots_diamond] X = [default:gold_ingot]
|
||||
[3d_armor:boots_gold] X = [default:gold_ingot]
|
||||
[3d_armor:boots_mithril] X = [moreores:mithril_ingot] *
|
||||
|
||||
* Requires moreores mod by Calinou - https://forum.minetest.net/viewtopic.php?id=549
|
||||
|
Loading…
Reference in New Issue
Block a user