2014-04-13 21:17:11 +02:00
|
|
|
ARMOR_INIT_DELAY = 1
|
|
|
|
ARMOR_INIT_TIMES = 1
|
|
|
|
ARMOR_BONES_DELAY = 1
|
|
|
|
ARMOR_UPDATE_TIME = 1
|
|
|
|
ARMOR_DROP = true
|
|
|
|
ARMOR_DESTROY = false
|
|
|
|
ARMOR_LEVEL_MULTIPLIER = 1
|
|
|
|
ARMOR_HEAL_MULTIPLIER = 1
|
|
|
|
|
|
|
|
local modpath = minetest.get_modpath(ARMOR_MOD_NAME)
|
|
|
|
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-04-13 21:17:11 +02:00
|
|
|
local time = 0
|
2013-06-22 20:31:57 +02:00
|
|
|
|
|
|
|
armor = {
|
|
|
|
player_hp = {},
|
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"},
|
2014-04-13 18:41:19 +02:00
|
|
|
formspec = "size[8,8.5]list[detached:player_name_armor;armor;0,1;2,3;]"
|
|
|
|
.."image[2,0.75;2,4;armor_preview]"
|
|
|
|
.."list[current_player;main;0,4.5;8,4;]"
|
|
|
|
.."list[current_player;craft;4,1;3,3;]"
|
|
|
|
.."list[current_player;craftpreview;7,2;1,1;]",
|
2013-11-12 22:22:52 +01:00
|
|
|
textures = {},
|
2014-04-13 18:41:19 +02:00
|
|
|
default_skin = "character",
|
2013-06-22 20:31:57 +02:00
|
|
|
}
|
|
|
|
|
2014-04-13 18:41:19 +02:00
|
|
|
if inventory_plus then
|
|
|
|
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
|
|
|
|
unified_inventory.register_button("armor", {
|
|
|
|
type = "image",
|
|
|
|
image = "inventory_plus_armor.png",
|
|
|
|
})
|
|
|
|
unified_inventory.register_page("armor", {
|
|
|
|
get_formspec = function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local formspec = "background[0.06,0.99;7.92,7.52;3d_armor_ui_form.png]"
|
|
|
|
.."label[0,0;Armor]"
|
|
|
|
.."list[detached:"..name.."_armor;armor;0,1;2,3;]"
|
|
|
|
.."image[2.5,0.75;2,4;"..armor.textures[name].preview.."]"
|
|
|
|
.."label[5,1;Level: "..armor.def[name].level.."]"
|
|
|
|
.."label[5,1.5;Heal: "..armor.def[name].heal.."]"
|
|
|
|
return {formspec=formspec}
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
|
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)
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local player_inv = player:get_inventory()
|
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
|
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}
|
|
|
|
local preview = armor:get_player_skin(name).."_preview.png"
|
|
|
|
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
|
|
|
|
local texture = item:gsub("%:", "_")
|
|
|
|
table.insert(textures, texture..".png")
|
|
|
|
preview = preview.."^"..texture.."_preview.png"
|
|
|
|
armor_level = armor_level + level
|
|
|
|
state = state + stack:get_wear()
|
|
|
|
items = items + 1
|
|
|
|
local heal = def.groups["armor_heal"] or 0
|
|
|
|
armor_heal = armor_heal + heal
|
|
|
|
for kk,vv in ipairs(self.physics) do
|
|
|
|
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
|
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
|
|
|
|
end
|
|
|
|
player:set_armor_groups(armor_groups)
|
2014-04-13 18:41:19 +02:00
|
|
|
player:set_physics_override(physics_o)
|
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
|
2013-11-12 22:22:52 +01:00
|
|
|
self:update_player_visuals(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
armor.update_armor = function(self, player)
|
|
|
|
if not player then
|
|
|
|
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
|
|
|
|
end
|
|
|
|
if self.player_hp[name] > hp then
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
|
|
|
if not armor_inv then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local heal_max = 0
|
2013-09-12 01:08:11 +02:00
|
|
|
local state = 0
|
|
|
|
local items = 0
|
2014-04-13 18:41:19 +02:00
|
|
|
for i=1, 6 do
|
|
|
|
local stack = player_inv:get_stack("armor", i)
|
2013-06-22 20:31:57 +02:00
|
|
|
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)
|
2014-04-13 18:41:19 +02:00
|
|
|
armor_inv:set_stack("armor", i, stack)
|
|
|
|
player_inv:set_stack("armor", i, stack)
|
2013-09-12 01:08:11 +02:00
|
|
|
state = state + stack:get_wear()
|
2013-11-12 22:22:52 +01:00
|
|
|
items = items + 1
|
2013-06-22 20:31:57 +02:00
|
|
|
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!")
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
2013-06-22 20:31:57 +02:00
|
|
|
self:set_player_armor(player)
|
2014-04-14 20:25:10 +02:00
|
|
|
armor:update_inventory(player)
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
|
|
|
heal_max = heal_max + heal
|
|
|
|
end
|
|
|
|
end
|
2013-11-12 22:22:52 +01:00
|
|
|
self.def[name].state = state
|
|
|
|
self.def[name].count = items
|
2014-04-13 21:17:11 +02:00
|
|
|
heal_max = heal_max * ARMOR_HEAL_MULTIPLIER
|
2013-06-22 20:31:57 +02:00
|
|
|
if heal_max > math.random(100) then
|
|
|
|
player:set_hp(self.player_hp[name])
|
|
|
|
return
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
|
|
|
self.player_hp[name] = hp
|
|
|
|
end
|
|
|
|
|
2014-04-13 18:41:19 +02:00
|
|
|
armor.get_player_skin = function(self, name)
|
|
|
|
local skin = nil
|
|
|
|
if skins then
|
|
|
|
skin = skins.skins[name]
|
|
|
|
elseif u_skins then
|
|
|
|
skin = u_skins.u_skins[name]
|
|
|
|
end
|
|
|
|
return skin or armor.default_skin
|
|
|
|
end
|
|
|
|
|
2014-04-14 20:25:10 +02:00
|
|
|
armor.get_armor_formspec = function(self, name)
|
|
|
|
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)
|
|
|
|
return formspec:gsub("armor_heal", armor.def[name].heal)
|
|
|
|
end
|
|
|
|
|
2014-04-13 18:41:19 +02:00
|
|
|
armor.update_inventory = function(self, player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if 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
|
2014-04-14 20:25:10 +02:00
|
|
|
local formspec = armor:get_armor_formspec(name)
|
|
|
|
if inventory_plus then
|
|
|
|
local page = player:get_inventory_formspec()
|
|
|
|
if page:find("detached:"..name.."_armor") then
|
|
|
|
inventory_plus.set_inventory_formspec(player, formspec)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
player:set_inventory_formspec(formspec)
|
|
|
|
end
|
2014-04-13 18:41:19 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-12 22:22:52 +01:00
|
|
|
-- Register Player Model
|
|
|
|
|
|
|
|
default.player_register_model("3d_armor_character.x", {
|
|
|
|
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)
|
|
|
|
local name = player:get_player_name()
|
2014-04-14 20:25:10 +02:00
|
|
|
if inventory_plus and fields.armor then
|
|
|
|
local formspec = armor:get_armor_formspec(name)
|
|
|
|
inventory_plus.set_inventory_formspec(player, formspec)
|
2013-06-22 20:31:57 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
for field, _ in pairs(fields) do
|
2014-04-13 18:41:19 +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)
|
2013-11-12 22:22:52 +01:00
|
|
|
default.player_set_model(player, "3d_armor_character.x")
|
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()
|
2013-06-22 20:31:57 +02:00
|
|
|
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)
|
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,
|
|
|
|
})
|
2014-04-13 18:41:19 +02:00
|
|
|
if inventory_plus then
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Legacy support, import player's armor from old inventory format
|
|
|
|
for _,v in pairs(armor.elements) do
|
2013-06-22 20:31:57 +02:00
|
|
|
local list = "armor_"..v
|
2014-04-13 18:41:19 +02:00
|
|
|
armor_inv:add_item("armor", player_inv:get_stack(list, 1))
|
|
|
|
player_inv:set_stack(list, 1, nil)
|
2013-06-22 20:31:57 +02:00
|
|
|
end
|
2014-04-13 18:41:19 +02:00
|
|
|
|
2013-11-12 22:22:52 +01:00
|
|
|
armor.player_hp[name] = 0
|
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,
|
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
|
|
|
}
|
|
|
|
if minetest.get_modpath("skins") then
|
|
|
|
local skin = skins.skins[name]
|
|
|
|
if skin and skins.get_type(skin) == skins.type.MODEL then
|
|
|
|
armor.textures[name].skin = skin..".png"
|
|
|
|
end
|
2014-04-13 18:41:19 +02:00
|
|
|
elseif minetest.get_modpath("u_skins") then
|
|
|
|
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
|
2013-11-12 22:22:52 +01:00
|
|
|
end
|
|
|
|
if minetest.get_modpath("player_textures") then
|
|
|
|
local filename = minetest.get_modpath("player_textures").."/textures/player_"..name
|
|
|
|
local f = io.open(filename..".png")
|
|
|
|
if f then
|
|
|
|
f:close()
|
|
|
|
armor.textures[name].skin = "player_"..name..".png"
|
|
|
|
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)
|
|
|
|
if inventory_plus == nil and unified_inventory == nil then
|
|
|
|
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)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local pos = player:getpos()
|
|
|
|
if name and pos then
|
|
|
|
pos = vector.round(pos)
|
|
|
|
local drop = {}
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
2014-04-13 18:41:19 +02:00
|
|
|
for i=1, player_inv:get_size("armor") do
|
|
|
|
local stack = armor_inv:get_stack("armor", i)
|
2014-04-13 21:17:11 +02:00
|
|
|
if stack:get_count() > 0 then
|
|
|
|
table.insert(drop, stack)
|
|
|
|
armor_inv:set_stack("armor", i, nil)
|
|
|
|
player_inv:set_stack("armor", i, nil)
|
|
|
|
end
|
2014-04-08 23:03:01 +02:00
|
|
|
end
|
|
|
|
armor:set_player_armor(player)
|
2014-04-14 20:25:10 +02:00
|
|
|
armor:update_inventory(player)
|
2014-04-13 21:17:11 +02:00
|
|
|
if ARMOR_DESTROY == false then
|
|
|
|
if minetest.get_modpath("bones") then
|
|
|
|
minetest.after(ARMOR_BONES_DELAY, function()
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.name == "bones:bones" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if name == owner then
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
if inv:room_for_item("main", stack) then
|
|
|
|
inv:add_item("main", stack)
|
|
|
|
end
|
|
|
|
end
|
2014-04-08 23:03:01 +02:00
|
|
|
end
|
|
|
|
end
|
2014-04-13 21:17:11 +02:00
|
|
|
end)
|
|
|
|
else
|
|
|
|
for _,stack in ipairs(drop) do
|
|
|
|
local obj = minetest.add_item(pos, stack:get_name())
|
|
|
|
if obj then
|
|
|
|
local x = math.random(1, 5)
|
|
|
|
if math.random(1,2) == 1 then
|
|
|
|
x = -x
|
|
|
|
end
|
|
|
|
local z = math.random(1, 5)
|
|
|
|
if math.random(1,2) == 1 then
|
|
|
|
z = -z
|
|
|
|
end
|
|
|
|
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
|
|
|
|
end
|
2014-04-08 23:03:01 +02:00
|
|
|
end
|
|
|
|
end
|
2014-04-13 21:17:11 +02:00
|
|
|
end
|
2014-04-08 23:03:01 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2013-06-22 20:31:57 +02:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
time = time + dtime
|
2014-04-13 21:17:11 +02:00
|
|
|
if time > ARMOR_UPDATE_TIME then
|
2013-06-22 20:31:57 +02:00
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
|
|
|
armor:update_armor(player)
|
|
|
|
end
|
|
|
|
time = 0
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|