2014-04-13 21:17:11 +02:00
|
|
|
ARMOR_INIT_DELAY = 1
|
|
|
|
ARMOR_INIT_TIMES = 1
|
|
|
|
ARMOR_BONES_DELAY = 1
|
|
|
|
ARMOR_UPDATE_TIME = 1
|
2014-08-17 18:07:27 +02:00
|
|
|
ARMOR_DROP = minetest.get_modpath("bones") ~= nil
|
2014-04-13 21:17:11 +02:00
|
|
|
ARMOR_DESTROY = false
|
|
|
|
ARMOR_LEVEL_MULTIPLIER = 1
|
|
|
|
ARMOR_HEAL_MULTIPLIER = 1
|
2016-04-10 16:56:33 +02:00
|
|
|
ARMOR_RADIATION_MULTIPLIER = 1
|
2015-02-19 19:53:31 +01:00
|
|
|
ARMOR_MATERIALS = {
|
2015-02-20 16:09:30 +01:00
|
|
|
wood = "group:wood",
|
2015-02-19 19:53:31 +01:00
|
|
|
cactus = "default:cactus",
|
|
|
|
steel = "default:steel_ingot",
|
|
|
|
bronze = "default:bronze_ingot",
|
|
|
|
diamond = "default:diamond",
|
|
|
|
gold = "default:gold_ingot",
|
|
|
|
mithril = "moreores:mithril_ingot",
|
2015-05-04 18:08:40 +02:00
|
|
|
crystal = "ethereal:crystal_ingot",
|
|
|
|
}
|
|
|
|
ARMOR_FIRE_PROTECT = minetest.get_modpath("ethereal") ~= nil
|
|
|
|
ARMOR_FIRE_NODES = {
|
2016-04-10 16:56:33 +02:00
|
|
|
{"default:lava_source", 5, 8},
|
|
|
|
{"default:lava_flowing", 5, 8},
|
2015-05-04 18:08:40 +02:00
|
|
|
{"fire:basic_flame", 3, 4},
|
2015-12-19 20:23:04 +01:00
|
|
|
{"fire:permanent_flame", 3, 4},
|
2015-05-04 18:08:40 +02:00
|
|
|
{"ethereal:crystal_spike", 2, 1},
|
2015-12-19 20:23:04 +01:00
|
|
|
{"ethereal:fire_flower", 2, 1},
|
2015-05-04 18:08:40 +02:00
|
|
|
{"default:torch", 1, 1},
|
2017-03-06 20:06:08 +01:00
|
|
|
{"default:torch_ceiling", 1, 1},
|
|
|
|
{"default:torch_wall", 1, 1},
|
2015-02-19 19:53:31 +01:00
|
|
|
}
|
2014-04-13 21:17:11 +02:00
|
|
|
|
2015-01-04 20:57:55 +01:00
|
|
|
local skin_mod = nil
|
|
|
|
local inv_mod = nil
|
2017-03-10 20:09:11 +01:00
|
|
|
local use_player_monoids = minetest.global_exists("player_monoids")
|
|
|
|
local use_armor_monoid = minetest.global_exists("armor_monoid")
|
2017-03-12 19:23:49 +01:00
|
|
|
local preview_textures = {}
|
2015-01-04 20:57:55 +01:00
|
|
|
|
2014-04-13 21:17:11 +02:00
|
|
|
local modpath = minetest.get_modpath(ARMOR_MOD_NAME)
|
2014-08-17 18:00:52 +02:00
|
|
|
local worldpath = minetest.get_worldpath()
|
2014-04-13 21:17:11 +02:00
|
|
|
local input = io.open(modpath.."/armor.conf", "r")
|
|
|
|
if input then
|
|
|
|
dofile(modpath.."/armor.conf")
|
|
|
|
input:close()
|
|
|
|
input = nil
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
2014-08-17 18:00:52 +02:00
|
|
|
input = io.open(worldpath.."/armor.conf", "r")
|
|
|
|
if input then
|
|
|
|
dofile(worldpath.."/armor.conf")
|
|
|
|
input:close()
|
|
|
|
input = nil
|
|
|
|
end
|
2015-02-19 19:53:31 +01:00
|
|
|
if not minetest.get_modpath("moreores") then
|
|
|
|
ARMOR_MATERIALS.mithril = nil
|
|
|
|
end
|
2015-05-04 18:08:40 +02:00
|
|
|
if not minetest.get_modpath("ethereal") then
|
|
|
|
ARMOR_MATERIALS.crystal = nil
|
|
|
|
end
|
2015-02-19 19:53:31 +01:00
|
|
|
|
2013-06-22 20:31:57 +02:00
|
|
|
armor = {
|
2015-12-09 21:49:14 +01:00
|
|
|
timer = 0,
|
2013-06-24 20:06:19 +02:00
|
|
|
elements = {"head", "torso", "legs", "feet"},
|
2013-12-21 06:52:15 +01:00
|
|
|
physics = {"jump","speed","gravity"},
|
2017-02-15 20:37:35 +01:00
|
|
|
formspec = "size[8,8.5]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
default.get_hotbar_bg(0,4.25)..
|
|
|
|
"image[2,0.5;2,4;armor_preview]"..
|
|
|
|
"list[current_player;main;0,4.25;8,1;]"..
|
|
|
|
"list[current_player;main;0,5.5;8,3;8]"..
|
|
|
|
"list[current_player;craft;4,0.5;3,3;]"..
|
|
|
|
"list[current_player;craftpreview;7,1.5;1,1;]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[current_player;craft]",
|
2013-11-12 22:22:52 +01:00
|
|
|
textures = {},
|
2014-04-13 18:41:19 +02:00
|
|
|
default_skin = "character",
|
2017-01-11 20:36:51 +01:00
|
|
|
version = "0.4.7",
|
2013-06-22 20:31:57 +02:00
|
|
|
}
|
|
|
|
|
2017-03-11 20:23:08 +01:00
|
|
|
local armor_formpage = "image[2.5,0;2,4;armor_preview]"..
|
|
|
|
"label[5,1;Level: armor_level]"..
|
|
|
|
"label[5,1.5;Heal: armor_heal]"..
|
|
|
|
"label[5,2;Fire: armor_fire]"..
|
|
|
|
"label[5,2.5;Radiation: armor_radiation]"..
|
|
|
|
"list[current_player;main;0,4.25;8,1;]"..
|
|
|
|
"list[current_player;main;0,5.5;8,3;8]"
|
2015-01-04 20:57:55 +01:00
|
|
|
if minetest.get_modpath("inventory_plus") then
|
|
|
|
inv_mod = "inventory_plus"
|
2017-03-03 18:59:31 +01:00
|
|
|
armor.formspec = "size[8,8.5]button[6,0;2,0.5;main;Back]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
default.get_hotbar_bg(0,4.25)..
|
2017-03-11 20:23:08 +01:00
|
|
|
armor_formpage
|
2015-09-09 20:07:31 +02:00
|
|
|
if minetest.get_modpath("crafting") then
|
|
|
|
inventory_plus.get_formspec = function(player, page)
|
|
|
|
end
|
|
|
|
end
|
2017-02-16 01:10:19 +01:00
|
|
|
elseif minetest.get_modpath("unified_inventory") and not unified_inventory.sfinv_compat_layer then
|
2015-01-04 20:57:55 +01:00
|
|
|
inv_mod = "unified_inventory"
|
2014-04-13 18:41:19 +02:00
|
|
|
unified_inventory.register_button("armor", {
|
|
|
|
type = "image",
|
|
|
|
image = "inventory_plus_armor.png",
|
|
|
|
})
|
|
|
|
unified_inventory.register_page("armor", {
|
2015-11-15 20:18:21 +01:00
|
|
|
get_formspec = function(player, perplayer_formspec)
|
|
|
|
local fy = perplayer_formspec.formspec_y
|
2014-04-13 18:41:19 +02:00
|
|
|
local name = player:get_player_name()
|
2017-03-11 20:23:08 +01:00
|
|
|
local formspec = "background[0.06,"..fy..";7.92,7.52;3d_armor_ui_form.png]"..
|
|
|
|
"label[0,0;Armor]"..
|
|
|
|
"list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]"..
|
|
|
|
"image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]"..
|
|
|
|
"label[5.0,"..(fy + 0.0)..";Level: "..armor.def[name].level.."]"..
|
|
|
|
"label[5.0,"..(fy + 0.5)..";Heal: "..armor.def[name].heal.."]"..
|
|
|
|
"label[5.0,"..(fy + 1.0)..";Fire: "..armor.def[name].fire.."]"..
|
|
|
|
"label[5.0,"..(fy + 1.5)..";Radiation: "..armor.def[name].radiation.."]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[detached:"..name.."_armor;armor]"
|
2014-04-13 18:41:19 +02:00
|
|
|
return {formspec=formspec}
|
|
|
|
end,
|
|
|
|
})
|
2015-04-25 18:45:59 +02:00
|
|
|
elseif minetest.get_modpath("inventory_enhanced") then
|
|
|
|
inv_mod = "inventory_enhanced"
|
2017-02-12 23:30:28 +01:00
|
|
|
elseif minetest.get_modpath("smart_inventory") then
|
|
|
|
inv_mod = "smart_inventory"
|
2017-02-16 01:10:19 +01:00
|
|
|
elseif minetest.get_modpath("sfinv") then
|
|
|
|
inv_mod = "sfinv"
|
2017-03-11 20:23:08 +01:00
|
|
|
armor.formspec = armor_formpage
|
2017-02-16 01:10:19 +01:00
|
|
|
sfinv.register_page("3d_armor:armor", {
|
|
|
|
title = "Armor",
|
|
|
|
get = function(self, player, context)
|
2017-03-11 20:23:08 +01:00
|
|
|
local name = player:get_player_name()
|
|
|
|
local formspec = armor:get_armor_formspec(name, true)
|
|
|
|
return sfinv.make_formspec(player, context, formspec, false)
|
2017-02-16 01:10:19 +01:00
|
|
|
end
|
|
|
|
})
|
2014-04-13 18:41:19 +02:00
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
|
2017-03-12 19:23:49 +01:00
|
|
|
local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"}
|
|
|
|
for _, mod in pairs(skin_mods) do
|
|
|
|
local path = minetest.get_modpath(mod)
|
|
|
|
if path then
|
|
|
|
local dir_list = minetest.get_dir_list(path.."/textures")
|
|
|
|
for _, fn in pairs(dir_list) do
|
|
|
|
if fn:find("_preview.png$") then
|
|
|
|
preview_textures[fn] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
skin_mod = mod
|
|
|
|
end
|
2015-03-08 19:29:17 +01:00
|
|
|
end
|
|
|
|
|
2013-09-12 01:29:30 +02:00
|
|
|
armor.def = {
|
|
|
|
state = 0,
|
2013-11-12 22:22:52 +01:00
|
|
|
count = 0,
|
2013-09-12 01:29:30 +02:00
|
|
|
}
|
|
|
|
|
2013-11-12 22:22:52 +01:00
|
|
|
armor.update_player_visuals = function(self, player)
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if self.textures[name] then
|
|
|
|
default.player_set_textures(player, {
|
|
|
|
self.textures[name].skin,
|
|
|
|
self.textures[name].armor,
|
|
|
|
self.textures[name].wielditem,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-22 20:31:57 +02:00
|
|
|
armor.set_player_armor = function(self, player)
|
2015-04-02 21:59:45 +02:00
|
|
|
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
|
2014-09-11 21:13:16 +02:00
|
|
|
if not name then
|
2014-04-21 20:10:24 +02:00
|
|
|
return
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
local armor_texture = "3d_armor_trans.png"
|
2013-06-22 20:31:57 +02:00
|
|
|
local armor_level = 0
|
2014-04-13 18:41:19 +02:00
|
|
|
local armor_heal = 0
|
2015-05-04 18:08:40 +02:00
|
|
|
local armor_fire = 0
|
2016-01-25 15:47:05 +01:00
|
|
|
local armor_water = 0
|
2016-04-10 16:56:33 +02:00
|
|
|
local armor_radiation = 0
|
2013-09-12 01:08:11 +02:00
|
|
|
local state = 0
|
|
|
|
local items = 0
|
2014-04-13 18:41:19 +02:00
|
|
|
local elements = {}
|
2013-06-22 20:31:57 +02:00
|
|
|
local textures = {}
|
2013-12-21 06:52:15 +01:00
|
|
|
local physics_o = {speed=1,gravity=1,jump=1}
|
2014-04-13 18:41:19 +02:00
|
|
|
local material = {type=nil, count=1}
|
2017-03-12 19:23:49 +01:00
|
|
|
local preview = armor:get_preview(name)
|
2014-04-13 18:41:19 +02:00
|
|
|
for _,v in ipairs(self.elements) do
|
|
|
|
elements[v] = false
|
|
|
|
end
|
|
|
|
for i=1, 6 do
|
|
|
|
local stack = player_inv:get_stack("armor", i)
|
2013-11-12 22:22:52 +01:00
|
|
|
local item = stack:get_name()
|
2014-04-13 18:41:19 +02:00
|
|
|
if stack:get_count() == 1 then
|
|
|
|
local def = stack:get_definition()
|
|
|
|
for k, v in pairs(elements) do
|
|
|
|
if v == false then
|
|
|
|
local level = def.groups["armor_"..k]
|
|
|
|
if level then
|
2015-12-04 21:36:42 +01:00
|
|
|
local texture = def.texture or item:gsub("%:", "_")
|
2014-04-13 18:41:19 +02:00
|
|
|
table.insert(textures, texture..".png")
|
|
|
|
preview = preview.."^"..texture.."_preview.png"
|
|
|
|
armor_level = armor_level + level
|
|
|
|
state = state + stack:get_wear()
|
|
|
|
items = items + 1
|
2016-01-25 15:47:05 +01:00
|
|
|
armor_heal = armor_heal + (def.groups["armor_heal"] or 0)
|
|
|
|
armor_fire = armor_fire + (def.groups["armor_fire"] or 0)
|
|
|
|
armor_water = armor_water + (def.groups["armor_water"] or 0)
|
2016-04-10 16:56:33 +02:00
|
|
|
armor_radiation = armor_radiation + (def.groups["armor_radiation"] or 0)
|
2015-01-04 20:57:55 +01:00
|
|
|
for kk,vv in ipairs(self.physics) do
|
2014-04-13 18:41:19 +02:00
|
|
|
local o_value = def.groups["physics_"..vv]
|
|
|
|
if o_value then
|
|
|
|
physics_o[vv] = physics_o[vv] + o_value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local mat = string.match(item, "%:.+_(.+)$")
|
|
|
|
if material.type then
|
|
|
|
if material.type == mat then
|
|
|
|
material.count = material.count + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
material.type = mat
|
|
|
|
end
|
|
|
|
elements[k] = true
|
|
|
|
end
|
|
|
|
end
|
2013-12-21 06:52:15 +01:00
|
|
|
end
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
|
|
|
if minetest.get_modpath("shields") then
|
|
|
|
armor_level = armor_level * 0.9
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
2014-04-13 18:41:19 +02:00
|
|
|
if material.type and material.count == #self.elements then
|
2013-11-12 22:22:52 +01:00
|
|
|
armor_level = armor_level * 1.1
|
|
|
|
end
|
2014-04-13 21:17:11 +02:00
|
|
|
armor_level = armor_level * ARMOR_LEVEL_MULTIPLIER
|
|
|
|
armor_heal = armor_heal * ARMOR_HEAL_MULTIPLIER
|
2016-04-10 16:56:33 +02:00
|
|
|
armor_radiation = armor_radiation * ARMOR_RADIATION_MULTIPLIER
|
2013-11-12 22:22:52 +01:00
|
|
|
if #textures > 0 then
|
2013-06-22 20:31:57 +02:00
|
|
|
armor_texture = table.concat(textures, "^")
|
|
|
|
end
|
|
|
|
local armor_groups = {fleshy=100}
|
|
|
|
if armor_level > 0 then
|
|
|
|
armor_groups.level = math.floor(armor_level / 20)
|
|
|
|
armor_groups.fleshy = 100 - armor_level
|
2016-04-10 16:56:33 +02:00
|
|
|
armor_groups.radiation = 100 - armor_radiation
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
2017-03-10 20:09:11 +01:00
|
|
|
if use_armor_monoid then
|
|
|
|
armor_monoid.monoid:add_change(player, {
|
|
|
|
fleshy = armor_groups.fleshy / 100
|
|
|
|
}, "3d_armor:armor")
|
|
|
|
else
|
|
|
|
player:set_armor_groups(armor_groups)
|
|
|
|
end
|
|
|
|
if use_player_monoids then
|
|
|
|
player_monoids.speed:add_change(player, physics_o.speed,
|
|
|
|
"3d_armor:physics")
|
|
|
|
player_monoids.jump:add_change(player, physics_o.jump,
|
|
|
|
"3d_armor:physics")
|
|
|
|
player_monoids.gravity:add_change(player, physics_o.gravity,
|
|
|
|
"3d_armor:physics")
|
|
|
|
else
|
|
|
|
player:set_physics_override(physics_o)
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
self.textures[name].armor = armor_texture
|
2014-04-13 18:41:19 +02:00
|
|
|
self.textures[name].preview = preview
|
2013-11-12 22:22:52 +01:00
|
|
|
self.def[name].state = state
|
|
|
|
self.def[name].count = items
|
2014-04-13 18:41:19 +02:00
|
|
|
self.def[name].level = armor_level
|
|
|
|
self.def[name].heal = armor_heal
|
2014-09-11 21:11:08 +02:00
|
|
|
self.def[name].jump = physics_o.jump
|
|
|
|
self.def[name].speed = physics_o.speed
|
|
|
|
self.def[name].gravity = physics_o.gravity
|
2015-05-04 18:08:40 +02:00
|
|
|
self.def[name].fire = armor_fire
|
2016-01-25 15:47:05 +01:00
|
|
|
self.def[name].water = armor_water
|
2016-04-10 16:56:33 +02:00
|
|
|
self.def[name].radiation = armor_radiation
|
2013-11-12 22:22:52 +01:00
|
|
|
self:update_player_visuals(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
|
|
|
|
2015-07-15 17:57:17 +02:00
|
|
|
armor.update_armor = function(self, player)
|
2015-12-09 21:49:14 +01:00
|
|
|
-- Legacy support: Called when armor levels are changed
|
2017-02-16 01:10:19 +01:00
|
|
|
-- Other mods can hook on to this function, see hud mod for example
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
|
|
|
|
2014-04-13 18:41:19 +02:00
|
|
|
armor.get_player_skin = function(self, name)
|
|
|
|
local skin = nil
|
2015-03-08 16:21:37 +01:00
|
|
|
if skin_mod == "skins" or skin_mod == "simple_skins" then
|
2014-04-13 18:41:19 +02:00
|
|
|
skin = skins.skins[name]
|
2015-01-04 20:57:55 +01:00
|
|
|
elseif skin_mod == "u_skins" then
|
2014-04-13 18:41:19 +02:00
|
|
|
skin = u_skins.u_skins[name]
|
2015-04-25 14:28:45 +02:00
|
|
|
elseif skin_mod == "wardrobe" then
|
2015-05-01 19:06:43 +02:00
|
|
|
skin = string.gsub(wardrobe.playerSkins[name], "%.png$","")
|
2014-04-13 18:41:19 +02:00
|
|
|
end
|
|
|
|
return skin or armor.default_skin
|
|
|
|
end
|
|
|
|
|
2015-03-08 16:21:37 +01:00
|
|
|
armor.get_preview = function(self, name)
|
2017-03-12 19:23:49 +01:00
|
|
|
local preview = armor:get_player_skin(name).."_preview.png"
|
|
|
|
if preview_textures[preview] then
|
|
|
|
return preview
|
2015-03-08 16:21:37 +01:00
|
|
|
end
|
2017-03-12 19:23:49 +01:00
|
|
|
return "character_preview.png"
|
2015-03-08 16:21:37 +01:00
|
|
|
end
|
|
|
|
|
2017-03-11 20:23:08 +01:00
|
|
|
armor.get_armor_formspec = function(self, name, listring)
|
2015-01-07 22:25:40 +01:00
|
|
|
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
|
2017-02-15 20:37:35 +01:00
|
|
|
local formspec = armor.formspec.."list[detached:"..name.."_armor;armor;0,0.5;2,3;]"
|
2017-03-11 20:23:08 +01:00
|
|
|
if listring == true then
|
|
|
|
formspec = formspec.."listring[current_player;main]"..
|
|
|
|
"listring[detached:"..name.."_armor;armor]"
|
|
|
|
end
|
2014-04-14 20:25:10 +02:00
|
|
|
formspec = formspec:gsub("armor_preview", armor.textures[name].preview)
|
|
|
|
formspec = formspec:gsub("armor_level", armor.def[name].level)
|
2015-05-04 18:08:40 +02:00
|
|
|
formspec = formspec:gsub("armor_heal", armor.def[name].heal)
|
|
|
|
formspec = formspec:gsub("armor_fire", armor.def[name].fire)
|
2016-04-10 16:56:33 +02:00
|
|
|
formspec = formspec:gsub("armor_radiation", armor.def[name].radiation)
|
2017-03-11 20:23:08 +01:00
|
|
|
formspec = formspec:gsub("player_name", armor.def[name].radiation)
|
2015-05-04 18:08:40 +02:00
|
|
|
return formspec
|
2014-04-14 20:25:10 +02:00
|
|
|
end
|
|
|
|
|
2014-04-13 18:41:19 +02:00
|
|
|
armor.update_inventory = function(self, player)
|
2015-04-02 21:59:45 +02:00
|
|
|
local name = armor:get_valid_player(player, "[set_player_armor]")
|
2015-04-25 18:45:59 +02:00
|
|
|
if not name or inv_mod == "inventory_enhanced" then
|
2015-01-04 22:37:12 +01:00
|
|
|
return
|
|
|
|
end
|
2017-02-12 23:30:28 +01:00
|
|
|
if inv_mod == "smart_inventory" then
|
2017-02-20 17:05:27 +01:00
|
|
|
local state = smart_inventory.get_page_state("player", name)
|
2017-02-12 23:30:28 +01:00
|
|
|
if state then
|
2017-02-20 17:05:27 +01:00
|
|
|
state:get("update_hook"):submit()
|
2017-02-12 23:30:28 +01:00
|
|
|
end
|
2017-02-16 01:10:19 +01:00
|
|
|
elseif inv_mod == "sfinv" then
|
|
|
|
if sfinv.set_page then
|
|
|
|
sfinv.set_page(player, "3d_armor:armor")
|
|
|
|
else
|
|
|
|
-- Backwards compat
|
|
|
|
sfinv.set_player_inventory_formspec(player, {
|
|
|
|
page = "3d_armor:armor"
|
|
|
|
})
|
|
|
|
end
|
|
|
|
elseif inv_mod == "unified_inventory" then
|
2014-04-14 20:25:10 +02:00
|
|
|
if unified_inventory.current_page[name] == "armor" then
|
|
|
|
unified_inventory.set_inventory_formspec(player, "armor")
|
|
|
|
end
|
2014-04-13 18:41:19 +02:00
|
|
|
else
|
2015-01-04 20:57:55 +01:00
|
|
|
if inv_mod == "inventory_plus" then
|
2017-03-11 20:23:08 +01:00
|
|
|
local formspec = armor:get_armor_formspec(name, true)
|
2014-04-14 20:25:10 +02:00
|
|
|
local page = player:get_inventory_formspec()
|
|
|
|
if page:find("detached:"..name.."_armor") then
|
|
|
|
inventory_plus.set_inventory_formspec(player, formspec)
|
|
|
|
end
|
2016-02-07 16:46:37 +01:00
|
|
|
elseif not core.setting_getbool("creative_mode") then
|
2017-03-11 20:23:08 +01:00
|
|
|
local formspec = armor:get_armor_formspec(name)
|
2014-04-14 20:25:10 +02:00
|
|
|
player:set_inventory_formspec(formspec)
|
|
|
|
end
|
2014-04-13 18:41:19 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-02 21:59:45 +02:00
|
|
|
armor.get_valid_player = function(self, player, msg)
|
|
|
|
msg = msg or ""
|
|
|
|
if not player then
|
|
|
|
minetest.log("error", "3d_armor: Player reference is nil "..msg)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if not name then
|
|
|
|
minetest.log("error", "3d_armor: Player name is nil "..msg)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pos = player:getpos()
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
|
|
|
if not pos then
|
|
|
|
minetest.log("error", "3d_armor: Player position is nil "..msg)
|
|
|
|
return
|
|
|
|
elseif not player_inv then
|
|
|
|
minetest.log("error", "3d_armor: Player inventory is nil "..msg)
|
|
|
|
return
|
|
|
|
elseif not armor_inv then
|
|
|
|
minetest.log("error", "3d_armor: Detached armor inventory is nil "..msg)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return name, player_inv, armor_inv, pos
|
|
|
|
end
|
|
|
|
|
2017-03-08 20:36:30 +01:00
|
|
|
armor.drop_armor = function(pos, stack)
|
|
|
|
local obj = minetest.add_item(pos, stack)
|
|
|
|
if obj then
|
|
|
|
obj:setvelocity({x=math.random(-1, 1), y=5, z=math.random(-1, 1)})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 22:22:52 +01:00
|
|
|
-- Register Player Model
|
|
|
|
|
2015-02-19 22:08:24 +01:00
|
|
|
default.player_register_model("3d_armor_character.b3d", {
|
2013-11-12 22:22:52 +01:00
|
|
|
animation_speed = 30,
|
|
|
|
textures = {
|
2014-04-13 21:17:11 +02:00
|
|
|
armor.default_skin..".png",
|
2013-11-12 22:22:52 +01:00
|
|
|
"3d_armor_trans.png",
|
|
|
|
"3d_armor_trans.png",
|
|
|
|
},
|
|
|
|
animations = {
|
|
|
|
stand = {x=0, y=79},
|
|
|
|
lay = {x=162, y=166},
|
|
|
|
walk = {x=168, y=187},
|
|
|
|
mine = {x=189, y=198},
|
|
|
|
walk_mine = {x=200, y=219},
|
|
|
|
sit = {x=81, y=160},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2013-06-22 20:31:57 +02:00
|
|
|
-- Register Callbacks
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
2015-04-02 21:59:45 +02:00
|
|
|
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
|
2015-04-25 18:45:59 +02:00
|
|
|
if not name or inv_mod == "inventory_enhanced" then
|
2015-04-02 21:59:45 +02:00
|
|
|
return
|
|
|
|
end
|
2015-01-04 20:57:55 +01:00
|
|
|
if inv_mod == "inventory_plus" and fields.armor then
|
2017-03-11 20:23:08 +01:00
|
|
|
local formspec = armor:get_armor_formspec(name, true)
|
2014-04-14 20:25:10 +02:00
|
|
|
inventory_plus.set_inventory_formspec(player, formspec)
|
2013-06-22 20:31:57 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
for field, _ in pairs(fields) do
|
2014-10-02 22:08:18 +02:00
|
|
|
if string.find(field, "skins_set") then
|
2013-06-22 20:31:57 +02:00
|
|
|
minetest.after(0, function(player)
|
2014-04-13 18:41:19 +02:00
|
|
|
local skin = armor:get_player_skin(name)
|
|
|
|
armor.textures[name].skin = skin..".png"
|
|
|
|
armor:set_player_armor(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
end, player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2015-02-19 22:08:24 +01:00
|
|
|
default.player_set_model(player, "3d_armor_character.b3d")
|
2013-06-22 20:31:57 +02:00
|
|
|
local name = player:get_player_name()
|
2014-04-13 18:41:19 +02:00
|
|
|
local player_inv = player:get_inventory()
|
2015-05-04 18:08:40 +02:00
|
|
|
local armor_inv = minetest.create_detached_inventory(name.."_armor", {
|
2013-06-22 20:31:57 +02:00
|
|
|
on_put = function(inv, listname, index, stack, player)
|
|
|
|
player:get_inventory():set_stack(listname, index, stack)
|
|
|
|
armor:set_player_armor(player)
|
2014-04-13 18:41:19 +02:00
|
|
|
armor:update_inventory(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
end,
|
|
|
|
on_take = function(inv, listname, index, stack, player)
|
|
|
|
player:get_inventory():set_stack(listname, index, nil)
|
|
|
|
armor:set_player_armor(player)
|
2014-04-13 18:41:19 +02:00
|
|
|
armor:update_inventory(player)
|
|
|
|
end,
|
|
|
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
local plaver_inv = player:get_inventory()
|
|
|
|
local stack = inv:get_stack(to_list, to_index)
|
|
|
|
player_inv:set_stack(to_list, to_index, stack)
|
|
|
|
player_inv:set_stack(from_list, from_index, nil)
|
|
|
|
armor:set_player_armor(player)
|
|
|
|
armor:update_inventory(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
end,
|
|
|
|
allow_put = function(inv, listname, index, stack, player)
|
2014-04-13 18:41:19 +02:00
|
|
|
return 1
|
2013-06-22 20:31:57 +02:00
|
|
|
end,
|
|
|
|
allow_take = function(inv, listname, index, stack, player)
|
|
|
|
return stack:get_count()
|
|
|
|
end,
|
|
|
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
2014-04-13 18:41:19 +02:00
|
|
|
return count
|
2013-06-22 20:31:57 +02:00
|
|
|
end,
|
2016-11-27 17:12:43 +01:00
|
|
|
}, name)
|
2015-01-04 20:57:55 +01:00
|
|
|
if inv_mod == "inventory_plus" then
|
2014-04-13 18:41:19 +02:00
|
|
|
inventory_plus.register_button(player,"armor", "Armor")
|
|
|
|
end
|
|
|
|
armor_inv:set_size("armor", 6)
|
|
|
|
player_inv:set_size("armor", 6)
|
|
|
|
for i=1, 6 do
|
|
|
|
local stack = player_inv:get_stack("armor", i)
|
|
|
|
armor_inv:set_stack("armor", i, stack)
|
2017-02-16 01:10:19 +01:00
|
|
|
end
|
2013-09-12 01:29:30 +02:00
|
|
|
armor.def[name] = {
|
2013-11-12 22:22:52 +01:00
|
|
|
state = 0,
|
|
|
|
count = 0,
|
2014-04-13 18:41:19 +02:00
|
|
|
level = 0,
|
|
|
|
heal = 0,
|
2014-09-11 21:11:08 +02:00
|
|
|
jump = 1,
|
|
|
|
speed = 1,
|
|
|
|
gravity = 1,
|
2015-05-04 18:08:40 +02:00
|
|
|
fire = 0,
|
2016-01-25 15:47:05 +01:00
|
|
|
water = 0,
|
2016-04-10 16:56:33 +02:00
|
|
|
radiation = 0,
|
2013-09-12 01:29:30 +02:00
|
|
|
}
|
2013-11-12 22:22:52 +01:00
|
|
|
armor.textures[name] = {
|
2014-04-13 18:41:19 +02:00
|
|
|
skin = armor.default_skin..".png",
|
2013-11-12 22:22:52 +01:00
|
|
|
armor = "3d_armor_trans.png",
|
|
|
|
wielditem = "3d_armor_trans.png",
|
2014-04-13 18:41:19 +02:00
|
|
|
preview = armor.default_skin.."_preview.png",
|
2013-11-12 22:22:52 +01:00
|
|
|
}
|
2015-03-08 19:29:17 +01:00
|
|
|
if skin_mod == "skins" then
|
2013-11-12 22:22:52 +01:00
|
|
|
local skin = skins.skins[name]
|
|
|
|
if skin and skins.get_type(skin) == skins.type.MODEL then
|
|
|
|
armor.textures[name].skin = skin..".png"
|
|
|
|
end
|
2015-03-08 19:29:17 +01:00
|
|
|
elseif skin_mod == "simple_skins" then
|
2014-09-12 19:30:09 +02:00
|
|
|
local skin = skins.skins[name]
|
|
|
|
if skin then
|
2015-12-09 21:49:14 +01:00
|
|
|
armor.textures[name].skin = skin..".png"
|
2014-09-12 19:30:09 +02:00
|
|
|
end
|
2015-03-08 19:29:17 +01:00
|
|
|
elseif skin_mod == "u_skins" then
|
2014-04-13 18:41:19 +02:00
|
|
|
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"
|
|
|
|
end
|
2015-04-25 14:28:45 +02:00
|
|
|
elseif skin_mod == "wardrobe" then
|
|
|
|
local skin = wardrobe.playerSkins[name]
|
|
|
|
if skin then
|
|
|
|
armor.textures[name].skin = skin
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
2017-03-12 18:01:04 +01:00
|
|
|
local texture_path = minetest.get_modpath("player_textures")
|
|
|
|
if texture_path then
|
|
|
|
local dir_list = minetest.get_dir_list(texture_path.."/textures")
|
|
|
|
for _, fn in pairs(dir_list) do
|
|
|
|
if fn == "player_"..name..".png" then
|
|
|
|
armor.textures[name].skin = fn
|
|
|
|
break
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
|
|
|
end
|
2014-04-13 21:17:11 +02:00
|
|
|
for i=1, ARMOR_INIT_TIMES do
|
|
|
|
minetest.after(ARMOR_INIT_DELAY * i, function(player)
|
|
|
|
armor:set_player_armor(player)
|
2015-01-04 20:57:55 +01:00
|
|
|
if not inv_mod then
|
2014-04-13 21:17:11 +02:00
|
|
|
armor:update_inventory(player)
|
|
|
|
end
|
|
|
|
end, player)
|
|
|
|
end
|
2013-06-22 20:31:57 +02:00
|
|
|
end)
|
|
|
|
|
2014-04-13 21:17:11 +02:00
|
|
|
if ARMOR_DROP == true or ARMOR_DESTROY == true then
|
2014-04-08 23:03:01 +02:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
2015-04-02 21:59:45 +02:00
|
|
|
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
|
|
|
|
if not name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local drop = {}
|
|
|
|
for i=1, player_inv:get_size("armor") do
|
|
|
|
local stack = armor_inv:get_stack("armor", i)
|
|
|
|
if stack:get_count() > 0 then
|
|
|
|
table.insert(drop, stack)
|
|
|
|
armor_inv:set_stack("armor", i, nil)
|
|
|
|
player_inv:set_stack("armor", i, nil)
|
2014-04-18 01:12:38 +02:00
|
|
|
end
|
2015-04-02 21:59:45 +02:00
|
|
|
end
|
|
|
|
armor:set_player_armor(player)
|
|
|
|
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
|
|
|
|
armor:update_inventory(player)
|
|
|
|
end
|
|
|
|
if ARMOR_DESTROY == false then
|
2015-04-17 04:57:07 +02:00
|
|
|
minetest.after(ARMOR_BONES_DELAY, function()
|
2017-02-24 23:45:23 +01:00
|
|
|
local meta = nil
|
2017-02-24 23:32:27 +01:00
|
|
|
local maxp = vector.add(pos, 8)
|
|
|
|
local minp = vector.subtract(pos, 8)
|
|
|
|
local bones = minetest.find_nodes_in_area(minp, maxp, {"bones:bones"})
|
|
|
|
for _, p in pairs(bones) do
|
2017-02-25 00:00:03 +01:00
|
|
|
local m = minetest.get_meta(p)
|
|
|
|
if m:get_string("owner") == name then
|
|
|
|
meta = m
|
2017-02-24 23:32:27 +01:00
|
|
|
break
|
2016-07-22 16:46:05 +02:00
|
|
|
end
|
2017-02-24 23:32:27 +01:00
|
|
|
end
|
2017-02-24 23:45:23 +01:00
|
|
|
if meta then
|
2016-07-22 16:46:05 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for _,stack in ipairs(drop) do
|
2017-02-24 23:32:27 +01:00
|
|
|
if inv:room_for_item("main", stack) then
|
2016-07-22 16:46:05 +02:00
|
|
|
inv:add_item("main", stack)
|
|
|
|
else
|
|
|
|
armor.drop_armor(pos, stack)
|
2014-04-08 23:03:01 +02:00
|
|
|
end
|
|
|
|
end
|
2015-04-17 04:57:07 +02:00
|
|
|
else
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
armor.drop_armor(pos, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2014-04-08 23:03:01 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2015-12-09 21:49:14 +01:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change)
|
|
|
|
local name, player_inv, armor_inv = armor:get_valid_player(player, "[on_hpchange]")
|
|
|
|
if name and hp_change < 0 then
|
2016-02-08 20:05:32 +01:00
|
|
|
|
|
|
|
-- used for insta kill tools/commands like /kill (doesnt damage armor)
|
|
|
|
if hp_change < -100 then
|
|
|
|
return hp_change
|
|
|
|
end
|
|
|
|
|
2015-12-09 21:49:14 +01:00
|
|
|
local heal_max = 0
|
|
|
|
local state = 0
|
|
|
|
local items = 0
|
|
|
|
for i=1, 6 do
|
|
|
|
local stack = player_inv:get_stack("armor", i)
|
|
|
|
if stack:get_count() > 0 then
|
|
|
|
local use = stack:get_definition().groups["armor_use"] or 0
|
|
|
|
local heal = stack:get_definition().groups["armor_heal"] or 0
|
|
|
|
local item = stack:get_name()
|
|
|
|
stack:add_wear(use)
|
|
|
|
armor_inv:set_stack("armor", i, stack)
|
|
|
|
player_inv:set_stack("armor", i, stack)
|
|
|
|
state = state + stack:get_wear()
|
|
|
|
items = items + 1
|
|
|
|
if stack:get_count() == 0 then
|
|
|
|
local desc = minetest.registered_items[item].description
|
|
|
|
if desc then
|
|
|
|
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
|
|
|
end
|
|
|
|
armor:set_player_armor(player)
|
|
|
|
armor:update_inventory(player)
|
|
|
|
end
|
|
|
|
heal_max = heal_max + heal
|
|
|
|
end
|
|
|
|
end
|
|
|
|
armor.def[name].state = state
|
|
|
|
armor.def[name].count = items
|
|
|
|
heal_max = heal_max * ARMOR_HEAL_MULTIPLIER
|
|
|
|
if heal_max > math.random(100) then
|
|
|
|
hp_change = 0
|
|
|
|
end
|
|
|
|
armor:update_armor(player)
|
|
|
|
end
|
|
|
|
return hp_change
|
|
|
|
end, true)
|
|
|
|
|
2016-01-25 15:47:05 +01:00
|
|
|
-- Fire Protection and water breating, added by TenPlus1
|
2015-12-09 21:49:14 +01:00
|
|
|
|
|
|
|
if ARMOR_FIRE_PROTECT == true then
|
|
|
|
-- override hot nodes so they do not hurt player anywhere but mod
|
2016-01-25 15:47:05 +01:00
|
|
|
for _, row in pairs(ARMOR_FIRE_NODES) do
|
2015-12-09 21:49:14 +01:00
|
|
|
if minetest.registered_nodes[row[1]] then
|
|
|
|
minetest.override_item(row[1], {damage_per_second = 0})
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
|
|
|
end
|
2016-01-25 15:47:05 +01:00
|
|
|
else
|
|
|
|
print ("[3d_armor] Fire Nodes disabled")
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
armor.timer = armor.timer + dtime
|
|
|
|
if armor.timer < ARMOR_UPDATE_TIME then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for _,player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local pos = player:getpos()
|
|
|
|
local hp = player:get_hp()
|
|
|
|
-- water breathing
|
|
|
|
if name and armor.def[name].water > 0 then
|
|
|
|
if player:get_breath() < 10 then
|
|
|
|
player:set_breath(10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- fire protection
|
|
|
|
if ARMOR_FIRE_PROTECT == true
|
|
|
|
and name and pos and hp then
|
|
|
|
pos.y = pos.y + 1.4 -- head level
|
|
|
|
local node_head = minetest.get_node(pos).name
|
|
|
|
pos.y = pos.y - 1.2 -- feet level
|
|
|
|
local node_feet = minetest.get_node(pos).name
|
|
|
|
-- is player inside a hot node?
|
|
|
|
for _, row in pairs(ARMOR_FIRE_NODES) do
|
|
|
|
-- check fire protection, if not enough then get hurt
|
|
|
|
if row[1] == node_head or row[1] == node_feet then
|
|
|
|
if hp > 0 and armor.def[name].fire < row[2] then
|
|
|
|
hp = hp - row[3] * ARMOR_UPDATE_TIME
|
|
|
|
player:set_hp(hp)
|
|
|
|
break
|
2015-12-09 21:49:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-01-25 15:47:05 +01:00
|
|
|
end
|
|
|
|
armor.timer = 0
|
|
|
|
end)
|
2016-02-08 20:05:32 +01:00
|
|
|
|
|
|
|
-- kill player when command issued
|
|
|
|
minetest.register_chatcommand("kill", {
|
|
|
|
params = "<name>",
|
|
|
|
description = "Kills player instantly",
|
2016-06-17 16:08:50 +02:00
|
|
|
privs = {ban=true},
|
2016-02-08 20:05:32 +01:00
|
|
|
func = function(name, param)
|
2016-06-17 18:29:43 +02:00
|
|
|
local player = minetest.get_player_by_name(param)
|
2016-02-08 20:05:32 +01:00
|
|
|
if player then
|
2016-06-17 16:08:50 +02:00
|
|
|
player:set_hp(0)
|
2016-02-08 20:05:32 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2016-11-27 18:18:08 +01:00
|
|
|
|
|
|
|
minetest.register_chatcommand("killme", {
|
|
|
|
description = "Kill yourself instantly",
|
|
|
|
func = function(name)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
if player then
|
2016-12-07 20:24:00 +01:00
|
|
|
player:set_hp(-1001)
|
2016-11-27 18:18:08 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|