Make armor more configurable

This commit is contained in:
stujones11 2014-04-13 20:17:11 +01:00
parent 8457220413
commit 8a881022e9
5 changed files with 115 additions and 33 deletions

@ -1,7 +1,9 @@
[mod] Visible Player Armor [3d_armor] [mod] Visible Player Armor [3d_armor]
===================================== =====================================
depends: default, inventory_plus Depends: default
Recommends: inventory_plus or unified_inventory (use only one)
Adds craftable armor that is visible to other players. Each armor item worn contributes to Adds craftable armor that is visible to other players. Each armor item worn contributes to
a player's armor group level making them less vulnerable to weapons. a player's armor group level making them less vulnerable to weapons.
@ -9,8 +11,9 @@ a player's armor group level making them less vulnerable to weapons.
Armor takes damage when a player is hurt but also offers a percentage chance of healing. Armor takes damage when a player is hurt but also offers a percentage chance of healing.
Overall level is boosted by 10% when wearing a full matching set. Overall level is boosted by 10% when wearing a full matching set.
default settings: [minetest.conf] Configuration
-------------
# Set number of seconds between armor updates. Armor can be configured by adding a file called armor.conf in 3d_armor mod directory.
3d_armor_update_time = 1 see armor.conf.example for all available options.

@ -0,0 +1,30 @@
--Armor Configuration (defaults)
-- Increase this if you get initialization glitches when a player first joins.
ARMOR_INIT_DELAY = 1
-- Number of initialization attempts.
-- Use in conjunction with ARMOR_INIT_DELAY if initialization problems persist.
ARMOR_INIT_TIMES = 1
-- Increase this if armor is not getting into bones due to server lag.
ARMOR_BONES_DELAY = 1
-- How often player armor/wield items are updated.
ARMOR_UPDATE_TIME = 1
-- Drop armor when a player dies.
-- Uses bones mod if present, otherwise items are dropped around the player.
ARMOR_DROP = true
-- Pulverise armor when a player dies, overrides ARMOR_DROP.
ARMOR_DESTROY = false
-- You can use this to increase or decrease armor effectiveness,
-- eg: ARMOR_LEVEL_MULTIPLIER = 0.5 will reduce armor level by half,
ARMOR_LEVEL_MULTIPLIER = 1
-- You can use this to increase or decrease armor effectiveness,
-- eg: ARMOR_HEAL_MULTIPLIER = 0 will disable healing altogether.
ARMOR_HEAL_MULTIPLIER = 1

@ -1,9 +1,20 @@
local time = 0 ARMOR_INIT_DELAY = 1
local update_time = tonumber(minetest.setting_get("3d_armor_update_time")) ARMOR_INIT_TIMES = 1
if not update_time then ARMOR_BONES_DELAY = 1
update_time = 1 ARMOR_UPDATE_TIME = 1
minetest.setting_set("3d_armor_update_time", tostring(update_time)) 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
end end
local time = 0
armor = { armor = {
player_hp = {}, player_hp = {},
@ -125,6 +136,8 @@ armor.set_player_armor = function(self, player)
if material.type and material.count == #self.elements then if material.type and material.count == #self.elements then
armor_level = armor_level * 1.1 armor_level = armor_level * 1.1
end end
armor_level = armor_level * ARMOR_LEVEL_MULTIPLIER
armor_heal = armor_heal * ARMOR_HEAL_MULTIPLIER
if #textures > 0 then if #textures > 0 then
armor_texture = table.concat(textures, "^") armor_texture = table.concat(textures, "^")
end end
@ -185,6 +198,7 @@ armor.update_armor = function(self, player)
end end
self.def[name].state = state self.def[name].state = state
self.def[name].count = items self.def[name].count = items
heal_max = heal_max * ARMOR_HEAL_MULTIPLIER
if heal_max > math.random(100) then if heal_max > math.random(100) then
player:set_hp(self.player_hp[name]) player:set_hp(self.player_hp[name])
return return
@ -225,7 +239,7 @@ end
default.player_register_model("3d_armor_character.x", { default.player_register_model("3d_armor_character.x", {
animation_speed = 30, animation_speed = 30,
textures = { textures = {
armor.default_skin, armor.default_skin..".png",
"3d_armor_trans.png", "3d_armor_trans.png",
"3d_armor_trans.png", "3d_armor_trans.png",
}, },
@ -340,15 +354,17 @@ minetest.register_on_joinplayer(function(player)
armor.textures[name].skin = "player_"..name..".png" armor.textures[name].skin = "player_"..name..".png"
end end
end end
minetest.after(1, function(player) for i=1, ARMOR_INIT_TIMES do
armor:set_player_armor(player) minetest.after(ARMOR_INIT_DELAY * i, function(player)
if inventory_plus == nil and unified_inventory == nil then armor:set_player_armor(player)
armor:update_inventory(player) if inventory_plus == nil and unified_inventory == nil then
end armor:update_inventory(player)
end, player) end
end, player)
end
end) end)
if minetest.get_modpath("bones") then if ARMOR_DROP == true or ARMOR_DESTROY == true then
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local pos = player:getpos() local pos = player:getpos()
@ -359,33 +375,62 @@ if minetest.get_modpath("bones") then
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"}) local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
for i=1, player_inv:get_size("armor") do for i=1, player_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i) local stack = armor_inv:get_stack("armor", i)
table.insert(drop, stack) if stack:get_count() > 0 then
armor_inv:set_stack("armor", i, nil) table.insert(drop, stack)
player_inv:set_stack("armor", i, nil) armor_inv:set_stack("armor", i, nil)
player_inv:set_stack("armor", i, nil)
end
end end
armor:set_player_armor(player) armor:set_player_armor(player)
minetest.after(1, function() --TODO: Make delay configurable if unified_inventory then
local node = minetest.get_node(pos) unified_inventory.set_inventory_formspec(player, "craft")
if node.name == "bones:bones" then elseif inventory_plus then
local meta = minetest.get_meta(pos) local formspec = inventory_plus.get_formspec(player,"main")
local owner = meta:get_string("owner") inventory_plus.set_inventory_formspec(player, formspec)
local inv = meta:get_inventory() else
if name == owner then armor:update_inventory(player)
for _,stack in ipairs(drop) do end
if inv:room_for_item("main", stack) then if ARMOR_DESTROY == false then
inv:add_item("main", stack) 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
end end
end end
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
end end
end end
end) end
end end
end) end)
end end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
time = time + dtime time = time + dtime
if time > update_time then if time > ARMOR_UPDATE_TIME then
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
armor:update_armor(player) armor:update_armor(player)
end end

@ -1,4 +1,5 @@
dofile(minetest.get_modpath(minetest.get_current_modname()).."/armor.lua") ARMOR_MOD_NAME = minetest.get_current_modname()
dofile(minetest.get_modpath(ARMOR_MOD_NAME).."/armor.lua")
local use_moreores = minetest.get_modpath("moreores") local use_moreores = minetest.get_modpath("moreores")
-- Regisiter Head Armor -- Regisiter Head Armor

@ -17,6 +17,9 @@ when wearing a full matching set (helmet, chestplate, leggings and boots of the
Compatible with player skins [skins] by Zeg9 and Player Textures [player_textures] by PilzAdam. Compatible with player skins [skins] by Zeg9 and Player Textures [player_textures] by PilzAdam.
Armor can be configured by adding a file called armor.conf in 3d_armor mod directory.
see armor.conf.example for all available options.
[mod] Visible Wielded Items [wieldview] [mod] Visible Wielded Items [wieldview]
--------------------------------------- ---------------------------------------