forked from mtcontrib/3d_armor
Updated 3d_armor files.
This commit is contained in:
parent
04e4d2af6f
commit
aedff2cc55
@ -1,56 +1,15 @@
|
||||
|
||||
armor_api = {
|
||||
default_character_skin = "character.png",
|
||||
player_hp = {},
|
||||
wielded_items = {},
|
||||
}
|
||||
|
||||
armor_api.get_player_skin = function(self, name)
|
||||
local mod_path = minetest.get_modpath("skins")
|
||||
if mod_path then
|
||||
local skin = skins.skins[name]
|
||||
if skin then
|
||||
if skins.get_type(skin) == skins.type.MODEL then
|
||||
return skin..".png"
|
||||
end
|
||||
end
|
||||
end
|
||||
return self.default_character_skin
|
||||
end
|
||||
|
||||
armor_api.get_wielded_item_texture = function(self, player)
|
||||
if not player then
|
||||
return nil
|
||||
end
|
||||
local stack = player:get_wielded_item()
|
||||
local item = stack:get_name()
|
||||
if not item then
|
||||
return nil
|
||||
end
|
||||
if not minetest.registered_items[item] then
|
||||
return nil
|
||||
end
|
||||
local texture = minetest.registered_items[item].inventory_image
|
||||
if texture == "" then
|
||||
if not minetest.registered_items[item].tiles then
|
||||
return nil
|
||||
end
|
||||
texture = minetest.registered_items[item].tiles[1]
|
||||
end
|
||||
return texture
|
||||
end
|
||||
|
||||
armor_api.set_player_armor = function(self, player)
|
||||
armor_api.get_player_armor = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local texture = "3d_armor_character_bg.png^[combine:64x64:0,32="..self:get_player_skin(name)
|
||||
local texture = ""
|
||||
local player_inv = player:get_inventory()
|
||||
local wielded_item_texture = self:get_wielded_item_texture(player)
|
||||
if wielded_item_texture then
|
||||
texture = texture.."^[combine:64x64:0,0="..wielded_item_texture
|
||||
end
|
||||
local armor = {head, torso, legs, shield}
|
||||
for _,v in ipairs({"head", "torso", "legs"}) do
|
||||
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||
@ -74,34 +33,14 @@ armor_api.set_player_armor = function(self, player)
|
||||
)
|
||||
local level = (armor_level / 2) + 0.5
|
||||
local fleshy = 3 - (armor_level / 2)
|
||||
if fleshy < 0 then
|
||||
fleshy = 0
|
||||
end
|
||||
local armor_groups = {level=1, fleshy=3, snappy=1, choppy=1}
|
||||
armor_groups.level = level
|
||||
armor_groups.fleshy = fleshy
|
||||
player:set_armor_groups(armor_groups)
|
||||
player:set_properties({
|
||||
visual = "mesh",
|
||||
textures = {texture},
|
||||
visual_size = {x=1, y=1},
|
||||
})
|
||||
end
|
||||
|
||||
armor_api.update_wielded_item = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local stack = player:get_wielded_item()
|
||||
local item = stack:get_name()
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
if self.wielded_items[name] then
|
||||
if self.wielded_items[name] == item then
|
||||
return
|
||||
end
|
||||
self:set_player_armor(player)
|
||||
end
|
||||
self.wielded_items[name] = item
|
||||
return texture
|
||||
end
|
||||
|
||||
armor_api.update_armor = function(self, player)
|
||||
@ -134,7 +73,7 @@ armor_api.update_armor = function(self, player)
|
||||
if desc then
|
||||
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
||||
end
|
||||
self:set_player_armor(player)
|
||||
wieldview:update_player_visuals(player)
|
||||
end
|
||||
heal_max = heal_max + heal
|
||||
end
|
||||
|
@ -1,13 +1,15 @@
|
||||
|
||||
local time = 0
|
||||
local update_time = tonumber(minetest.setting_get("3d_armor_update_time"))
|
||||
if update_time == nil then
|
||||
update_time = 2
|
||||
minetest.setting_set("3d_armor_update_time", tostring(update_time))
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/armor_api.lua")
|
||||
|
||||
-- Regisiter Head Armor
|
||||
|
||||
minetest.register_tool("3d_armor:helmet_wood", {
|
||||
description = "Wood Helmet",
|
||||
inventory_image = "3d_armor_inv_helmet_wood.png",
|
||||
groups = {armor_head=2, armor_heal=10, armor_use=5000},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:helmet_steel", {
|
||||
description = "Steel Helmet",
|
||||
inventory_image = "3d_armor_inv_helmet_steel.png",
|
||||
@ -15,39 +17,13 @@ minetest.register_tool("3d_armor:helmet_steel", {
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:chestplate_steel", {
|
||||
description = "Steel Chestplate",
|
||||
inventory_image = "3d_armor_inv_chestplate_steel.png",
|
||||
groups = {armor_torso=3, armor_heal=20, armor_use=2500},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:leggings_steel", {
|
||||
description = "Steel Leggings",
|
||||
inventory_image = "3d_armor_inv_leggings_steel.png",
|
||||
groups = {armor_legs=3, armor_heal=15, armor_use=1500},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:shield_steel", {
|
||||
description = "Steel Shield",
|
||||
inventory_image = "3d_armor_inv_shield_steel.png",
|
||||
groups = {armor_shield=3, armor_heal=20, armor_use=1500},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:shield_wood", {
|
||||
description = "Wooden Shield",
|
||||
inventory_image = "3d_armor_inv_shield_wood.png",
|
||||
groups = {armor_shield=2, armor_heal=10, armor_use=10000},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:shield_enhanced_wood", {
|
||||
description = "Enhanced Wooden Shield",
|
||||
inventory_image = "3d_armor_inv_shield_enhanced_wood.png",
|
||||
groups = {armor_shield=2, armor_heal=15, armor_use=3000},
|
||||
wear = 0,
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:helmet_wood",
|
||||
recipe = {
|
||||
{"default:wood", "default:wood", "default:wood"},
|
||||
{"default:wood", "", "default:wood"},
|
||||
{"", "", ""},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -59,6 +35,31 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
-- Regisiter Torso Armor
|
||||
|
||||
minetest.register_tool("3d_armor:chestplate_wood", {
|
||||
description = "Wood Chestplate",
|
||||
inventory_image = "3d_armor_inv_chestplate_wood.png",
|
||||
groups = {armor_torso=2, armor_heal=10, armor_use=5000},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:chestplate_steel", {
|
||||
description = "Steel Chestplate",
|
||||
inventory_image = "3d_armor_inv_chestplate_steel.png",
|
||||
groups = {armor_torso=3, armor_heal=15, armor_use=2500},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:chestplate_wood",
|
||||
recipe = {
|
||||
{"default:wood", "", "default:wood"},
|
||||
{"default:wood", "default:wood", "default:wood"},
|
||||
{"default:wood", "default:wood", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:chestplate_steel",
|
||||
recipe = {
|
||||
@ -68,6 +69,31 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
-- Regisiter Leg Armor
|
||||
|
||||
minetest.register_tool("3d_armor:leggings_wood", {
|
||||
description = "Wood Leggings",
|
||||
inventory_image = "3d_armor_inv_leggings_wood.png",
|
||||
groups = {armor_legs=2, armor_heal=10, armor_use=5000},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:leggings_steel", {
|
||||
description = "Steel Leggings",
|
||||
inventory_image = "3d_armor_inv_leggings_steel.png",
|
||||
groups = {armor_legs=3, armor_heal=15, armor_use=1500},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:leggings_wood",
|
||||
recipe = {
|
||||
{"default:wood", "default:wood", "default:wood"},
|
||||
{"default:wood", "", "default:wood"},
|
||||
{"default:wood", "", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:leggings_steel",
|
||||
recipe = {
|
||||
@ -77,13 +103,27 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:shield_steel",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"", "default:steel_ingot", ""},
|
||||
},
|
||||
-- Regisiter Shields
|
||||
|
||||
minetest.register_tool("3d_armor:shield_wood", {
|
||||
description = "Wooden Shield",
|
||||
inventory_image = "3d_armor_inv_shield_wood.png",
|
||||
groups = {armor_shield=1, armor_heal=10, armor_use=10000},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:shield_enhanced_wood", {
|
||||
description = "Enhanced Wooden Shield",
|
||||
inventory_image = "3d_armor_inv_shield_enhanced_wood.png",
|
||||
groups = {armor_shield=2, armor_heal=15, armor_use=3000},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_tool("3d_armor:shield_steel", {
|
||||
description = "Steel Shield",
|
||||
inventory_image = "3d_armor_inv_shield_steel.png",
|
||||
groups = {armor_shield=3, armor_heal=20, armor_use=1500},
|
||||
wear = 0,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -104,6 +144,17 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "3d_armor:shield_steel",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"", "default:steel_ingot", ""},
|
||||
},
|
||||
})
|
||||
|
||||
-- Register Callbacks
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
if fields.outfit then
|
||||
@ -119,7 +170,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
for field, _ in pairs(fields) do
|
||||
if string.sub(field,0,string.len("skins_set_")) == "skins_set_" then
|
||||
minetest.after(1, function(player)
|
||||
armor_api:set_player_armor(player)
|
||||
wieldview:update_player_visuals(player)
|
||||
end, player)
|
||||
end
|
||||
end
|
||||
@ -132,11 +183,11 @@ minetest.register_on_joinplayer(function(player)
|
||||
local armor_inv = minetest.create_detached_inventory(name.."_outfit",{
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, stack)
|
||||
armor_api:set_player_armor(player)
|
||||
wieldview:update_player_visuals(player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, nil)
|
||||
armor_api:set_player_armor(player)
|
||||
wieldview:update_player_visuals(player)
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if inv:is_empty(listname) then
|
||||
@ -147,6 +198,9 @@ minetest.register_on_joinplayer(function(player)
|
||||
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 0
|
||||
end,
|
||||
})
|
||||
for _,v in ipairs({"head", "torso", "legs", "shield"}) do
|
||||
local armor = "armor_"..v
|
||||
@ -155,26 +209,5 @@ minetest.register_on_joinplayer(function(player)
|
||||
armor_inv:set_stack(armor, 1, player_inv:get_stack(armor, 1))
|
||||
end
|
||||
armor_api.player_hp[name] = 0
|
||||
local texture = armor_api:get_player_skin(name)
|
||||
player:set_properties({
|
||||
visual = "mesh",
|
||||
mesh = "3d_armor_character.x",
|
||||
textures = {texture},
|
||||
visual_size = {x=1, y=1},
|
||||
})
|
||||
minetest.after(1, function(player)
|
||||
armor_api:set_player_armor(player)
|
||||
end, player)
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
time = time + dtime
|
||||
if time > update_time then
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
armor_api:update_wielded_item(player)
|
||||
armor_api:update_armor(player)
|
||||
end
|
||||
time = 0
|
||||
end
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user