copy detached stacks
This commit is contained in:
parent
6864c647ac
commit
080b30dc7f
@ -1,4 +1,31 @@
|
|||||||
|
|
||||||
|
local get_inv_name = function(player)
|
||||||
|
return "mission_chestput_" .. player:get_player_name()
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_inv = function(player)
|
||||||
|
return minetest.get_inventory({type="detached",name=get_inv_name(player)})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- setup detached inv
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
local inv = minetest.create_detached_inventory(get_inv_name(player), {
|
||||||
|
on_put = function(inv, listname, index, stack, player)
|
||||||
|
-- copy stack
|
||||||
|
local playerInv = player:get_inventory()
|
||||||
|
playerInv:add_item("main", stack)
|
||||||
|
end,
|
||||||
|
allow_take = function(inv, listname, index, stack, player)
|
||||||
|
-- remove from det inv
|
||||||
|
inv:remove_item("main", stack)
|
||||||
|
-- give player nothing
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
})
|
||||||
|
inv:set_size("main", 1)
|
||||||
|
end)
|
||||||
|
|
||||||
missions.register_step({
|
missions.register_step({
|
||||||
|
|
||||||
@ -9,10 +36,19 @@ missions.register_step({
|
|||||||
return {count=1, name="default:cobble"}
|
return {count=1, name="default:cobble"}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
validate = function(pos, node, player, step, stepdata)
|
||||||
|
-- TODO
|
||||||
|
end,
|
||||||
|
|
||||||
edit_formspec = function(pos, node, player, stepnumber, step, stepdata)
|
edit_formspec = function(pos, node, player, stepnumber, step, stepdata)
|
||||||
|
--TODO: populate inv
|
||||||
|
|
||||||
local formspec = "size[8,8;]" ..
|
local formspec = "size[8,8;]" ..
|
||||||
"label[0,0;Put items in chest]" ..
|
"label[0,0;Put items in chest]" ..
|
||||||
|
"list[detached:" .. get_inv_name(player) .. ";main;0,1;1,1;]" ..
|
||||||
|
--"button_exit[1,1;4,1;read;Read items]" ..
|
||||||
|
|
||||||
|
"list[current_player;main;0,6;8,1;]" ..
|
||||||
"button_exit[0,7;8,1;save;Save]"
|
"button_exit[0,7;8,1;save;Save]"
|
||||||
|
|
||||||
return formspec;
|
return formspec;
|
||||||
@ -21,6 +57,9 @@ missions.register_step({
|
|||||||
update = function(fields, player, step, stepdata, show_editor, show_mission)
|
update = function(fields, player, step, stepdata, show_editor, show_mission)
|
||||||
--TODO
|
--TODO
|
||||||
|
|
||||||
|
if fields.read then
|
||||||
|
end
|
||||||
|
|
||||||
if fields.save then
|
if fields.save then
|
||||||
show_mission()
|
show_mission()
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ local counter = {} -- playername -> count
|
|||||||
missions.register_step({
|
missions.register_step({
|
||||||
|
|
||||||
type = "simpledig",
|
type = "simpledig",
|
||||||
name = "Dig nodes",
|
name = "Dig any nodes",
|
||||||
|
|
||||||
create = function()
|
create = function()
|
||||||
return {count=100}
|
return {count=100}
|
||||||
|
@ -18,6 +18,17 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
on_put = function(inv, listname, index, stack, player)
|
||||||
|
-- copy stack
|
||||||
|
local playerInv = player:get_inventory()
|
||||||
|
playerInv:add_item("main", stack)
|
||||||
|
end,
|
||||||
|
allow_take = function(inv, listname, index, stack, player)
|
||||||
|
-- remove from det inv
|
||||||
|
inv:remove_item("main", stack)
|
||||||
|
-- give player nothing
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -64,7 +75,6 @@ missions.register_step({
|
|||||||
"label[0,0;Walk to (Step #" .. stepnumber .. ")]" ..
|
"label[0,0;Walk to (Step #" .. stepnumber .. ")]" ..
|
||||||
|
|
||||||
"list[detached:" .. get_inv_name(player) .. ";main;0,1;1,1;]" ..
|
"list[detached:" .. get_inv_name(player) .. ";main;0,1;1,1;]" ..
|
||||||
"button_exit[1,1;4,1;read;Read position]" ..
|
|
||||||
|
|
||||||
--TODO: escape
|
--TODO: escape
|
||||||
"label[0,2;" .. name .. "]" ..
|
"label[0,2;" .. name .. "]" ..
|
||||||
@ -103,7 +113,7 @@ missions.register_step({
|
|||||||
stepdata.description = fields.description
|
stepdata.description = fields.description
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.read then
|
if fields.save then
|
||||||
local inv = get_inv(player)
|
local inv = get_inv(player)
|
||||||
local stack = inv:get_stack("main", 1)
|
local stack = inv:get_stack("main", 1)
|
||||||
|
|
||||||
@ -114,19 +124,8 @@ missions.register_step({
|
|||||||
|
|
||||||
stepdata.pos = pos
|
stepdata.pos = pos
|
||||||
stepdata.name = name
|
stepdata.name = name
|
||||||
|
|
||||||
|
|
||||||
--move item back to user
|
|
||||||
inv:remove_item("main", stack)
|
|
||||||
|
|
||||||
local playerInv = player:get_inventory()
|
|
||||||
playerInv:add_item("main", stack)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
show_editor()
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields.save then
|
|
||||||
show_mission()
|
show_mission()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user