diff options
Diffstat (limited to 'currency')
-rw-r--r-- | currency/Money_Info.txt | 69 | ||||
-rw-r--r-- | currency/barter.lua | 338 | ||||
-rw-r--r-- | currency/crafting.lua | 252 | ||||
-rw-r--r-- | currency/craftitems.lua | 102 | ||||
-rw-r--r-- | currency/depends.txt | 2 | ||||
-rw-r--r-- | currency/description.txt | 2 | ||||
-rw-r--r-- | currency/income.lua | 48 | ||||
-rw-r--r-- | currency/init.lua | 48 | ||||
-rw-r--r-- | currency/loot.lua | 21 | ||||
-rw-r--r-- | currency/safe.lua | 212 | ||||
-rw-r--r-- | currency/shop.lua | 434 | ||||
-rw-r--r-- | currency/textures/minegeld_100.png | bin | 0 -> 3527 bytes | |||
-rw-r--r-- | currency/textures/minegeld_cent_10.png | bin | 0 -> 2326 bytes | |||
-rw-r--r-- | currency/textures/minegeld_cent_25.png | bin | 0 -> 2900 bytes | |||
-rw-r--r-- | currency/textures/minegeld_cent_5.png | bin | 0 -> 2992 bytes |
15 files changed, 832 insertions, 696 deletions
diff --git a/currency/Money_Info.txt b/currency/Money_Info.txt index 722d2b9..9bb769c 100644 --- a/currency/Money_Info.txt +++ b/currency/Money_Info.txt @@ -1,33 +1,36 @@ -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
+Minegeld +--------- + +They have no recipe. + +In general, one Mg equals one US dollar, as of Sept. 2018. + +A good starting amount is about 250 Mg on a server + +You currently get a basic income of 10 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 suggestions: + +Coal Lump 1 Mg +Iron Lump 4 Mg +Copper Lump 4 Mg +Gold Lump 5 Mg +Mese Crystal 40 Mg +Diamond 50 Mg + +Ingot Conversion + +Steel Ingot 5 Mg +Copper Ingot 5 Mg +Gold Ingot 6 Mg + +Block Conversion + +Coal Block 9 Mg +Steel Block 45 Mg +Copper Block 45 Mg +Gold Block 54 Mg +Mese Block 360 Mg +Diamond Block 450 Mg diff --git a/currency/barter.lua b/currency/barter.lua index 1fb4f1b..d4763e6 100644 --- a/currency/barter.lua +++ b/currency/barter.lua @@ -1,169 +1,169 @@ -barter = {}
-
--- internationalization boilerplate
-local MP = minetest.get_modpath(minetest.get_current_modname())
-local S, NS = dofile(MP.."/intllib.lua")
-
-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;" .. S("Start") .. "]",
- player = function(name) return "label[3,0;"..name.."]" end,
- accept1 = "button[3,1;1,1;pl1_accept1;" .. S("Confirm") .. "]"..
- "button[3,2;1,1;pl1_cancel;" .. S("Cancel") .. "]",
- accept2 = "button[3,1;1,1;pl1_accept2;" .. S("Exchange") .. "]"..
- "button[3,2;1,1;pl1_cancel;" .. S("Cancel") .. "]",
- },
- pl2 = {
- start = "button[4,1;1,1;pl2_start;" .. S("Start") .. "]",
- player = function(name) return "label[4,0;"..name.."]" end,
- accept1 = "button[4,1;1,1;pl2_accept1;" .. S("Confirm") .. "]"..
- "button[4,2;1,1;pl2_cancel;" .. S("Cancel") .. "]",
- accept2 = "button[4,1;1,1;pl2_accept2;" .. S("Exchange") .. "]"..
- "button[4,2;1,1;pl2_cancel;" .. S("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 = S("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", S("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,
-})
+barter = {} + +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +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;" .. S("Start") .. "]", + player = function(name) return "label[3,0;"..name.."]" end, + accept1 = "button[3,1;1,1;pl1_accept1;" .. S("Confirm") .. "]".. + "button[3,2;1,1;pl1_cancel;" .. S("Cancel") .. "]", + accept2 = "button[3,1;1,1;pl1_accept2;" .. S("Exchange") .. "]".. + "button[3,2;1,1;pl1_cancel;" .. S("Cancel") .. "]", + }, + pl2 = { + start = "button[4,1;1,1;pl2_start;" .. S("Start") .. "]", + player = function(name) return "label[4,0;"..name.."]" end, + accept1 = "button[4,1;1,1;pl2_accept1;" .. S("Confirm") .. "]".. + "button[4,2;1,1;pl2_cancel;" .. S("Cancel") .. "]", + accept2 = "button[4,1;1,1;pl2_accept2;" .. S("Exchange") .. "]".. + "button[4,2;1,1;pl2_cancel;" .. S("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 = S("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", S("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 index ab1374c..5013fd2 100644 --- a/currency/crafting.lua +++ b/currency/crafting.lua @@ -1,83 +1,169 @@ -minetest.register_craft({
- output = 'currency:safe',
- recipe = {
- {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
- {'default:steel_ingot', 'default:mese_crystal', '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_10 5",
- recipe = {"currency:minegeld_50"},
-})
-
-minetest.register_craft({
- type = "shapeless",
- output = "currency:minegeld_50",
- recipe = {"currency:minegeld_10", "currency:minegeld_10", "currency:minegeld_10", "currency:minegeld_10", "currency:minegeld_10"},
-})
-
-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,
-})
-
+minetest.register_craft({ + output = 'currency:safe', + recipe = { + {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:mese_crystal', '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_cent_10", + recipe = { + "currency:minegeld_cent_5", + "currency:minegeld_cent_5" + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_cent_5 2", + recipe = {"currency:minegeld_cent_10"}, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_cent_25", + recipe = { + "currency:minegeld_cent_5", + "currency:minegeld_cent_5", + "currency:minegeld_cent_5", + "currency:minegeld_cent_5", + "currency:minegeld_cent_5" + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_cent_5 5", + recipe = {"currency:minegeld_cent_25"}, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld", + recipe = { + "currency:minegeld_cent_25", + "currency:minegeld_cent_25", + "currency:minegeld_cent_25", + "currency:minegeld_cent_25" + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_cent_25 4", + recipe = {"currency:minegeld"}, +}) + +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 5", + recipe = {"currency:minegeld_5"}, +}) + +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_10 5", + recipe = {"currency:minegeld_50"}, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_50", + recipe = { + "currency:minegeld_10", + "currency:minegeld_10", + "currency:minegeld_10", + "currency:minegeld_10", + "currency:minegeld_10" + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_100", + recipe = { + "currency:minegeld_50", + "currency:minegeld_50" + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "currency:minegeld_50 2", + recipe = {"currency:minegeld_100" }, +}) + +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 index 521195f..079bcb5 100644 --- a/currency/craftitems.lua +++ b/currency/craftitems.lua @@ -1,37 +1,65 @@ --- internationalization boilerplate
-local MP = minetest.get_modpath(minetest.get_current_modname())
-local S, NS = dofile(MP.."/intllib.lua")
-
-minetest.register_craftitem("currency:minegeld", {
- description = S("1 MineGeld Note"),
- inventory_image = "minegeld.png",
- stack_max = 30000,
- groups = {minegeld = 1}
-})
-
-minetest.register_craftitem("currency:minegeld_5", {
- description = S("5 MineGeld Note"),
- inventory_image = "minegeld_5.png",
- stack_max = 30000,
- groups = {minegeld = 1}
-})
-
-minetest.register_craftitem("currency:minegeld_10", {
- description = S("10 MineGeld Note"),
- inventory_image = "minegeld_10.png",
- stack_max = 30000,
- groups = {minegeld = 1}
-})
-
-minetest.register_craftitem("currency:minegeld_50", {
- description = S("50 MineGeld Note"),
- inventory_image = "minegeld_50.png",
- stack_max = 30000,
- groups = {minegeld = 1}
-})
-
-minetest.register_craftitem("currency:minegeld_bundle", {
- description = S("Bundle of random Minegeld notes"),
- inventory_image = "minegeld_bundle.png",
- stack_max = 30000,
-})
+-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +minetest.register_craftitem("currency:minegeld_cent_5", { + description = S("5 Minegeld cent coin"), + inventory_image = "minegeld_cent_5.png", + stack_max = 1000, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_cent_10", { + description = S("10 Minegeld cent coin"), + inventory_image = "minegeld_cent_10.png", + stack_max = 1000, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_cent_25", { + description = S("25 Minegeld cent coin"), + inventory_image = "minegeld_cent_25.png", + stack_max = 1000, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld", { + description = S("1 Minegeld Note"), + inventory_image = "minegeld.png", + stack_max = 65535, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_5", { + description = S("5 Minegeld Note"), + inventory_image = "minegeld_5.png", + stack_max = 65535, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_10", { + description = S("10 Minegeld Note"), + inventory_image = "minegeld_10.png", + stack_max = 65535, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_50", { + description = S("50 Minegeld Note"), + inventory_image = "minegeld_50.png", + stack_max = 65535, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_100", { + description = S("100 Minegeld Note"), + inventory_image = "minegeld_100.png", + stack_max = 65535, + groups = {minegeld = 1} +}) + +minetest.register_craftitem("currency:minegeld_bundle", { + description = S("Bundle of random Minegeld notes"), + inventory_image = "minegeld_bundle.png", + stack_max = 65535, +}) diff --git a/currency/depends.txt b/currency/depends.txt index b650e9b..1b01adf 100644 --- a/currency/depends.txt +++ b/currency/depends.txt @@ -1,4 +1,4 @@ default intllib? loot? -pipeworks?
\ No newline at end of file +pipeworks? diff --git a/currency/description.txt b/currency/description.txt index aca9890..e6e2898 100644 --- a/currency/description.txt +++ b/currency/description.txt @@ -1 +1 @@ -Provides shops, barter tables, safes, and three denominations of currency, called "Minegeld". +Provides shops, barter tables, safes, and multiple denominations of currency, called "Minegeld". diff --git a/currency/income.lua b/currency/income.lua index cbbd5d8..2c9fb47 100644 --- a/currency/income.lua +++ b/currency/income.lua @@ -6,33 +6,33 @@ local S, NS = dofile(MP.."/intllib.lua") 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 - minetest.log("info", "[Currency] "..S("basic income for @1", name)) - end - end + 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 + minetest.log("info", "[Currency] "..S("basic income for @1", 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 - minetest.log("info", "[Currency] "..S("added basic income for @1 to inventory", name)) - end + 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_10", count=count}) + players_income[name] = 0 + minetest.log("info", "[Currency] "..S("added basic income for @1 to inventory", name)) + end end minetest.register_on_dignode(function(pos, oldnode, digger) diff --git a/currency/init.lua b/currency/init.lua index 6dbf3a9..27cb054 100644 --- a/currency/init.lua +++ b/currency/init.lua @@ -1,24 +1,24 @@ -local modpath = minetest.get_modpath("currency")
-
--- internationalization boilerplate
-local S, NS = dofile(modpath.."/intllib.lua")
-
-minetest.log("info", S("Currency mod loading..."))
-
-dofile(modpath.."/craftitems.lua")
-minetest.log("info", "[Currency] "..S("Craft_items Loaded!"))
-dofile(modpath.."/shop.lua")
-minetest.log("info", "[Currency] "..S("Shop Loaded!"))
-dofile(modpath.."/barter.lua")
-minetest.log("info", "[Currency] "..S("Barter Loaded!"))
-dofile(modpath.."/safe.lua")
-minetest.log("info", "[Currency] "..S("Safe Loaded!"))
-dofile(modpath.."/crafting.lua")
-minetest.log("info", "[Currency] "..S("Crafting Loaded!"))
-
-if minetest.settings:get_bool("creative_mode") then
- minetest.log("info", "[Currency] "..S("Creative mode in use, skipping basic income."))
-else
- dofile(modpath.."/income.lua")
- minetest.log("info", "[Currency] "..S("Income Loaded!"))
-end
+local modpath = minetest.get_modpath("currency") + +-- internationalization boilerplate +local S, NS = dofile(modpath.."/intllib.lua") + +minetest.log("info", S("Currency mod loading...")) + +dofile(modpath.."/craftitems.lua") +minetest.log("info", "[Currency] "..S("Craft_items Loaded!")) +dofile(modpath.."/shop.lua") +minetest.log("info", "[Currency] "..S("Shop Loaded!")) +dofile(modpath.."/barter.lua") +minetest.log("info", "[Currency] "..S("Barter Loaded!")) +dofile(modpath.."/safe.lua") +minetest.log("info", "[Currency] "..S("Safe Loaded!")) +dofile(modpath.."/crafting.lua") +minetest.log("info", "[Currency] "..S("Crafting Loaded!")) + +if minetest.settings:get_bool("creative_mode") then + minetest.log("info", "[Currency] "..S("Creative mode in use, skipping basic income.")) +else + dofile(modpath.."/income.lua") + minetest.log("info", "[Currency] "..S("Income Loaded!")) +end diff --git a/currency/loot.lua b/currency/loot.lua index e687724..d0ea820 100644 --- a/currency/loot.lua +++ b/currency/loot.lua @@ -27,4 +27,23 @@ loot.register_loot({ min_size = 1, max_size = 10, }, -})
\ No newline at end of file +}) + + +loot.register_loot({ + weights = { generic = 50 }, + payload = { + stack = ItemStack("currency:minegeld_50"), + min_size = 1, + max_size = 10, + }, +}) + +loot.register_loot({ + weights = { generic = 50 }, + payload = { + stack = ItemStack("currency:minegeld_100"), + min_size = 1, + max_size = 10, + }, +}) diff --git a/currency/safe.lua b/currency/safe.lua index b5c3c38..ad243e5 100644 --- a/currency/safe.lua +++ b/currency/safe.lua @@ -1,106 +1,106 @@ --- internationalization boilerplate
-local MP = minetest.get_modpath(minetest.get_current_modname())
-local S, NS = dofile(MP.."/intllib.lua")
-
-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;]"..
- "listring[nodemeta:".. spos .. ";main]"..
- "listring[current_player;main]"
- return formspec
-end
-
-local function has_safe_privilege(meta, player)
- local name = ""
- if player then
- if minetest.check_player_privs(player, "protection_bypass") then
- return true
- end
- name = player:get_player_name()
- end
- if name ~= meta:get_string("owner") then
- return false
- end
- return true
-end
-
-minetest.register_node("currency:safe", {
- description = S("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", S("Safe (owned by @1)", 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", S("@1 tried to access a safe belonging to @2 at @3",
- player:get_player_name(), meta:get_string("owner"), 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", S("@1 tried to access a safe belonging to @2 at @3",
- player:get_player_name(), meta:get_string("owner"), 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", S("@1 tried to access a safe belonging to @2 at @3",
- player:get_player_name(), meta:get_string("owner"), 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", S("@1 moves stuff in safe at @2", player:get_player_name(), minetest.pos_to_string(pos)))
- end,
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- minetest.log("action", S("@1 moves stuff to safe at @2", player:get_player_name(), minetest.pos_to_string(pos)))
- end,
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- minetest.log("action", S("@1 takes stuff from safe at @2", player:get_player_name(), 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,
-})
+-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +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;]".. + "listring[nodemeta:".. spos .. ";main]".. + "listring[current_player;main]" + return formspec +end + +local function has_safe_privilege(meta, player) + local name = "" + if player then + if minetest.check_player_privs(player, "protection_bypass") then + return true + end + name = player:get_player_name() + end + if name ~= meta:get_string("owner") then + return false + end + return true +end + +minetest.register_node("currency:safe", { + description = S("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", S("Safe (owned by @1)", 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", S("@1 tried to access a safe belonging to @2 at @3", + player:get_player_name(), meta:get_string("owner"), 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", S("@1 tried to access a safe belonging to @2 at @3", + player:get_player_name(), meta:get_string("owner"), 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", S("@1 tried to access a safe belonging to @2 at @3", + player:get_player_name(), meta:get_string("owner"), 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", S("@1 moves stuff in safe at @2", player:get_player_name(), minetest.pos_to_string(pos))) + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", S("@1 moves stuff to safe at @2", player:get_player_name(), minetest.pos_to_string(pos))) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", S("@1 takes stuff from safe at @2", player:get_player_name(), 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 index 301a08c..6f7d264 100644 --- a/currency/shop.lua +++ b/currency/shop.lua @@ -1,217 +1,217 @@ --- internationalization boilerplate
-local MP = minetest.get_modpath(minetest.get_current_modname())
-local S, NS = dofile(MP.."/intllib.lua")
-
-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;" .. S("Customer gives (pay here!)") .. "]"..
- "list[current_player;customer_gives;0,0.5;3,2;]"..
- "label[0,2.5;" .. S("Customer gets:") .. "]"..
- "list[current_player;customer_gets;0,3;3,2;]"..
- "label[5,0;" .. S("Owner wants:") .. "]"..
- "list["..list_name..";owner_wants;5,0.5;3,2;]"..
- "label[5,2.5;" .. S("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;" .. S("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;" .. S("Customers gave:") .. "]"..
- "list["..list_name..";customers_gave;0,0.5;3,2;]"..
- "label[0,2.5;" .. S("Your stock:") .. "]"..
- "list["..list_name..";stock;0,3;3,2;]"..
- "label[5,0;" .. S("You want:") .. "]"..
- "list["..list_name..";owner_wants;5,0.5;3,2;]"..
- "label[5,2.5;" .. S("In exchange, you give:") .. "]"..
- "list["..list_name..";owner_gives;5,3;3,2;]"..
- "label[0,5;" .. S("Owner, Use (E)+Place (right mouse button) for customer interface") .. "]"..
- "list[current_player;main;0,5.5;8,4;]"
- return formspec
- end,
-}
-
-local have_pipeworks = minetest.global_exists("pipeworks")
-
-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 = S("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,tubedevice=1,tubedevice_receiver=1},
- 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", S("Exchange shop (owned by @1)", 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)
- if have_pipeworks then pipeworks.after_place(pos) end
- end,
- after_dig_node = (have_pipeworks and pipeworks and pipeworks.after_dig),
- tube = {
- insert_object = function(pos, node, stack, direction)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- return inv:add_item("stock",stack)
- end,
- can_insert = function(pos,node,stack,direction)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- return inv:room_for_item("stock", stack)
- end,
- input_inventory = "customers_gave",
- connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
- },
- 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,S("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,S("Exchanged!"))
- else
- if owners_fault then
- minetest.chat_send_player(name,S("Exchange can not be done, contact the shop owner."))
- else
- minetest.chat_send_player(name,S("Exchange can not be done, check if you put all items!"))
- end
- end
- end
- end
-end)
-
+-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +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;" .. S("Customer gives (pay here!)") .. "]".. + "list[current_player;customer_gives;0,0.5;3,2;]".. + "label[0,2.5;" .. S("Customer gets:") .. "]".. + "list[current_player;customer_gets;0,3;3,2;]".. + "label[5,0;" .. S("Owner wants:") .. "]".. + "list["..list_name..";owner_wants;5,0.5;3,2;]".. + "label[5,2.5;" .. S("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;" .. S("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;" .. S("Customers gave:") .. "]".. + "list["..list_name..";customers_gave;0,0.5;3,2;]".. + "label[0,2.5;" .. S("Your stock:") .. "]".. + "list["..list_name..";stock;0,3;3,2;]".. + "label[5,0;" .. S("You want:") .. "]".. + "list["..list_name..";owner_wants;5,0.5;3,2;]".. + "label[5,2.5;" .. S("In exchange, you give:") .. "]".. + "list["..list_name..";owner_gives;5,3;3,2;]".. + "label[0,5;" .. S("Owner, Use (E)+Place (right mouse button) for customer interface") .. "]".. + "list[current_player;main;0,5.5;8,4;]" + return formspec + end, +} + +local have_pipeworks = minetest.global_exists("pipeworks") + +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 = S("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,tubedevice=1,tubedevice_receiver=1}, + 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", S("Exchange shop (owned by @1)", 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) + if have_pipeworks then pipeworks.after_place(pos) end + end, + after_dig_node = (have_pipeworks and pipeworks and pipeworks.after_dig), + tube = { + insert_object = function(pos, node, stack, direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:add_item("stock",stack) + end, + can_insert = function(pos,node,stack,direction) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:room_for_item("stock", stack) + end, + input_inventory = "customers_gave", + connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1} + }, + 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,S("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,S("Exchanged!")) + else + if owners_fault then + minetest.chat_send_player(name,S("Exchange can not be done, contact the shop owner.")) + else + minetest.chat_send_player(name,S("Exchange can not be done, check if you put all items!")) + end + end + end + end +end) + diff --git a/currency/textures/minegeld_100.png b/currency/textures/minegeld_100.png Binary files differnew file mode 100644 index 0000000..0e33b7a --- /dev/null +++ b/currency/textures/minegeld_100.png diff --git a/currency/textures/minegeld_cent_10.png b/currency/textures/minegeld_cent_10.png Binary files differnew file mode 100644 index 0000000..3875232 --- /dev/null +++ b/currency/textures/minegeld_cent_10.png diff --git a/currency/textures/minegeld_cent_25.png b/currency/textures/minegeld_cent_25.png Binary files differnew file mode 100644 index 0000000..cf27f29 --- /dev/null +++ b/currency/textures/minegeld_cent_25.png diff --git a/currency/textures/minegeld_cent_5.png b/currency/textures/minegeld_cent_5.png Binary files differnew file mode 100644 index 0000000..451c27a --- /dev/null +++ b/currency/textures/minegeld_cent_5.png |