Add files via upload
parent
b573a34a0f
commit
8ac5690c3c
|
@ -0,0 +1 @@
|
||||||
|
It adds a public inventory.
|
|
@ -0,0 +1,62 @@
|
||||||
|
local pi_file = minetest.get_worldpath() .. "/pi"
|
||||||
|
|
||||||
|
local pi = minetest.create_detached_inventory("pi", {
|
||||||
|
on_put = function(inv, listname, index, stack, player)
|
||||||
|
local list = inv:get_list("main")
|
||||||
|
if list then
|
||||||
|
local output = io.open(pi_file, "w")
|
||||||
|
local str = ""
|
||||||
|
table.foreach(list,function(index)
|
||||||
|
str = str..list[index]:to_string()..","
|
||||||
|
end
|
||||||
|
)
|
||||||
|
str = str:sub(1, #str - 1)
|
||||||
|
output:write(str)
|
||||||
|
io.close(output)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_take = function(inv, listname, index, stack, player)
|
||||||
|
local list = inv:get_list("main")
|
||||||
|
if list then
|
||||||
|
local output = io.open(pi_file, "w")
|
||||||
|
local str = ""
|
||||||
|
table.foreach(list,function(index)
|
||||||
|
str = str..list[index]:to_string()..","
|
||||||
|
end
|
||||||
|
)
|
||||||
|
str = str:sub(1, #str - 1)
|
||||||
|
output:write(str)
|
||||||
|
io.close(output)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
pi:set_size("main", 128)
|
||||||
|
|
||||||
|
local function load_pi()
|
||||||
|
local input = io.open(pi_file, "r")
|
||||||
|
if input then
|
||||||
|
local str = input:read()
|
||||||
|
if str then
|
||||||
|
for item in str.gmatch(str, '([^,]+)') do
|
||||||
|
pi:add_item("main", item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
io.close(input)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
load_pi()
|
||||||
|
|
||||||
|
minetest.register_chatcommand("pi", {
|
||||||
|
params = "",
|
||||||
|
description = "shows the public inventory",
|
||||||
|
func = function(name, param)
|
||||||
|
minetest.show_formspec(name, "public_inventory:pi",
|
||||||
|
"size[16,11;]"..
|
||||||
|
"list[detached:pi;main;0,0;16,8;]"..
|
||||||
|
"list[current_player;main;0,9;16,2;]")
|
||||||
|
return true, ""
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
author = cd2
|
||||||
|
name = public_inventory
|
||||||
|
description = Adds a public inventory.
|
||||||
|
title = Public Inventory
|
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
Loading…
Reference in New Issue