daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest May 22nd, 2014 151 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function has_locked_chest_privilege(meta, player)
  2.         if player:get_player_name() ~= meta:get_string("owner") then
  3.                 return false
  4.         end
  5.         return true
  6. end
  7.  
  8. function default.get_locked_chest_formspec(pos)
  9.         local spos = pos.x .. "," .. pos.y .. "," ..pos.z
  10.         local formspec =
  11.                 "size[11.4,9]"..
  12.                 "list[nodemeta:".. spos .. ";main;0,0;8,4;]"..
  13.                 "list[current_player;main;0,5;8,4;]"..
  14.  
  15.                 "field[8.5,1.5;3,1;name1;Shared with #1;]"..
  16.                 "field[8.5,3.5;3,1;name2;Shared with #2;]"..
  17.                 "field[8.5,5.5;3,1;name3;Shared with #3;]"..
  18.                 "field[8.5,7.5;3,1;name4;Shared with #4;]"
  19.  
  20.         return formspec
  21. end
  22.  
  23. minetest.register_node("shared_with:chest_locked", {
  24.  
  25.         description = "Shared Chest",
  26.         tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
  27.                 "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"},
  28.         paramtype2 = "facedir",
  29.         groups = {choppy=2,oddly_breakable_by_hand=2},
  30.         legacy_facedir_simple = true,
  31.         is_ground_content = false,
  32.         sounds = default.node_sound_wood_defaults(),
  33.  
  34.         after_place_node = function(pos, placer)
  35.                 local meta = minetest.get_meta(pos)
  36.                 meta:set_string("owner", placer:get_player_name() or "")
  37.                 meta:set_string("infotext", "Shared Chest (owned by "..
  38.                                 meta:get_string("owner")..")")
  39.         end,
  40.  
  41.         on_construct = function(pos)
  42.                 local meta = minetest.get_meta(pos)
  43.                 meta:set_string("infotext", "Shared Chest")
  44.                 meta:set_string("owner", "")
  45.                 meta:set_string("name1","")
  46.                 meta:set_string("name2","")
  47.                 meta:set_string("name3","")
  48.                 meta:set_string("name4","")
  49.                 meta:set_string("coords",minetest.pos_to_string(pos))
  50. print ("SET POS:",pos, "....", minetest.pos_to_string(pos))
  51.                 local inv = meta:get_inventory()
  52.                 inv:set_size("main", 8*4)
  53.         end,
  54.  
  55.         can_dig = function(pos,player)
  56.                 local meta = minetest.get_meta(pos);
  57.                 local inv = meta:get_inventory()
  58.                 return inv:is_empty("main") and has_locked_chest_privilege(meta, player)
  59.         end,
  60.  
  61.         allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  62.                 local meta = minetest.get_meta(pos)
  63.                 if not has_locked_chest_privilege(meta, player) then
  64.                         minetest.log("action", player:get_player_name()..
  65.                                         " tried to access a locked chest belonging to "..
  66.                                         meta:get_string("owner").." at "..
  67.                                         minetest.pos_to_string(pos))
  68.                         return 0
  69.                 end
  70.                 return count
  71.         end,
  72.  
  73.         allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  74.                 local meta = minetest.get_meta(pos)
  75.                 if not has_locked_chest_privilege(meta, player) then
  76.                         minetest.log("action", player:get_player_name()..
  77.                                         " tried to access a locked chest belonging to "..
  78.                                         meta:get_string("owner").." at "..
  79.                                         minetest.pos_to_string(pos))
  80.                         return 0
  81.                 end
  82.                 return stack:get_count()
  83.         end,
  84.  
  85.         allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  86.                 local meta = minetest.get_meta(pos)
  87.                 if not has_locked_chest_privilege(meta, player) then
  88.                         minetest.log("action", player:get_player_name()..
  89.                                         " tried to access a locked chest belonging to "..
  90.                                         meta:get_string("owner").." at "..
  91.                                         minetest.pos_to_string(pos))
  92.                         return 0
  93.                 end
  94.                 return stack:get_count()
  95.         end,
  96.  
  97.         on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  98.                 minetest.log("action", player:get_player_name()..
  99.                                 " moves stuff in locked chest at "..minetest.pos_to_string(pos))
  100.         end,
  101.  
  102.         on_metadata_inventory_put = function(pos, listname, index, stack, player)
  103.                 minetest.log("action", player:get_player_name()..
  104.                                 " moves stuff to locked chest at "..minetest.pos_to_string(pos))
  105.         end,
  106.  
  107.         on_metadata_inventory_take = function(pos, listname, index, stack, player)
  108.                 minetest.log("action", player:get_player_name()..
  109.                                 " takes stuff from locked chest at "..minetest.pos_to_string(pos))
  110.         end,
  111.  
  112.         on_rightclick = function(pos, node, clicker)
  113.                 local meta = minetest.get_meta(pos)
  114.                 if has_locked_chest_privilege(meta, clicker) then
  115.                         minetest.show_formspec(
  116.                                 clicker:get_player_name(),
  117.                                 "shared_with:chest_locked",
  118.                                 default.get_locked_chest_formspec(pos)
  119.                         )
  120.                 end
  121.         end,
  122.  
  123.         on_receive_fields = function(pos, formname, fields, sender)
  124.                 print ("YESS")
  125.         end,
  126.  
  127. })
  128.  
  129. minetest.register_on_player_receive_fields(function(player, formname, fields)
  130.  
  131.         if string.sub(formname,0,string.len("shared_with:")) ~= "shared_with:" then
  132.                 print ("NOT SHARED WITH")
  133.                 return
  134.         end
  135.  
  136.  
  137. --              if fields.name1 then
  138. --                      meta:set_string("name1", meta:get_string("name1"))
  139. --              end
  140.  
  141. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top