mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50: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 {}
|
||||
table.insert(pclasses.data.reserved_items[itemstring], cname)
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------
|
||||
-- Determination and reserved items tick --
|
||||
-------------------------------------------
|
||||
@ -102,16 +104,14 @@ local function tick()
|
||||
end
|
||||
if drop_stack then
|
||||
inv:set_stack("main", i, "")
|
||||
local pos = ref:getpos()
|
||||
pos.y = pos.y+2
|
||||
pos.x = pos.x + math.random(-6,6)
|
||||
pos.z = pos.z + math.random(-6,6)
|
||||
minetest.after(1, function()
|
||||
local item = minetest.add_item(pos, stack)
|
||||
if item then
|
||||
item:setvelocity({x = math.random(-5,5), y = math.random(1,7), z = math.random(-5,5)})
|
||||
end
|
||||
end)
|
||||
local grave_inv = minetest.get_inventory({type = "detached", name = name .. "_graveyard"})
|
||||
if grave_inv:room_for_item("graveyard", stack) then
|
||||
grave_inv:add_item("graveyard", stack)
|
||||
inv:add_item("graveyard", stack)
|
||||
-- ^ Because add_item doesn't trigger on_put, nonsense
|
||||
else
|
||||
minetest.add_item(pos, stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ pclasses.conf = {}
|
||||
pclasses.conf.default_class = "adventurer"
|
||||
pclasses.conf.save_interval = 3 * 60
|
||||
pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
|
||||
|
||||
pclasses.conf.gravefile = minetest.get_worldpath() .. "/graveyards"
|
||||
-- Classes
|
||||
pclasses.classes = {}
|
||||
|
||||
@ -28,15 +28,18 @@ pclasses.data.reserved_items = {}
|
||||
pclasses.data.hud_ids = {} -- HUD maybe?
|
||||
|
||||
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
|
||||
dofile(minetest.get_modpath("pclasses") .. "/inventory.lua")
|
||||
dofile(minetest.get_modpath("pclasses") .. "/nodes.lua")
|
||||
|
||||
function pclasses.data.load()
|
||||
local file = io.open(minetest.get_worldpath().."/quests", "r")
|
||||
local file = io.open(pclasses.conf.datafile, "r")
|
||||
if file then
|
||||
local loaded = minetest.deserialize(file:read("*all"))
|
||||
file:close()
|
||||
pclasses.data.players = loaded.players or pclasses.data.players
|
||||
minetest.log("action", "[PClasses] Loaded data")
|
||||
if loaded then
|
||||
pclasses.data.players = loaded.players or pclasses.data.players
|
||||
minetest.log("action", "[PClasses] Loaded data")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -54,8 +57,8 @@ function pclasses.data.save()
|
||||
end
|
||||
|
||||
local function data_save_loop()
|
||||
minetest.after(save_interval, data_save_loop)
|
||||
pclasses.data.save()
|
||||
minetest.after(pclasses.conf.save_interval, data_save_loop)
|
||||
end
|
||||
|
||||
pclasses.data.load()
|
||||
@ -66,12 +69,18 @@ pclasses.data.load()
|
||||
|
||||
if pclasses.conf.default_class then
|
||||
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
|
||||
if pclasses.api.get_class_by_name(pclasses.conf.default_class) then
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
if pclasses.api.get_player_class(pname) == nil then
|
||||
pclasses.api.set_player_class(pname, pclasses.conf.default_class)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
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)
|
||||
end
|
||||
pclasses.api.create_graveyard_inventory(player)
|
||||
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