2016-02-10 12:46:16 +01:00
|
|
|
armor = {}
|
2016-02-11 12:21:53 +01:00
|
|
|
armor.invs = {}
|
2016-02-17 19:33:33 +01:00
|
|
|
armor.data = {}
|
|
|
|
|
|
|
|
armor.armor_file = minetest.get_worldpath() .. "/armor"
|
2016-02-11 12:21:53 +01:00
|
|
|
|
2016-02-10 12:46:16 +01:00
|
|
|
function armor.register_armor(name, def)
|
2016-02-11 12:21:53 +01:00
|
|
|
minetest.register_craftitem(name .. "_chestplate", {
|
|
|
|
description = def.description .. " Chestplate",
|
|
|
|
inventory_image = def.tex .. "_chestplate.png",
|
|
|
|
protection = def.protection,
|
|
|
|
skin = def.skin .. "_chestplate.png",
|
|
|
|
})
|
2016-02-27 10:52:46 +01:00
|
|
|
minetest.register_craftitem(name .. "_boots", {
|
2016-02-11 12:21:53 +01:00
|
|
|
description = def.description .. " Boots",
|
|
|
|
inventory_image = def.tex .. "_boots.png",
|
|
|
|
protection = def.protection,
|
|
|
|
skin = def.skin .. "_boots.png",
|
|
|
|
})
|
|
|
|
minetest.register_craftitem(name .. "_leggings", {
|
|
|
|
description = def.description .. " Leggings",
|
|
|
|
inventory_image = def.tex .. "_leggings.png",
|
|
|
|
protection = def.protection,
|
|
|
|
skin = def.skin .. "_leggings.png",
|
|
|
|
})
|
2016-03-11 18:09:38 +01:00
|
|
|
minetest.register_craftitem(name .. "_helm", {
|
|
|
|
description = def.description .. " Helm",
|
|
|
|
inventory_image = def.tex .. "_helm.png",
|
|
|
|
protection = def.protection,
|
|
|
|
skin = def.skin .. "_helm.png",
|
|
|
|
})
|
2016-02-10 12:46:16 +01:00
|
|
|
end
|
2016-02-11 12:21:53 +01:00
|
|
|
|
|
|
|
function armor.update_armor(name, pl)
|
|
|
|
local a = armor.invs[name]:get_list("main")
|
|
|
|
local p = 100
|
|
|
|
for k,v in pairs(a) do
|
|
|
|
if v:get_definition() and v:get_definition().protection then
|
|
|
|
p = p - v:get_definition().protection
|
|
|
|
end
|
2016-02-17 19:33:33 +01:00
|
|
|
armor.data[name][k] = v:to_string()
|
|
|
|
print(armor.data[name][k])
|
2016-02-11 12:21:53 +01:00
|
|
|
end
|
2016-03-06 20:21:40 +01:00
|
|
|
pl:set_armor_groups({friendly = p})
|
2016-02-17 19:33:33 +01:00
|
|
|
armor.save_armor()
|
2016-02-11 12:21:53 +01:00
|
|
|
end
|
|
|
|
|
2016-03-11 18:09:38 +01:00
|
|
|
default.inv_form = default.inv_form .. "list[detached:armor_%s;main;0,0.5;2,2;]"
|
|
|
|
default.inv_form = default.inv_form.. default.itemslot_bg(0,0.5,2,2)
|
2016-02-11 12:21:53 +01:00
|
|
|
|
2016-02-17 19:33:33 +01:00
|
|
|
function armor.load_armor()
|
|
|
|
local input = io.open(armor.armor_file, "r")
|
|
|
|
if input then
|
|
|
|
local str = input:read()
|
|
|
|
if str then
|
|
|
|
print("[INFO] armor string : " .. str)
|
|
|
|
if minetest.deserialize(str) then
|
|
|
|
armor.data = minetest.deserialize(str)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print("[WARNING] armor file is empty")
|
|
|
|
end
|
|
|
|
io.close(input)
|
|
|
|
else
|
|
|
|
print("[error] couldnt find armor file")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function armor.save_armor()
|
|
|
|
if armor.data then
|
|
|
|
local output = io.open(armor.armor_file, "w")
|
|
|
|
local str = minetest.serialize(armor.data)
|
|
|
|
output:write(str)
|
|
|
|
io.close(output)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-11 12:21:53 +01:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
2016-03-06 20:21:40 +01:00
|
|
|
player:set_armor_groups({friendly = 100})
|
2016-02-11 12:21:53 +01:00
|
|
|
if armor.invs[player:get_player_name()] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
armor.invs[player:get_player_name()] = minetest.create_detached_inventory("armor_" .. player:get_player_name(), {
|
|
|
|
on_put = function(inv, listname, index, stack, player)
|
|
|
|
armor.update_armor(player:get_player_name(), player)
|
|
|
|
end,
|
|
|
|
on_take = function(inv, listname, index, stack, player)
|
|
|
|
armor.update_armor(player:get_player_name(), player)
|
|
|
|
end,
|
|
|
|
})
|
2016-03-11 18:09:38 +01:00
|
|
|
armor.invs[player:get_player_name()]:set_size("main", 4)
|
2016-02-17 19:33:33 +01:00
|
|
|
|
|
|
|
if armor.data[player:get_player_name()] then
|
|
|
|
armor.invs[player:get_player_name()]:add_item('main', armor.data[player:get_player_name()][1])
|
|
|
|
armor.invs[player:get_player_name()]:add_item('main', armor.data[player:get_player_name()][2])
|
|
|
|
armor.invs[player:get_player_name()]:add_item('main', armor.data[player:get_player_name()][3])
|
2016-03-11 18:09:38 +01:00
|
|
|
if armor.data[player:get_player_name()][4] then
|
|
|
|
armor.invs[player:get_player_name()]:add_item('main', armor.data[player:get_player_name()][4])
|
|
|
|
end
|
2016-02-17 19:33:33 +01:00
|
|
|
else
|
|
|
|
armor.data[player:get_player_name()] = {}
|
|
|
|
end
|
2016-03-06 20:21:40 +01:00
|
|
|
armor.update_armor(player:get_player_name(), player)
|
2016-02-11 12:21:53 +01:00
|
|
|
|
|
|
|
end)
|
|
|
|
|
2016-02-17 19:33:33 +01:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
armor.save_armor()
|
|
|
|
end)
|
|
|
|
|
2016-02-11 12:21:53 +01:00
|
|
|
armor.register_armor("armor:iron", {
|
|
|
|
description = "Iron",
|
|
|
|
tex = "armor_iron",
|
2016-03-11 18:09:38 +01:00
|
|
|
protection = 12,
|
2016-02-11 12:21:53 +01:00
|
|
|
skin = "armor_skin_iron"
|
|
|
|
})
|
|
|
|
|
|
|
|
armor.register_armor("armor:copper", {
|
|
|
|
description = "Copper",
|
|
|
|
tex = "armor_copper",
|
2016-03-11 18:09:38 +01:00
|
|
|
protection = 15,
|
2016-02-11 12:21:53 +01:00
|
|
|
skin = "armor_skin_copper"
|
|
|
|
})
|
|
|
|
|
|
|
|
armor.register_armor("armor:diamond", {
|
|
|
|
description = "Diamond",
|
|
|
|
tex = "armor_diamond",
|
2016-03-11 18:09:38 +01:00
|
|
|
protection = 20,
|
2016-02-11 12:21:53 +01:00
|
|
|
skin = "armor_skin_diamond"
|
|
|
|
})
|
2016-02-17 19:33:33 +01:00
|
|
|
|
2016-02-27 10:52:46 +01:00
|
|
|
|
|
|
|
--craft
|
|
|
|
blueprint.register_blueprint("armor_diamond_chestplate", {
|
|
|
|
description = "Diamond Chestplate",
|
|
|
|
materials = {"furnace:iron_plate", "furnace:iron_plate", "default:diamond", "default:diamond"},
|
|
|
|
out = "armor:diamond_chestplate",
|
|
|
|
color = "red"
|
|
|
|
})
|
|
|
|
|
|
|
|
blueprint.register_blueprint("armor_diamond_leggings", {
|
|
|
|
description = "Diamond Leggings",
|
|
|
|
materials = {"furnace:iron_plate", "default:diamond"},
|
|
|
|
out = "armor:diamond_leggings",
|
|
|
|
color = "red"
|
|
|
|
})
|
|
|
|
|
|
|
|
blueprint.register_blueprint("armor_diamond_boots", {
|
|
|
|
description = "Diamond Boots",
|
|
|
|
materials = {"furnace:iron_plate", "default:diamond"},
|
|
|
|
out = "armor:diamond_boots",
|
|
|
|
color = "red"
|
|
|
|
})
|
|
|
|
|
2016-02-17 19:33:33 +01:00
|
|
|
armor.load_armor()
|