2017-03-31 20:54:12 +02:00
|
|
|
local S = function(s) return s end
|
|
|
|
if minetest.global_exists("intllib") then
|
|
|
|
S = intllib.Getter()
|
|
|
|
end
|
2017-03-18 18:23:50 +01:00
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
local modpath = minetest.get_modpath(modname)
|
2017-03-17 21:05:55 +01:00
|
|
|
local worldpath = minetest.get_worldpath()
|
2017-04-05 18:46:09 +02:00
|
|
|
local last_punch_time = {}
|
2017-03-18 18:23:50 +01:00
|
|
|
|
|
|
|
dofile(modpath.."/api.lua")
|
|
|
|
|
|
|
|
-- Legacy Config Support
|
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
local input = io.open(modpath.."/armor.conf", "r")
|
|
|
|
if input then
|
|
|
|
dofile(modpath.."/armor.conf")
|
|
|
|
input:close()
|
|
|
|
input = nil
|
2015-02-19 19:53:31 +01:00
|
|
|
end
|
2017-03-17 21:05:55 +01:00
|
|
|
input = io.open(worldpath.."/armor.conf", "r")
|
|
|
|
if input then
|
|
|
|
dofile(worldpath.."/armor.conf")
|
|
|
|
input:close()
|
|
|
|
input = nil
|
2015-02-19 19:53:31 +01:00
|
|
|
end
|
2017-03-18 18:23:50 +01:00
|
|
|
for name, _ in pairs(armor.config) do
|
|
|
|
local global = "ARMOR_"..name:upper()
|
|
|
|
if minetest.global_exists(global) then
|
|
|
|
armor.config[name] = _G[global]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if minetest.global_exists("ARMOR_MATERIALS") then
|
|
|
|
armor.materials = table.copy(ARMOR_MATERIALS)
|
|
|
|
end
|
|
|
|
if minetest.global_exists("ARMOR_FIRE_NODES") then
|
|
|
|
armor.fire_nodes = table.copy(ARMOR_FIRE_NODES)
|
|
|
|
end
|
|
|
|
|
2017-03-18 19:04:10 +01:00
|
|
|
-- Load Configuration
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
for name, config in pairs(armor.config) do
|
|
|
|
local setting = minetest.setting_get("armor_"..name)
|
|
|
|
if type(config) == "number" then
|
|
|
|
setting = tonumber(setting)
|
|
|
|
elseif type(config) == "boolean" then
|
|
|
|
setting = minetest.setting_getbool("armor_"..name)
|
|
|
|
end
|
2017-04-05 18:51:50 +02:00
|
|
|
if setting ~= nil then
|
2017-03-18 18:23:50 +01:00
|
|
|
armor.config[name] = setting
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for material, _ in pairs(armor.materials) do
|
|
|
|
local key = "material_"..material
|
|
|
|
if armor.config[key] == false then
|
|
|
|
armor.materials[material] = nil
|
|
|
|
end
|
|
|
|
end
|
2017-03-31 20:54:12 +02:00
|
|
|
armor.formspec = armor.formspec..
|
|
|
|
"label[5,1;"..S("Level")..": armor_level]"..
|
|
|
|
"label[5,1.5;"..S("Heal")..": armor_attr_heal]"
|
2017-03-23 01:52:32 +01:00
|
|
|
if armor.config.fire_protect then
|
2017-03-31 20:54:12 +02:00
|
|
|
armor.formspec = armor.formspec.."label[5,2;"..S("Fire")..": armor_fire]"
|
2017-03-23 01:52:32 +01:00
|
|
|
end
|
2017-04-05 18:46:09 +02:00
|
|
|
armor:register_on_destroy(function(player, stack)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local def = stack:get_definition()
|
|
|
|
if name and def and def.description then
|
|
|
|
minetest.chat_send_player(name, S("Your").." "..def.description.." "..
|
|
|
|
S("got destroyed").."!")
|
|
|
|
end
|
|
|
|
end)
|
2017-03-18 18:23:50 +01:00
|
|
|
|
|
|
|
dofile(modpath.."/armor.lua")
|
2013-06-22 20:31:57 +02:00
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
-- Mod Compatibility
|
2013-03-15 21:27:58 +01:00
|
|
|
|
2017-03-19 19:39:58 +01:00
|
|
|
if minetest.get_modpath("technic") then
|
2017-03-31 20:54:12 +02:00
|
|
|
armor.formspec = armor.formspec..
|
|
|
|
"label[5,2.5;"..S("Radiation")..": armor_group_radiation]"
|
2017-03-23 01:52:32 +01:00
|
|
|
armor:register_armor_group("radiation")
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
2017-03-17 21:05:55 +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
|
|
|
|
armor:add_preview(fn)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
armor.skin_mod = mod
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not minetest.get_modpath("moreores") then
|
2017-03-18 18:23:50 +01:00
|
|
|
armor.materials.mithril = nil
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
if not minetest.get_modpath("ethereal") then
|
2017-03-18 18:23:50 +01:00
|
|
|
armor.materials.crystal = nil
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
-- Armor Player Model
|
|
|
|
|
|
|
|
default.player_register_model("3d_armor_character.b3d", {
|
|
|
|
animation_speed = 30,
|
|
|
|
textures = {
|
|
|
|
armor.default_skin..".png",
|
|
|
|
"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},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
|
2017-03-19 17:01:18 +01:00
|
|
|
if not name then
|
2017-03-17 21:05:55 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
for field, _ in pairs(fields) do
|
|
|
|
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"
|
|
|
|
armor:set_player_armor(player)
|
|
|
|
end, player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
default.player_set_model(player, "3d_armor_character.b3d")
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local armor_inv = minetest.create_detached_inventory(name.."_armor", {
|
|
|
|
on_put = function(inv, listname, index, stack, player)
|
|
|
|
player:get_inventory():set_stack(listname, index, stack)
|
|
|
|
armor:set_player_armor(player)
|
2017-03-18 21:12:43 +01:00
|
|
|
armor:run_callbacks("on_equip", player, stack)
|
2017-03-17 21:05:55 +01:00
|
|
|
end,
|
|
|
|
on_take = function(inv, listname, index, stack, player)
|
|
|
|
player:get_inventory():set_stack(listname, index, nil)
|
|
|
|
armor:set_player_armor(player)
|
2017-03-18 21:12:43 +01:00
|
|
|
armor:run_callbacks("on_unequip", player, stack)
|
2017-03-17 21:05:55 +01:00
|
|
|
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)
|
|
|
|
end,
|
|
|
|
allow_put = function(inv, listname, index, stack, player)
|
2017-03-18 21:27:39 +01:00
|
|
|
local def = stack:get_definition() or {}
|
|
|
|
for _, element in pairs(armor.elements) do
|
|
|
|
if def.groups["armor_"..element] then
|
|
|
|
for i = 1, 6 do
|
|
|
|
local item = inv:get_stack("armor", i):get_name()
|
|
|
|
if minetest.get_item_group(item, "armor_"..element) > 0 then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-17 21:05:55 +01:00
|
|
|
return 1
|
|
|
|
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)
|
|
|
|
return count
|
|
|
|
end,
|
|
|
|
}, name)
|
|
|
|
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-03-18 21:12:43 +01:00
|
|
|
armor:run_callbacks("on_equip", player, stack)
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
armor.def[name] = {
|
2017-03-23 01:52:32 +01:00
|
|
|
level = 0,
|
2017-03-17 21:05:55 +01:00
|
|
|
state = 0,
|
|
|
|
count = 0,
|
2017-03-23 01:52:32 +01:00
|
|
|
groups = {},
|
2017-03-17 21:05:55 +01:00
|
|
|
}
|
2017-03-23 01:52:32 +01:00
|
|
|
for _, phys in pairs(armor.physics) do
|
|
|
|
armor.def[name][phys] = 1
|
|
|
|
end
|
|
|
|
for _, attr in pairs(armor.attributes) do
|
|
|
|
armor.def[name][attr] = 0
|
|
|
|
end
|
|
|
|
for group, _ in pairs(armor.registered_groups) do
|
|
|
|
armor.def[name].groups[group] = 0
|
|
|
|
end
|
2017-03-19 19:52:51 +01:00
|
|
|
local skin = armor:get_player_skin(name)
|
2017-03-17 21:05:55 +01:00
|
|
|
armor.textures[name] = {
|
2017-03-19 19:52:51 +01:00
|
|
|
skin = skin..".png",
|
2017-03-17 21:05:55 +01:00
|
|
|
armor = "3d_armor_trans.png",
|
|
|
|
wielditem = "3d_armor_trans.png",
|
|
|
|
preview = armor.default_skin.."_preview.png",
|
|
|
|
}
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
2017-03-18 18:23:50 +01:00
|
|
|
for i=1, armor.config.init_times do
|
|
|
|
minetest.after(armor.config.init_delay * i, function(player)
|
2017-03-17 21:05:55 +01:00
|
|
|
armor:set_player_armor(player)
|
|
|
|
end, player)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-03-23 01:52:32 +01:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if name then
|
|
|
|
armor.def[name] = nil
|
|
|
|
armor.textures[name] = nil
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
if armor.config.drop == true or armor.config.destroy == true then
|
2017-03-17 21:05:55 +01:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
2017-03-22 20:00:48 +01:00
|
|
|
local name, player_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
|
2017-03-17 21:05:55 +01:00
|
|
|
if not name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local drop = {}
|
|
|
|
for i=1, player_inv:get_size("armor") do
|
2017-03-22 20:00:48 +01:00
|
|
|
local stack = player_inv:get_stack("armor", i)
|
2017-03-17 21:05:55 +01:00
|
|
|
if stack:get_count() > 0 then
|
|
|
|
table.insert(drop, stack)
|
2017-03-22 20:00:48 +01:00
|
|
|
armor:set_inventory_stack(player, i, nil)
|
2017-03-18 21:12:43 +01:00
|
|
|
armor:run_callbacks("on_unequip", player, stack)
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
armor:set_player_armor(player)
|
2017-03-18 18:23:50 +01:00
|
|
|
if armor.config.destroy == false then
|
|
|
|
minetest.after(armor.config.bones_delay, function()
|
2017-03-17 21:05:55 +01:00
|
|
|
local meta = nil
|
|
|
|
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
|
|
|
|
local m = minetest.get_meta(p)
|
|
|
|
if m:get_string("owner") == name then
|
|
|
|
meta = m
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if meta then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
if inv:room_for_item("main", stack) then
|
|
|
|
inv:add_item("main", stack)
|
|
|
|
else
|
|
|
|
armor.drop_armor(pos, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
armor.drop_armor(pos, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|
2015-05-04 18:08:40 +02:00
|
|
|
end
|
|
|
|
|
2017-04-05 18:46:09 +02:00
|
|
|
if armor.config.punch_damage == true then
|
|
|
|
minetest.register_on_punchplayer(function(player, hitter,
|
|
|
|
time_from_last_punch, tool_capabilities)
|
|
|
|
armor:punch(player, hitter, time_from_last_punch, tool_capabilities)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if name then
|
|
|
|
last_punch_time[name] = minetest.get_gametime()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2017-03-17 21:05:55 +01:00
|
|
|
minetest.register_on_player_hpchange(function(player, hp_change)
|
2017-04-05 18:46:09 +02:00
|
|
|
if player and hp_change < 0 then
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if name and armor.def[name] then
|
|
|
|
local heal = armor.def[name].heal or 0
|
|
|
|
if heal >= math.random(100) then
|
|
|
|
hp_change = 0
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-05 18:46:09 +02:00
|
|
|
-- check if armor damage was handled by on_punchplayer
|
|
|
|
local time = last_punch_time[name] or 0
|
|
|
|
if time == 0 or time + 1 < minetest.get_gametime() then
|
|
|
|
armor:punch(player)
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return hp_change
|
|
|
|
end, true)
|
|
|
|
|
|
|
|
-- Fire Protection and water breating, added by TenPlus1
|
|
|
|
|
2017-03-18 18:23:50 +01:00
|
|
|
if armor.config.fire_protect == true then
|
2017-03-17 21:05:55 +01:00
|
|
|
-- override hot nodes so they do not hurt player anywhere but mod
|
2017-03-18 18:23:50 +01:00
|
|
|
for _, row in pairs(armor.fire_nodes) do
|
2017-03-17 21:05:55 +01:00
|
|
|
if minetest.registered_nodes[row[1]] then
|
|
|
|
minetest.override_item(row[1], {damage_per_second = 0})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print ("[3d_armor] Fire Nodes disabled")
|
2013-04-11 21:56:35 +02:00
|
|
|
end
|
2013-03-15 21:27:58 +01:00
|
|
|
|
2017-03-31 22:18:29 +02:00
|
|
|
if armor.config.water_protect == true or armor.config.fire_protect == true then
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
armor.timer = armor.timer + dtime
|
|
|
|
if armor.timer < armor.config.update_time then
|
|
|
|
return
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
2017-03-31 22:18:29 +02:00
|
|
|
for _,player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local pos = player:getpos()
|
|
|
|
local hp = player:get_hp()
|
|
|
|
if not name or not pos or not hp then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- water breathing
|
|
|
|
if armor.config.water_protect == true then
|
|
|
|
if armor.def[name].water > 0 and player:get_breath() < 10 then
|
|
|
|
player:set_breath(10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- fire protection
|
|
|
|
if armor.config.fire_protect == true 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.config.update_time
|
|
|
|
player:set_hp(hp)
|
|
|
|
break
|
|
|
|
end
|
2017-03-17 21:05:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-31 22:18:29 +02:00
|
|
|
armor.timer = 0
|
|
|
|
end)
|
|
|
|
end
|