mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-25 02:00:37 +01:00
Static graveyard inventory
- Added graveyard inventory for reserved_items. Next thing to add : mechanism to get them out when shifting class
This commit is contained in:
parent
640f02cdd2
commit
55bd0ea800
0
mods/mff/mff_pclasses/init.lua
Normal file → Executable file
0
mods/mff/mff_pclasses/init.lua
Normal file → Executable file
@ -83,6 +83,8 @@ function pclasses.api.reserve_item(cname, itemstring)
|
|||||||
pclasses.data.reserved_items[itemstring] = pclasses.data.reserved_items[itemstring] or {}
|
pclasses.data.reserved_items[itemstring] = pclasses.data.reserved_items[itemstring] or {}
|
||||||
table.insert(pclasses.data.reserved_items[itemstring], cname)
|
table.insert(pclasses.data.reserved_items[itemstring], cname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
-- Determination and reserved items tick --
|
-- Determination and reserved items tick --
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
@ -102,16 +104,14 @@ local function tick()
|
|||||||
end
|
end
|
||||||
if drop_stack then
|
if drop_stack then
|
||||||
inv:set_stack("main", i, "")
|
inv:set_stack("main", i, "")
|
||||||
local pos = ref:getpos()
|
local grave_inv = minetest.get_inventory({type = "detached", name = name .. "_graveyard"})
|
||||||
pos.y = pos.y+2
|
if grave_inv:room_for_item("graveyard", stack) then
|
||||||
pos.x = pos.x + math.random(-6,6)
|
grave_inv:add_item("graveyard", stack)
|
||||||
pos.z = pos.z + math.random(-6,6)
|
inv:add_item("graveyard", stack)
|
||||||
minetest.after(1, function()
|
-- ^ Because add_item doesn't trigger on_put, nonsense
|
||||||
local item = minetest.add_item(pos, stack)
|
else
|
||||||
if item then
|
minetest.add_item(pos, stack)
|
||||||
item:setvelocity({x = math.random(-5,5), y = math.random(1,7), z = math.random(-5,5)})
|
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ pclasses.conf = {}
|
|||||||
pclasses.conf.default_class = "adventurer"
|
pclasses.conf.default_class = "adventurer"
|
||||||
pclasses.conf.save_interval = 3 * 60
|
pclasses.conf.save_interval = 3 * 60
|
||||||
pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
|
pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
|
||||||
|
pclasses.conf.gravefile = minetest.get_worldpath() .. "/graveyards"
|
||||||
-- Classes
|
-- Classes
|
||||||
pclasses.classes = {}
|
pclasses.classes = {}
|
||||||
|
|
||||||
@ -28,17 +28,20 @@ pclasses.data.reserved_items = {}
|
|||||||
pclasses.data.hud_ids = {} -- HUD maybe?
|
pclasses.data.hud_ids = {} -- HUD maybe?
|
||||||
|
|
||||||
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
|
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
|
||||||
|
dofile(minetest.get_modpath("pclasses") .. "/inventory.lua")
|
||||||
dofile(minetest.get_modpath("pclasses") .. "/nodes.lua")
|
dofile(minetest.get_modpath("pclasses") .. "/nodes.lua")
|
||||||
|
|
||||||
function pclasses.data.load()
|
function pclasses.data.load()
|
||||||
local file = io.open(minetest.get_worldpath().."/quests", "r")
|
local file = io.open(pclasses.conf.datafile, "r")
|
||||||
if file then
|
if file then
|
||||||
local loaded = minetest.deserialize(file:read("*all"))
|
local loaded = minetest.deserialize(file:read("*all"))
|
||||||
file:close()
|
file:close()
|
||||||
|
if loaded then
|
||||||
pclasses.data.players = loaded.players or pclasses.data.players
|
pclasses.data.players = loaded.players or pclasses.data.players
|
||||||
minetest.log("action", "[PClasses] Loaded data")
|
minetest.log("action", "[PClasses] Loaded data")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function pclasses.data.save()
|
function pclasses.data.save()
|
||||||
local file, err = io.open(pclasses.conf.datafile, "w")
|
local file, err = io.open(pclasses.conf.datafile, "w")
|
||||||
@ -54,8 +57,8 @@ function pclasses.data.save()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function data_save_loop()
|
local function data_save_loop()
|
||||||
minetest.after(save_interval, data_save_loop)
|
|
||||||
pclasses.data.save()
|
pclasses.data.save()
|
||||||
|
minetest.after(pclasses.conf.save_interval, data_save_loop)
|
||||||
end
|
end
|
||||||
|
|
||||||
pclasses.data.load()
|
pclasses.data.load()
|
||||||
@ -66,12 +69,18 @@ pclasses.data.load()
|
|||||||
|
|
||||||
if pclasses.conf.default_class then
|
if pclasses.conf.default_class then
|
||||||
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
|
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
|
||||||
if pclasses.api.get_class_by_name(pclasses.conf.default_class) then
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if pclasses.api.get_player_class(pname) == nil then
|
if pclasses.api.get_class_by_name(pclasses.conf.default_class) and pclasses.api.get_player_class(pname) == nil then
|
||||||
pclasses.api.set_player_class(pname, pclasses.conf.default_class)
|
pclasses.api.set_player_class(pname, pclasses.conf.default_class)
|
||||||
end
|
end
|
||||||
|
pclasses.api.create_graveyard_inventory(player)
|
||||||
end)
|
end)
|
||||||
end
|
|
||||||
end
|
minetest.register_on_shutdown(function()
|
||||||
|
pclasses.data.save()
|
||||||
|
end)
|
||||||
|
|
||||||
|
data_save_loop()
|
||||||
|
50
mods/pclasses/inventory.lua
Executable file
50
mods/pclasses/inventory.lua
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
------------------------
|
||||||
|
-- PClasses' inventory
|
||||||
|
--
|
||||||
|
|
||||||
|
-- Inventory for 'dead' items
|
||||||
|
pclasses.api.create_graveyard_inventory = function(player)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
local player_inv = minetest.get_inventory({type = "player", name = pname})
|
||||||
|
local grave_inv = minetest.create_detached_inventory(pname .. "_graveyard", {
|
||||||
|
on_take = function(inv, listname, index, stack, player)
|
||||||
|
player_inv:set_stack(listname, index, nil)
|
||||||
|
end,
|
||||||
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
local stack = inv:get_stack(to_list, to_index)
|
||||||
|
player_inv:set_stack(to_list, to_index, stack)
|
||||||
|
player_inv:set_stack(from_list, from_index, nil)
|
||||||
|
end,
|
||||||
|
allow_take = function(inv, listname, index, stack, player)
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
grave_inv:set_size("graveyard", 7*8)
|
||||||
|
player_inv:set_size("graveyard", 7*8)
|
||||||
|
for i = 1,56 do
|
||||||
|
local stack = player_inv:get_stack("graveyard", i)
|
||||||
|
grave_inv:set_stack("graveyard", i, stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
unified_inventory.register_button("graveyard", {
|
||||||
|
type = "image",
|
||||||
|
image = "pclasses_grave_button.png",
|
||||||
|
tooltip = "Item Graveyard",
|
||||||
|
})
|
||||||
|
|
||||||
|
unified_inventory.register_page("graveyard", {
|
||||||
|
get_formspec = function(player)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
local form = "label[0,0;Graveyard]" ..
|
||||||
|
"list[detached:" .. pname .. "_graveyard;graveyard;1,1;7,8]"
|
||||||
|
return {formspec = form, draw_inventory = false}
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
0
mods/pclasses/nodes.lua
Normal file → Executable file
0
mods/pclasses/nodes.lua
Normal file → Executable file
0
mods/pclasses/textures/pclasses_class_switch_orb_overlay.png
Normal file → Executable file
0
mods/pclasses/textures/pclasses_class_switch_orb_overlay.png
Normal file → Executable file
Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 292 B |
0
other_things/logos/logo_github_500.png
Normal file → Executable file
0
other_things/logos/logo_github_500.png
Normal file → Executable file
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Loading…
Reference in New Issue
Block a user