Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function has_locked_chest_privilege(meta, player)
- if player:get_player_name() ~= meta:get_string("owner") then
- return false
- end
- return true
- end
- function default.get_locked_chest_formspec(pos)
- local spos = pos.x .. "," .. pos.y .. "," ..pos.z
- local formspec =
- "size[11.4,9]"..
- "list[nodemeta:".. spos .. ";main;0,0;8,4;]"..
- "list[current_player;main;0,5;8,4;]"..
- "field[8.5,1.5;3,1;name1;Shared with #1;]"..
- "field[8.5,3.5;3,1;name2;Shared with #2;]"..
- "field[8.5,5.5;3,1;name3;Shared with #3;]"..
- "field[8.5,7.5;3,1;name4;Shared with #4;]"
- return formspec
- end
- minetest.register_node("shared_with:chest_locked", {
- description = "Shared Chest",
- tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
- "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"},
- paramtype2 = "facedir",
- groups = {choppy=2,oddly_breakable_by_hand=2},
- legacy_facedir_simple = true,
- is_ground_content = false,
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos)
- meta:set_string("owner", placer:get_player_name() or "")
- meta:set_string("infotext", "Shared Chest (owned by "..
- meta:get_string("owner")..")")
- end,
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- meta:set_string("infotext", "Shared Chest")
- meta:set_string("owner", "")
- meta:set_string("name1","")
- meta:set_string("name2","")
- meta:set_string("name3","")
- meta:set_string("name4","")
- meta:set_string("coords",minetest.pos_to_string(pos))
- print ("SET POS:",pos, "....", minetest.pos_to_string(pos))
- local inv = meta:get_inventory()
- inv:set_size("main", 8*4)
- end,
- can_dig = function(pos,player)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory()
- return inv:is_empty("main") and has_locked_chest_privilege(meta, player)
- end,
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- local meta = minetest.get_meta(pos)
- if not has_locked_chest_privilege(meta, player) then
- minetest.log("action", player:get_player_name()..
- " tried to access a locked chest belonging to "..
- meta:get_string("owner").." at "..
- minetest.pos_to_string(pos))
- return 0
- end
- return count
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos)
- if not has_locked_chest_privilege(meta, player) then
- minetest.log("action", player:get_player_name()..
- " tried to access a locked chest belonging to "..
- meta:get_string("owner").." at "..
- minetest.pos_to_string(pos))
- return 0
- end
- return stack:get_count()
- end,
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos)
- if not has_locked_chest_privilege(meta, player) then
- minetest.log("action", player:get_player_name()..
- " tried to access a locked chest belonging to "..
- meta:get_string("owner").." at "..
- minetest.pos_to_string(pos))
- return 0
- end
- return stack:get_count()
- end,
- on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- minetest.log("action", player:get_player_name()..
- " moves stuff in locked chest at "..minetest.pos_to_string(pos))
- end,
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- minetest.log("action", player:get_player_name()..
- " moves stuff to locked chest at "..minetest.pos_to_string(pos))
- end,
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- minetest.log("action", player:get_player_name()..
- " takes stuff from locked chest at "..minetest.pos_to_string(pos))
- end,
- on_rightclick = function(pos, node, clicker)
- local meta = minetest.get_meta(pos)
- if has_locked_chest_privilege(meta, clicker) then
- minetest.show_formspec(
- clicker:get_player_name(),
- "shared_with:chest_locked",
- default.get_locked_chest_formspec(pos)
- )
- end
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- print ("YESS")
- end,
- })
- minetest.register_on_player_receive_fields(function(player, formname, fields)
- if string.sub(formname,0,string.len("shared_with:")) ~= "shared_with:" then
- print ("NOT SHARED WITH")
- return
- end
- -- if fields.name1 then
- -- meta:set_string("name1", meta:get_string("name1"))
- -- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement