Improve player model hanlding and update to version 0.4.0

This commit is contained in:
stujones11
2013-11-12 21:22:52 +00:00
parent 9dbf76d013
commit 0b3deea513
29 changed files with 208 additions and 149 deletions

View File

@ -1,12 +1,13 @@
[mod] Visible Player Armor [3d_armor]
=====================================
depends: default, inventory_plus, unified_skins
depends: default, inventory_plus
Adds craftable armor that is visible to other players. Each armor item worn contibutes 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.
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.
default settings: [minetest.conf]

View File

@ -14,36 +14,64 @@ armor = {
.."list[detached:player_name_armor;armor_torso;3,1;1,1;]"
.."list[detached:player_name_armor;armor_legs;3,2;1,1;]"
.."list[detached:player_name_armor;armor_feet;3,3;1,1;]",
textures = {},
default_skin = "character.png",
}
-- armor.def - Added by BlockMen for HUD integration
armor.def = {
state = 0,
count = 0
count = 0,
}
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
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()
local armor_texture = uniskins.default_texture
local armor_texture = "3d_armor_trans.png"
local armor_level = 0
local state = 0
local items = 0
local textures = {}
for _,v in ipairs(self.elements) do
local elements = {}
for i, v in ipairs(self.elements) do
local stack = player_inv:get_stack("armor_"..v, 1)
local level = stack:get_definition().groups["armor_"..v]
local item = stack:get_name()
elements[i] = string.match(item, "%:.+_(.+)$")
if level then
local item = stack:get_name()
table.insert(textures, item:gsub("%:", "_")..".png")
armor_level = armor_level + level
state = state + stack:get_wear()
items = items+1
end
items = items + 1
end
end
if table.getn(textures) > 0 then
if minetest.get_modpath("shields") then
armor_level = armor_level * 0.9
end
if elements[1] == elements[2] and
elements[1] == elements[3] and
elements[1] == elements[4] then
armor_level = armor_level * 1.1
end
if #textures > 0 then
armor_texture = table.concat(textures, "^")
end
local armor_groups = {fleshy=100}
@ -52,10 +80,10 @@ armor.set_player_armor = function(self, player)
armor_groups.fleshy = 100 - armor_level
end
player:set_armor_groups(armor_groups)
uniskins.armor[name] = armor_texture
uniskins:update_player_visuals(player)
armor.def[name].state = state
armor.def[name].count = items
self.textures[name].armor = armor_texture
self.def[name].state = state
self.def[name].count = items
self:update_player_visuals(player)
end
armor.update_armor = function(self, player)
@ -86,27 +114,46 @@ armor.update_armor = function(self, player)
armor_inv:set_stack("armor_"..v, 1, stack)
player_inv:set_stack("armor_"..v, 1, stack)
state = state + stack:get_wear()
items = items+1
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
end
self:set_player_armor(player)
end
heal_max = heal_max + heal
end
end
armor.def[name].state = state
armor.def[name].count = items
self.def[name].state = state
self.def[name].count = items
if heal_max > math.random(100) then
player:set_hp(self.player_hp[name])
return
end
end
end
self.player_hp[name] = hp
end
-- Register Player Model
default.player_register_model("3d_armor_character.x", {
animation_speed = 30,
textures = {
armor.default_skin,
"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},
},
})
-- Register Callbacks
minetest.register_on_player_receive_fields(function(player, formname, fields)
@ -117,16 +164,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
for field, _ in pairs(fields) do
if string.sub(field,0,string.len("skins_set_")) == "skins_set_" then
if string.find(field, "^skins_set_") then
minetest.after(0, function(player)
uniskins.skin[name] = skins.skins[name]..".png"
uniskins:update_player_visuals(player)
armor.textures[name].skin = skins.skins[name]..".png"
armor:update_player_visuals(player)
end, player)
end
end
end)
minetest.register_on_joinplayer(function(player)
default.player_set_model(player, "3d_armor_character.x")
inventory_plus.register_button(player,"armor", "Armor")
local player_inv = player:get_inventory()
local name = player:get_player_name()
@ -158,14 +206,33 @@ minetest.register_on_joinplayer(function(player)
armor_inv:set_size(list, 1)
armor_inv:set_stack(list, 1, player_inv:get_stack(list, 1))
end
armor.player_hp[name] = 0
armor.player_hp[name] = 0
armor.def[name] = {
state = 0,
count = 0
state = 0,
count = 0,
}
armor.textures[name] = {
skin = armor.default_skin,
armor = "3d_armor_trans.png",
wielditem = "3d_armor_trans.png",
}
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
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
minetest.after(0, function(player)
armor:set_player_armor(player)
end, player)
end, player)
end)
minetest.register_globalstep(function(dtime)

View File

@ -15,6 +15,7 @@ Helmets:
[3d_armor:helmet_steel] X = [default:steel_ingot]
[3d_armor:helmet_bronze] X = [default:bronze_ingot]
[3d_armor:helmet_diamond] X = [default:diamond]
[3d_armor:helmet_mithril] X = [moreores:mithril_ingot] *
Chestplates:
@ -30,6 +31,7 @@ Chestplates:
[3d_armor:chestplate_steel] X = [default:steel_ingot]
[3d_armor:chestplate_bronze] X = [default:bronze_ingot]
[3d_armor:chestplate_diamond] X = [default:diamond]
[3d_armor:chestplate_mithril] X = [moreores:mithril_ingot] *
Leggings:
@ -45,6 +47,7 @@ Leggings:
[3d_armor:leggings_steel] X = [default:steel_ingot]
[3d_armor:leggings_bronze] X = [default:bronze_ingot]
[3d_armor:leggings_diamond] X = [default:diamond]
[3d_armor:leggings_mithril] X = [moreores:mithril_ingot] *
Boots:
@ -58,4 +61,7 @@ Boots:
[3d_armor:boots_steel] X = [default:steel_ingot]
[3d_armor:boots_bronze] X = [default:bronze_ingot
[3d_armor:boots_diamond] X = [default:diamond]
[3d_armor:boots_mithril] X = [moreores:mithril_ingot] *
* Requires moreores mod by Calinou - https://forum.minetest.net/viewtopic.php?id=549

View File

@ -1,3 +1,3 @@
default
inventory_plus
unified_skins

View File

@ -1,4 +1,5 @@
dofile(minetest.get_modpath(minetest.get_current_modname()).."/armor.lua")
local use_moreores = minetest.get_modpath("moreores")
-- Regisiter Head Armor
@ -30,6 +31,14 @@ minetest.register_tool("3d_armor:helmet_diamond", {
wear = 0,
})
if use_moreores then
minetest.register_tool("3d_armor:helmet_mithril", {
description = "Mithril Helmet",
inventory_image = "3d_armor_inv_helmet_mithril.png",
groups = {armor_head=15, armor_heal=12, armor_use=50},
wear = 0,
})
end
-- Regisiter Torso Armor
@ -61,6 +70,14 @@ minetest.register_tool("3d_armor:chestplate_diamond", {
wear = 0,
})
if use_moreores then
minetest.register_tool("3d_armor:chestplate_mithril", {
description = "Mithril Chestplate",
inventory_image = "3d_armor_inv_chestplate_mithril.png",
groups = {armor_torso=20, armor_heal=12, armor_use=50},
wear = 0,
})
end
-- Regisiter Leg Armor
@ -92,6 +109,15 @@ minetest.register_tool("3d_armor:leggings_diamond", {
wear = 0,
})
if use_moreores then
minetest.register_tool("3d_armor:leggings_mithril", {
description = "Mithril Leggings",
inventory_image = "3d_armor_inv_leggings_mithril.png",
groups = {armor_legs=20, armor_heal=12, armor_use=50},
wear = 0,
})
end
-- Regisiter Boots
minetest.register_tool("3d_armor:boots_wood", {
@ -122,6 +148,15 @@ minetest.register_tool("3d_armor:boots_diamond", {
wear = 0,
})
if use_moreores then
minetest.register_tool("3d_armor:boots_mithril", {
description = "Mithril Boots",
inventory_image = "3d_armor_inv_boots_mithril.png",
groups = {armor_feet=15, armor_heal=12, armor_use=50},
wear = 0,
})
end
-- Register Craft Recipies
local craft_ingreds = {
@ -129,7 +164,11 @@ local craft_ingreds = {
steel = "default:steel_ingot",
bronze = "default:bronze_ingot",
diamond = "default:diamond",
}
}
if use_moreores then
craft_ingreds.mithril = "moreores:mithril_ingot"
end
for k, v in pairs(craft_ingreds) do
minetest.register_craft({
@ -165,4 +204,3 @@ for k, v in pairs(craft_ingreds) do
})
end

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B