mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-05 18:10:26 +01:00
Amulets/runes' inventory created with load and save features
- Added texture for the inventory's background to be customized later, adding copies of our textures in each slot - Added unified_inventory as a dependency for runes - Added inventory for runes and amulets and its handler
This commit is contained in:
parent
1413d905d2
commit
b93bd0e00a
|
@ -205,8 +205,91 @@ runes.functions.register_amulet = function(name, desc, maxcount, manadiff)
|
||||||
minetest.register_craftitem("runes:" .. name .. "_amulet", {
|
minetest.register_craftitem("runes:" .. name .. "_amulet", {
|
||||||
description = desc,
|
description = desc,
|
||||||
inventory_image = "runes_" .. name .. "_amulet.png",
|
inventory_image = "runes_" .. name .. "_amulet.png",
|
||||||
groups = {amulet = 1},
|
groups = {amulet = 1, rune = 1},
|
||||||
stack_max = maxcount,
|
stack_max = maxcount,
|
||||||
})
|
})
|
||||||
runes.datas.amulets[name] = manadiff
|
runes.datas.amulets[name] = manadiff
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Inventory
|
||||||
|
|
||||||
|
unified_inventory.register_button("runes", {
|
||||||
|
type = "image",
|
||||||
|
image = "runes_heal_major.png",
|
||||||
|
})
|
||||||
|
unified_inventory.register_page("runes", {
|
||||||
|
get_formspec = function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local formspec = "background[0,0.2;8,4;runes_rune_inventory.png]"..
|
||||||
|
"background[0,4.5;8,4;ui_wooden_chest_inventory.png]"..
|
||||||
|
"size[8,10]"..
|
||||||
|
"list[detached:"..name.."_runes;runes;0,0.2;8,4;]"
|
||||||
|
return {formspec=formspec}
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
runes.functions.register_detached_inventory = function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local datafile = io.open(minetest.get_worldpath().."/runes/"..name.."_rune.inv", "r")
|
||||||
|
local rune_inv_data = {}
|
||||||
|
if datafile then
|
||||||
|
local line = datafile:read()
|
||||||
|
if line then
|
||||||
|
rune_inv_data = minetest.deserialize(line)
|
||||||
|
end
|
||||||
|
io.close(datafile)
|
||||||
|
end
|
||||||
|
local rune_inv = minetest.create_detached_inventory(name.."_runes",{
|
||||||
|
on_put = function(inv, listname, index, stack, player)
|
||||||
|
player:get_inventory():set_stack(listname, index, stack)
|
||||||
|
armor:set_player_armor(player)
|
||||||
|
armor:update_inventory(player)
|
||||||
|
end,
|
||||||
|
on_take = function(inv, listname, index, stack, player)
|
||||||
|
player:get_inventory():set_stack(listname, index, nil)
|
||||||
|
armor:set_player_armor(player)
|
||||||
|
armor:update_inventory(player)
|
||||||
|
end,
|
||||||
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
|
if minetest.get_item_group(stack:get_name(), "rune") > 0 then
|
||||||
|
return stack:get_count()
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
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)
|
||||||
|
return count
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
rune_inv:set_size("runes", 8*4)
|
||||||
|
rune_inv:set_list("runes",rune_inv_data)
|
||||||
|
minetest.log("action","[runes] Rune inventory loaded for player " .. name)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(runes.functions.register_detached_inventory)
|
||||||
|
|
||||||
|
runes.functions.save_detached_inventory = function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local player_inv = player:get_inventory()
|
||||||
|
local datafile = io.open(minetest.get_worldpath().."/runes/"..name.."_rune.inv", "w")
|
||||||
|
local rune_inv_data = minetest.get_inventory({type = "detached", name=name.."_runes"})
|
||||||
|
local translated_rune_data = {}
|
||||||
|
for index, data in pairs(rune_inv_data:get_list("runes")) do
|
||||||
|
translated_rune_data[index] = data:get_name() .. " " .. data:get_count()
|
||||||
|
end
|
||||||
|
if datafile then
|
||||||
|
datafile:write(minetest.serialize(translated_rune_data))
|
||||||
|
end
|
||||||
|
io.close(datafile)
|
||||||
|
minetest.log("action", "[runes] Rune inventory saved for player " .. name)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(runes.functions.save_detached_inventory)
|
||||||
|
minetest.register_on_shutdown(function()
|
||||||
|
for index, player in pairs(minetest.get_connected_players()) do
|
||||||
|
runes.functions.save_detached_inventory(player)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
default
|
default
|
||||||
|
unified_inventory
|
||||||
mana
|
mana
|
||||||
|
|
BIN
mods/runes/textures/runes_rune_inventory.png
Executable file
BIN
mods/runes/textures/runes_rune_inventory.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
Loading…
Reference in New Issue
Block a user