summaryrefslogtreecommitdiff
path: root/currency
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-04-01 20:02:19 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-04-01 21:09:33 -0400
commitda66780a569712c23ae4f2996cfb4608a9f9d69d (patch)
tree217556029a78bc23ad4564720afc86de97228a04 /currency
parent615b22df4d423aded3613db7716943a2f389b047 (diff)
downloaddreambuilder_modpack-da66780a569712c23ae4f2996cfb4608a9f9d69d.tar
dreambuilder_modpack-da66780a569712c23ae4f2996cfb4608a9f9d69d.tar.gz
dreambuilder_modpack-da66780a569712c23ae4f2996cfb4608a9f9d69d.tar.bz2
dreambuilder_modpack-da66780a569712c23ae4f2996cfb4608a9f9d69d.tar.xz
dreambuilder_modpack-da66780a569712c23ae4f2996cfb4608a9f9d69d.zip
copy all standard Dreambuilder mods in from the old subgame
(exactly as last supplied there, updates to these mods will follow later)
Diffstat (limited to 'currency')
-rw-r--r--currency/Money_Info.txt33
-rw-r--r--currency/README.md4
-rw-r--r--currency/barter.lua165
-rw-r--r--currency/crafting.lua71
-rw-r--r--currency/craftitems.lua26
-rw-r--r--currency/depends.txt1
-rw-r--r--currency/income.lua40
-rw-r--r--currency/init.lua20
-rw-r--r--currency/safe.lua103
-rw-r--r--currency/shop.lua195
-rw-r--r--currency/textures/barter_base.pngbin0 -> 734 bytes
-rw-r--r--currency/textures/barter_side.pngbin0 -> 1400 bytes
-rw-r--r--currency/textures/barter_top.pngbin0 -> 896 bytes
-rw-r--r--currency/textures/minegeld.pngbin0 -> 3563 bytes
-rw-r--r--currency/textures/minegeld_10.pngbin0 -> 3509 bytes
-rw-r--r--currency/textures/minegeld_5.pngbin0 -> 3365 bytes
-rw-r--r--currency/textures/minegeld_bundle.pngbin0 -> 5092 bytes
-rw-r--r--currency/textures/safe_front.pngbin0 -> 309 bytes
-rw-r--r--currency/textures/safe_side.pngbin0 -> 150 bytes
-rw-r--r--currency/textures/shop_front.pngbin0 -> 822 bytes
-rw-r--r--currency/textures/shop_side.pngbin0 -> 755 bytes
-rw-r--r--currency/textures/shop_top.pngbin0 -> 734 bytes
22 files changed, 658 insertions, 0 deletions
diff --git a/currency/Money_Info.txt b/currency/Money_Info.txt
new file mode 100644
index 0000000..722d2b9
--- /dev/null
+++ b/currency/Money_Info.txt
@@ -0,0 +1,33 @@
+Mine-Geld
+---------
+
+They have no recipe.
+A good starting amount is about 250Mg on a server
+
+You currently get a basic income of 1 Minegeld per day,
+so long as you dig at least one node in that day
+and have an empty inventory slot for the money to go in.
+
+Lump Conversion
+
+Coal Lump ~1Mg
+Iron Lump ~4Mg
+Copper Lump ~4Mg
+Gold Lump ~5Mg
+Mese Crystal ~40Mg
+Diamond ~50Mg
+
+Ingot Conversion
+
+Steel Ingot ~5Mg
+Copper Ingot ~5Mg
+Gold Ingot ~6Mg
+
+Block Conversion
+
+Coal Block ~9Mg
+Steel Block ~45Mg
+Copper Block ~45Mg
+Gold Block ~54Mg
+Mese Block ~360Mg
+Diamond Block ~450Mg
diff --git a/currency/README.md b/currency/README.md
new file mode 100644
index 0000000..f4471a7
--- /dev/null
+++ b/currency/README.md
@@ -0,0 +1,4 @@
+currency
+========
+
+Repo for Currency Mod
diff --git a/currency/barter.lua b/currency/barter.lua
new file mode 100644
index 0000000..dad2e4a
--- /dev/null
+++ b/currency/barter.lua
@@ -0,0 +1,165 @@
+barter = {}
+
+barter.chest = {}
+barter.chest.formspec = {
+ main = "size[8,9]"..
+ "list[current_name;pl1;0,0;3,4;]"..
+ "list[current_name;pl2;5,0;3,4;]"..
+ "list[current_player;main;0,5;8,4;]",
+ pl1 = {
+ start = "button[3,1;1,1;pl1_start;Start]",
+ player = function(name) return "label[3,0;"..name.."]" end,
+ accept1 = "button[3,1;1,1;pl1_accept1;Confirm]"..
+ "button[3,2;1,1;pl1_cancel;Cancel]",
+ accept2 = "button[3,1;1,1;pl1_accept2;Exchange]"..
+ "button[3,2;1,1;pl1_cancel;Cancel]",
+ },
+ pl2 = {
+ start = "button[4,1;1,1;pl2_start;Start]",
+ player = function(name) return "label[4,0;"..name.."]" end,
+ accept1 = "button[4,1;1,1;pl2_accept1;Confirm]"..
+ "button[4,2;1,1;pl2_cancel;Cancel]",
+ accept2 = "button[4,1;1,1;pl2_accept2;Exchange]"..
+ "button[4,2;1,1;pl2_cancel;Cancel]",
+ },
+}
+
+barter.chest.check_privilege = function(listname,playername,meta)
+ if listname == "pl1" then
+ if playername ~= meta:get_string("pl1") then
+ return false
+ elseif meta:get_int("pl1step") ~= 1 then
+ return false
+ end
+ end
+ if listname == "pl2" then
+ if playername ~= meta:get_string("pl2") then
+ return false
+ elseif meta:get_int("pl2step") ~= 1 then
+ return false
+ end
+ end
+ return true
+end
+
+barter.chest.update_formspec = function(meta)
+ formspec = barter.chest.formspec.main
+ pl_formspec = function (n)
+ if meta:get_int(n.."step")==0 then
+ formspec = formspec .. barter.chest.formspec[n].start
+ else
+ formspec = formspec .. barter.chest.formspec[n].player(meta:get_string(n))
+ if meta:get_int(n.."step") == 1 then
+ formspec = formspec .. barter.chest.formspec[n].accept1
+ elseif meta:get_int(n.."step") == 2 then
+ formspec = formspec .. barter.chest.formspec[n].accept2
+ end
+ end
+ end
+ pl_formspec("pl1") pl_formspec("pl2")
+ meta:set_string("formspec",formspec)
+end
+
+barter.chest.give_inventory = function(inv,list,playername)
+ player = minetest.get_player_by_name(playername)
+ if player then
+ for k,v in ipairs(inv:get_list(list)) do
+ player:get_inventory():add_item("main",v)
+ inv:remove_item(list,v)
+ end
+ end
+end
+
+barter.chest.cancel = function(meta)
+ barter.chest.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl1"))
+ barter.chest.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl2"))
+ meta:set_string("pl1","")
+ meta:set_string("pl2","")
+ meta:set_int("pl1step",0)
+ meta:set_int("pl2step",0)
+end
+
+barter.chest.exchange = function(meta)
+ barter.chest.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl2"))
+ barter.chest.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl1"))
+ meta:set_string("pl1","")
+ meta:set_string("pl2","")
+ meta:set_int("pl1step",0)
+ meta:set_int("pl2step",0)
+end
+
+minetest.register_node("currency:barter", {
+ drawtype = "nodebox",
+ description = "Barter Table",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ tiles = {"barter_top.png",
+ "barter_base.png",
+ "barter_side.png"},
+ inventory_image = "barter_top.png",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.500000,0.312500,-0.500000,0.500000,0.500000,0.500000},
+ {-0.437500,-0.500000,-0.437500,-0.250000,0.500000,-0.250000},
+ {-0.437500,-0.500000,0.250000,-0.250000,0.500000,0.437500},
+ {0.250000,-0.500000,-0.437500,0.437500,0.500000,-0.250000},
+ {0.250000,-0.500000,0.250000,0.437500,0.500000,0.447500},
+ },
+ },
+ groups = {choppy=2,oddly_breakable_by_hand=2},
+ sounds = default.node_sound_wood_defaults(),
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("infotext", "Barter Table")
+ meta:set_string("pl1","")
+ meta:set_string("pl2","")
+ barter.chest.update_formspec(meta)
+ local inv = meta:get_inventory()
+ inv:set_size("pl1", 3*4)
+ inv:set_size("pl2", 3*4)
+ end,
+ on_receive_fields = function(pos, formname, fields, sender)
+ local meta = minetest.get_meta(pos)
+ pl_receive_fields = function(n)
+ if fields[n.."_start"] and meta:get_string(n) == "" then
+ meta:set_string(n,sender:get_player_name())
+ end
+ if meta:get_string(n) == "" then
+ meta:set_int(n.."step",0)
+ elseif meta:get_int(n.."step")==0 then
+ meta:set_int(n.."step",1)
+ end
+ if sender:get_player_name() == meta:get_string(n) then
+ if meta:get_int(n.."step")==1 and fields[n.."_accept1"] then
+ meta:set_int(n.."step",2)
+ end
+ if meta:get_int(n.."step")==2 and fields[n.."_accept2"] then
+ meta:set_int(n.."step",3)
+ if n == "pl1" and meta:get_int("pl2step") == 3 then barter.chest.exchange(meta) end
+ if n == "pl2" and meta:get_int("pl1step") == 3 then barter.chest.exchange(meta) end
+ end
+ if fields[n.."_cancel"] then barter.chest.cancel(meta) end
+ end
+ end
+ pl_receive_fields("pl1") pl_receive_fields("pl2")
+ -- End
+ barter.chest.update_formspec(meta)
+ 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 barter.chest.check_privilege(from_list,player:get_player_name(),meta) then return 0 end
+ if not barter.chest.check_privilege(to_list,player:get_player_name(),meta) then return 0 end
+ return count
+ end,
+ allow_metadata_inventory_put = function(pos, listname, index, stack, player)
+ local meta = minetest.get_meta(pos)
+ if not barter.chest.check_privilege(listname,player:get_player_name(),meta) then 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 barter.chest.check_privilege(listname,player:get_player_name(),meta) then return 0 end
+ return stack:get_count()
+ end,
+})
diff --git a/currency/crafting.lua b/currency/crafting.lua
new file mode 100644
index 0000000..33a9553
--- /dev/null
+++ b/currency/crafting.lua
@@ -0,0 +1,71 @@
+minetest.register_craft({
+ output = 'currency:safe',
+ recipe = {
+ {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
+ {'default:steel_ingot', '', 'default:steel_ingot'},
+ {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
+ }
+})
+
+minetest.register_craft({
+ output = 'currency:shop',
+ recipe = {
+ {'default:sign_wall'},
+ {'default:chest_locked'},
+ }
+})
+
+minetest.register_craft({
+ output = 'currency:barter',
+ recipe = {
+ {'default:sign_wall'},
+ {'default:chest'},
+ }
+})
+
+minetest.register_craft({
+ type = "shapeless",
+ output = "currency:minegeld_5",
+ recipe = {"currency:minegeld", "currency:minegeld", "currency:minegeld", "currency:minegeld", "currency:minegeld"},
+})
+
+minetest.register_craft({
+ type = "shapeless",
+ output = "currency:minegeld_10",
+ recipe = {"currency:minegeld_5", "currency:minegeld_5"},
+})
+
+minetest.register_craft({
+ type = "shapeless",
+ output = "currency:minegeld_5 2",
+ recipe = {"currency:minegeld_10"},
+})
+
+minetest.register_craft({
+ type = "shapeless",
+ output = "currency:minegeld 5",
+ recipe = {"currency:minegeld_5"},
+})
+
+minetest.register_craft({
+ type = "shapeless",
+ output = "currency:minegeld_bundle",
+ recipe = {
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld",
+ "group:minegeld"
+ },
+})
+
+minetest.register_craft({
+ type = "fuel",
+ recipe = "currency:minegeld_bundle",
+ burntime = 1,
+})
+
diff --git a/currency/craftitems.lua b/currency/craftitems.lua
new file mode 100644
index 0000000..47ad953
--- /dev/null
+++ b/currency/craftitems.lua
@@ -0,0 +1,26 @@
+minetest.register_craftitem("currency:minegeld", {
+ description = "1 MineGeld Note",
+ inventory_image = "minegeld.png",
+ stack_max = 30000,
+ groups = {minegeld = 1}
+})
+
+minetest.register_craftitem("currency:minegeld_5", {
+ description = "5 MineGeld Note",
+ inventory_image = "minegeld_5.png",
+ stack_max = 30000,
+ groups = {minegeld = 1}
+})
+
+minetest.register_craftitem("currency:minegeld_10", {
+ description = "10 MineGeld Note",
+ inventory_image = "minegeld_10.png",
+ stack_max = 30000,
+ groups = {minegeld = 1}
+})
+
+minetest.register_craftitem("currency:minegeld_bundle", {
+ description = "Bundle of random Minegeld notes",
+ inventory_image = "minegeld_bundle.png",
+ stack_max = 30000,
+})
diff --git a/currency/depends.txt b/currency/depends.txt
new file mode 100644
index 0000000..331d858
--- /dev/null
+++ b/currency/depends.txt
@@ -0,0 +1 @@
+default \ No newline at end of file
diff --git a/currency/income.lua b/currency/income.lua
new file mode 100644
index 0000000..5aa6fbc
--- /dev/null
+++ b/currency/income.lua
@@ -0,0 +1,40 @@
+players_income = {}
+
+local timer = 0
+minetest.register_globalstep(function(dtime)
+ timer = timer + dtime;
+ if timer >= 720 then --720 for one day
+ timer = 0
+ for _,player in ipairs(minetest.get_connected_players()) do
+ local name = player:get_player_name()
+ if players_income[name] == nil then
+ players_income[name] = 0
+ end
+ players_income[name] = 1
+ print("[Currency] basic income for "..name.."")
+ end
+ end
+end)
+
+earn_income = function(player)
+ if not player or player.is_fake_player then return end
+ local name = player:get_player_name()
+ if players_income[name] == nil then
+ players_income[name] = 0
+ end
+ if players_income[name] > 0 then
+ count = players_income[name]
+ local inv = player:get_inventory()
+ inv:add_item("main", {name="currency:minegeld_5", count=count})
+ players_income[name] = 0
+ print("[Currency] added basic income for "..name.." to inventory")
+ end
+end
+
+minetest.register_on_dignode(function(pos, oldnode, digger)
+ earn_income(digger)
+end)
+
+minetest.register_on_placenode(function(pos, node, placer)
+ earn_income(placer)
+end)
diff --git a/currency/init.lua b/currency/init.lua
new file mode 100644
index 0000000..0c94994
--- /dev/null
+++ b/currency/init.lua
@@ -0,0 +1,20 @@
+print(" Currency mod loading... ")
+local modpath = minetest.get_modpath("currency")
+
+dofile(modpath.."/craftitems.lua")
+print("[Currency] Craft_items Loaded!")
+dofile(modpath.."/shop.lua")
+print("[Currency] Shop Loaded!")
+dofile(modpath.."/barter.lua")
+print("[Currency] Barter Loaded!")
+dofile(modpath.."/safe.lua")
+print("[Currency] Safe Loaded!")
+dofile(modpath.."/crafting.lua")
+print("[Currency] Crafting Loaded!")
+
+if minetest.setting_getbool("creative_mode") then
+ print("[Currency] Creative mode in use, skipping basic income.")
+else
+ dofile(modpath.."/income.lua")
+ print("[Currency] Income Loaded!")
+end
diff --git a/currency/safe.lua b/currency/safe.lua
new file mode 100644
index 0000000..428711f
--- /dev/null
+++ b/currency/safe.lua
@@ -0,0 +1,103 @@
+function default.get_safe_formspec(pos)
+ local spos = pos.x .. "," .. pos.y .. "," ..pos.z
+ local formspec =
+ "size[8,9]"..
+ "list[nodemeta:".. spos .. ";main;1,1;6,2;]"..
+ "list[current_player;main;0,5;8,4;]"
+ return formspec
+end
+
+local function has_safe_privilege(meta, player)
+ if not player or player:get_player_name() ~= meta:get_string("owner") then
+ return false
+ end
+ return true
+end
+
+minetest.register_node("currency:safe", {
+ description = "Safe",
+ inventory_image = "safe_front.png",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ tiles = {"safe_side.png",
+ "safe_side.png",
+ "safe_side.png",
+ "safe_side.png",
+ "safe_side.png",
+ "safe_front.png",},
+ is_ground_content = false,
+ groups = {cracky=1},
+ 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", "Safe (owned by "..
+ meta:get_string("owner")..")")
+ end,
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("infotext", "Safe")
+ meta:set_string("owner", "")
+ local inv = meta:get_inventory()
+ inv:set_size("main", 6*2)
+ end,
+ can_dig = function(pos,player)
+ local meta = minetest.get_meta(pos);
+ local inv = meta:get_inventory()
+ return inv:is_empty("main") and has_safe_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_safe_privilege(meta, player) then
+ minetest.log("action", player:get_player_name()..
+ " tried to access a safe 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_safe_privilege(meta, player) then
+ minetest.log("action", player:get_player_name()..
+ " tried to access a safe 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_safe_privilege(meta, player) then
+ minetest.log("action", player:get_player_name()..
+ " tried to access a safe 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 safe 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 safe 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 safe at "..minetest.pos_to_string(pos))
+ end,
+ on_rightclick = function(pos, node, clicker)
+ local meta = minetest.get_meta(pos)
+ if has_safe_privilege(meta, clicker) then
+ minetest.show_formspec(
+ clicker:get_player_name(),
+ "currency:safe",
+ default.get_safe_formspec(pos)
+ )
+ end
+ end,
+})
diff --git a/currency/shop.lua b/currency/shop.lua
new file mode 100644
index 0000000..08bfac7
--- /dev/null
+++ b/currency/shop.lua
@@ -0,0 +1,195 @@
+default.shop = {}
+default.shop.current_shop = {}
+default.shop.formspec = {
+ customer = function(pos)
+ local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
+ local formspec = "size[8,9.5]"..
+ "label[0,0;Customer gives (pay here !)]"..
+ "list[current_player;customer_gives;0,0.5;3,2;]"..
+ "label[0,2.5;Customer gets]"..
+ "list[current_player;customer_gets;0,3;3,2;]"..
+ "label[5,0;Owner wants]"..
+ "list["..list_name..";owner_wants;5,0.5;3,2;]"..
+ "label[5,2.5;Owner gives]"..
+ "list["..list_name..";owner_gives;5,3;3,2;]"..
+ "list[current_player;main;0,5.5;8,4;]"..
+ "button[3,2;2,1;exchange;Exchange]"
+ return formspec
+ end,
+ owner = function(pos)
+ local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
+ local formspec = "size[8,9.5]"..
+ "label[0,0;Customers gave:]"..
+ "list["..list_name..";customers_gave;0,0.5;3,2;]"..
+ "label[0,2.5;Your stock:]"..
+ "list["..list_name..";stock;0,3;3,2;]"..
+ "label[5,0;You want:]"..
+ "list["..list_name..";owner_wants;5,0.5;3,2;]"..
+ "label[5,2.5;In exchange, you give:]"..
+ "list["..list_name..";owner_gives;5,3;3,2;]"..
+ "label[0,5;Owner, Use(E)+Place(RMB) for customer interface]"..
+ "list[current_player;main;0,5.5;8,4;]"
+ return formspec
+ end,
+}
+
+default.shop.check_privilege = function(listname,playername,meta)
+ --[[if listname == "pl1" then
+ if playername ~= meta:get_string("pl1") then
+ return false
+ elseif meta:get_int("pl1step") ~= 1 then
+ return false
+ end
+ end
+ if listname == "pl2" then
+ if playername ~= meta:get_string("pl2") then
+ return false
+ elseif meta:get_int("pl2step") ~= 1 then
+ return false
+ end
+ end]]
+ return true
+end
+
+
+default.shop.give_inventory = function(inv,list,playername)
+ player = minetest.get_player_by_name(playername)
+ if player then
+ for k,v in ipairs(inv:get_list(list)) do
+ player:get_inventory():add_item("main",v)
+ inv:remove_item(list,v)
+ end
+ end
+end
+
+default.shop.cancel = function(meta)
+ --[[default.shop.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl1"))
+ default.shop.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl2"))
+ meta:set_string("pl1","")
+ meta:set_string("pl2","")
+ meta:set_int("pl1step",0)
+ meta:set_int("pl2step",0)]]
+end
+
+default.shop.exchange = function(meta)
+ --[[default.shop.give_inventory(meta:get_inventory(),"pl1",meta:get_string("pl2"))
+ default.shop.give_inventory(meta:get_inventory(),"pl2",meta:get_string("pl1"))
+ meta:set_string("pl1","")
+ meta:set_string("pl2","")
+ meta:set_int("pl1step",0)
+ meta:set_int("pl2step",0)]]
+end
+
+minetest.register_node("currency:shop", {
+ description = "Shop",
+ paramtype2 = "facedir",
+ tiles = {"shop_top.png",
+ "shop_top.png",
+ "shop_side.png",
+ "shop_side.png",
+ "shop_side.png",
+ "shop_front.png"},
+ inventory_image = "shop_front.png",
+ groups = {choppy=2,oddly_breakable_by_hand=2},
+ sounds = default.node_sound_wood_defaults(),
+ after_place_node = function(pos, placer, itemstack)
+ local owner = placer:get_player_name()
+ local meta = minetest.get_meta(pos)
+ meta:set_string("infotext", "Exchange shop (owned by "..owner..")")
+ meta:set_string("owner",owner)
+ --[[meta:set_string("pl1","")
+ meta:set_string("pl2","")]]
+ local inv = meta:get_inventory()
+ inv:set_size("customers_gave", 3*2)
+ inv:set_size("stock", 3*2)
+ inv:set_size("owner_wants", 3*2)
+ inv:set_size("owner_gives", 3*2)
+ end,
+ on_rightclick = function(pos, node, clicker, itemstack)
+ clicker:get_inventory():set_size("customer_gives", 3*2)
+ clicker:get_inventory():set_size("customer_gets", 3*2)
+ default.shop.current_shop[clicker:get_player_name()] = pos
+ local meta = minetest.get_meta(pos)
+ if clicker:get_player_name() == meta:get_string("owner") and not clicker:get_player_control().aux1 then
+ minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",default.shop.formspec.owner(pos))
+ else
+ minetest.show_formspec(clicker:get_player_name(),"currency:shop_formspec",default.shop.formspec.customer(pos))
+ end
+ end,
+ allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
+ local meta = minetest.get_meta(pos)
+ if player:get_player_name() ~= meta:get_string("owner") then return 0 end
+ return count
+ end,
+ allow_metadata_inventory_put = function(pos, listname, index, stack, player)
+ local meta = minetest.get_meta(pos)
+ if player:get_player_name() ~= meta:get_string("owner") then 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 player:get_player_name() ~= meta:get_string("owner") then return 0 end
+ return stack:get_count()
+ end,
+ can_dig = function(pos, player)
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives")
+ end
+})
+
+minetest.register_on_player_receive_fields(function(sender, formname, fields)
+ if formname == "currency:shop_formspec" and fields.exchange ~= nil and fields.exchange ~= "" then
+ local name = sender:get_player_name()
+ local pos = default.shop.current_shop[name]
+ local meta = minetest.get_meta(pos)
+ if meta:get_string("owner") == name then
+ minetest.chat_send_player(name,"This is your own shop, you can't exchange to yourself !")
+ else
+ local minv = meta:get_inventory()
+ local pinv = sender:get_inventory()
+ local invlist_tostring = function(invlist)
+ local out = {}
+ for i, item in pairs(invlist) do
+ out[i] = item:to_string()
+ end
+ return out
+ end
+ local wants = minv:get_list("owner_wants")
+ local gives = minv:get_list("owner_gives")
+ if wants == nil or gives == nil then return end -- do not crash the server
+ -- Check if we can exchange
+ local can_exchange = true
+ local owners_fault = false
+ for i, item in pairs(wants) do
+ if not pinv:contains_item("customer_gives",item) then
+ can_exchange = false
+ end
+ end
+ for i, item in pairs(gives) do
+ if not minv:contains_item("stock",item) then
+ can_exchange = false
+ owners_fault = true
+ end
+ end
+ if can_exchange then
+ for i, item in pairs(wants) do
+ pinv:remove_item("customer_gives",item)
+ minv:add_item("customers_gave",item)
+ end
+ for i, item in pairs(gives) do
+ minv:remove_item("stock",item)
+ pinv:add_item("customer_gets",item)
+ end
+ minetest.chat_send_player(name,"Exchanged!")
+ else
+ if owners_fault then
+ minetest.chat_send_player(name,"Exchange can not be done, contact the shop owner.")
+ else
+ minetest.chat_send_player(name,"Exchange can not be done, check if you put all items !")
+ end
+ end
+ end
+ end
+end)
+
diff --git a/currency/textures/barter_base.png b/currency/textures/barter_base.png
new file mode 100644
index 0000000..b4e2599
--- /dev/null
+++ b/currency/textures/barter_base.png
Binary files differ
diff --git a/currency/textures/barter_side.png b/currency/textures/barter_side.png
new file mode 100644
index 0000000..57c1d7c
--- /dev/null
+++ b/currency/textures/barter_side.png
Binary files differ
diff --git a/currency/textures/barter_top.png b/currency/textures/barter_top.png
new file mode 100644
index 0000000..8ce9256
--- /dev/null
+++ b/currency/textures/barter_top.png
Binary files differ
diff --git a/currency/textures/minegeld.png b/currency/textures/minegeld.png
new file mode 100644
index 0000000..79e36ff
--- /dev/null
+++ b/currency/textures/minegeld.png
Binary files differ
diff --git a/currency/textures/minegeld_10.png b/currency/textures/minegeld_10.png
new file mode 100644
index 0000000..acdb05e
--- /dev/null
+++ b/currency/textures/minegeld_10.png
Binary files differ
diff --git a/currency/textures/minegeld_5.png b/currency/textures/minegeld_5.png
new file mode 100644
index 0000000..5c66ac6
--- /dev/null
+++ b/currency/textures/minegeld_5.png
Binary files differ
diff --git a/currency/textures/minegeld_bundle.png b/currency/textures/minegeld_bundle.png
new file mode 100644
index 0000000..c6b339d
--- /dev/null
+++ b/currency/textures/minegeld_bundle.png
Binary files differ
diff --git a/currency/textures/safe_front.png b/currency/textures/safe_front.png
new file mode 100644
index 0000000..0d4c007
--- /dev/null
+++ b/currency/textures/safe_front.png
Binary files differ
diff --git a/currency/textures/safe_side.png b/currency/textures/safe_side.png
new file mode 100644
index 0000000..1ec4c1f
--- /dev/null
+++ b/currency/textures/safe_side.png
Binary files differ
diff --git a/currency/textures/shop_front.png b/currency/textures/shop_front.png
new file mode 100644
index 0000000..29d0065
--- /dev/null
+++ b/currency/textures/shop_front.png
Binary files differ
diff --git a/currency/textures/shop_side.png b/currency/textures/shop_side.png
new file mode 100644
index 0000000..712364c
--- /dev/null
+++ b/currency/textures/shop_side.png
Binary files differ
diff --git a/currency/textures/shop_top.png b/currency/textures/shop_top.png
new file mode 100644
index 0000000..b4e2599
--- /dev/null
+++ b/currency/textures/shop_top.png
Binary files differ