1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-18 00:08:25 +01:00

Updated 3d_armor

- Updated models
 - Updated armor.lua : new skin mod supported, and new method to drop the armor
This commit is contained in:
LeMagnesium 2015-04-26 12:05:41 +02:00
parent 681c2af852
commit 7932cf13fd
3 changed files with 99 additions and 91 deletions

View File

@ -88,6 +88,8 @@ elseif minetest.get_modpath("simple_skins") then
skin_mod = "simple_skins"
elseif minetest.get_modpath("u_skins") then
skin_mod = "u_skins"
elseif minetest.get_modpath("wardrobe") then
skin_mod = "wardrobe"
end
armor.def = {
@ -110,17 +112,8 @@ armor.update_player_visuals = function(self, player)
end
armor.set_player_armor = function(self, player)
if not player then
return
end
local name = player:get_player_name()
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
if not name then
minetest.log("error", "3d_armor: Player name is nil [set_player_armor]")
return
end
local player_inv = player:get_inventory()
if not player_inv then
minetest.log("error", "3d_armor: Player inventory is nil [set_player_armor]")
return
end
local armor_texture = "3d_armor_trans.png"
@ -204,13 +197,8 @@ armor.set_player_armor = function(self, player)
end
armor.update_armor = function(self, player)
if not player then
minetest.log("error", "3d_armor: Player reference is nil [update_armor]")
return
end
local name = player:get_player_name()
local name, player_inv, armor_inv = armor:get_valid_player(player, "[update_armor]")
if not name then
minetest.log("error", "3d_armor: Player name is nil[update_armor]")
return
end
local hp = player:get_hp() or 0
@ -218,15 +206,6 @@ armor.update_armor = function(self, player)
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 player_inv then
minetest.log("error", "3d_armor: Player inventory is nil [update_armor]")
return
elseif not armor_inv then
minetest.log("error", "3d_armor: Detached inventory is nil [update_armor]")
return
end
local heal_max = 0
local state = 0
local items = 0
@ -269,6 +248,8 @@ armor.get_player_skin = function(self, name)
skin = skins.skins[name]
elseif skin_mod == "u_skins" then
skin = u_skins.u_skins[name]
elseif skin_mod == "wardrobe" then
skin = string.gsub(wardrobe.playerSkins[name], '.png$','')
end
return skin or armor.default_skin
end
@ -280,10 +261,6 @@ armor.get_preview = function(self, name)
end
armor.get_armor_formspec = function(self, name)
if not name then
minetest.log("error", "3d_armor: Player name is nil [get_armor_formspec]")
return ""
end
if not armor.textures[name] then
minetest.log("error", "3d_armor: Player texture["..name.."] is nil [get_armor_formspec]")
return ""
@ -299,13 +276,8 @@ armor.get_armor_formspec = function(self, name)
end
armor.update_inventory = function(self, player)
if not player then
minetest.log("error", "3d_armor: Player reference is nil [update_inventory]")
return
end
local name = player:get_player_name()
local name = armor:get_valid_player(player, "[set_player_armor]")
if not name then
minetest.log("error", "3d_armor: Player name is nil [update_inventory]")
return
end
if inv_mod == "unified_inventory" then
@ -325,6 +297,33 @@ armor.update_inventory = function(self, player)
end
end
armor.get_valid_player = function(self, player, msg)
msg = msg or ""
if not player then
minetest.log("error", "3d_armor: Player reference is nil "..msg)
return
end
local name = player:get_player_name()
if not name then
minetest.log("error", "3d_armor: Player name is nil "..msg)
return
end
local pos = player:getpos()
local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not pos then
minetest.log("error", "3d_armor: Player position is nil "..msg)
return
elseif not player_inv then
minetest.log("error", "3d_armor: Player inventory is nil "..msg)
return
elseif not armor_inv then
minetest.log("error", "3d_armor: Detached armor inventory is nil "..msg)
return
end
return name, player_inv, armor_inv, pos
end
-- Register Player Model
default.player_register_model("3d_armor_character.b3d", {
@ -347,7 +346,11 @@ default.player_register_model("3d_armor_character.b3d", {
-- Register Callbacks
minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
if not name then
return
end
if inv_mod == "inventory_plus" and fields.armor then
local formspec = armor:get_armor_formspec(name)
inventory_plus.set_inventory_formspec(player, formspec)
@ -446,6 +449,11 @@ minetest.register_on_joinplayer(function(player)
if skin and u_skins.get_type(skin) == u_skins.type.MODEL then
armor.textures[name].skin = skin..".png"
end
elseif skin_mod == "wardrobe" then
local skin = wardrobe.playerSkins[name]
if skin then
armor.textures[name].skin = skin
end
end
if minetest.get_modpath("player_textures") then
local filename = minetest.get_modpath("player_textures").."/textures/player_"..name
@ -466,67 +474,67 @@ minetest.register_on_joinplayer(function(player)
end)
if ARMOR_DROP == true or ARMOR_DESTROY == true then
armor.drop_armor = function(pos, stack)
local obj = minetest.add_item(pos, stack)
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
minetest.register_on_dieplayer(function(player)
local name = player:get_player_name()
local pos = player:getpos()
if name and pos then
local drop = {}
local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not armor_inv then return end
-- MODIFICATION MADE FOR MFF ^
for i=1, player_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
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
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
if not name then
return
end
local drop = {}
for i=1, player_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
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
armor:set_player_armor(player)
if inv_mod == "unified_inventory" then
unified_inventory.set_inventory_formspec(player, "craft")
elseif inv_mod == "inventory_plus" then
local formspec = inventory_plus.get_formspec(player,"main")
inventory_plus.set_inventory_formspec(player, formspec)
else
armor:update_inventory(player)
end
if ARMOR_DESTROY == false then
if minetest.get_modpath("bones") then
minetest.after(ARMOR_BONES_DELAY, function()
pos = vector.round(pos)
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)
else
end
armor:set_player_armor(player)
if inv_mod == "unified_inventory" then
unified_inventory.set_inventory_formspec(player, "craft")
elseif inv_mod == "inventory_plus" then
local formspec = inventory_plus.get_formspec(player,"main")
inventory_plus.set_inventory_formspec(player, formspec)
else
armor:update_inventory(player)
end
if ARMOR_DESTROY == false then
minetest.after(ARMOR_BONES_DELAY, function()
pos = vector.round(pos)
local node = minetest.get_node(pos)
print(node)
print(node.name)
if node and node.name == "bones:bones" then
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local inv = meta:get_inventory()
for _,stack in ipairs(drop) do
local obj = minetest.add_item(pos, stack)
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})
if name == owner and inv:room_for_item("main", stack) then
inv:add_item("main", stack)
else
armor.drop_armor(pos, stack)
end
end
else
for _,stack in ipairs(drop) do
armor.drop_armor(pos, stack)
end
end
end
end)
end
end)
end

BIN
mods/3d_armor/3d_armor/models/3d_armor_character.b3d Executable file → Normal file

Binary file not shown.

BIN
mods/3d_armor/3d_armor/models/3d_armor_character.blend Executable file → Normal file

Binary file not shown.