initial commit

This commit is contained in:
Vanessa Ezekowitz 2014-07-04 05:28:19 -04:00
commit 5e5580db1e
22 changed files with 652 additions and 0 deletions

33
Money_Info.txt Normal file

@ -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

4
README.md Normal file

@ -0,0 +1,4 @@
currency
========
Repo for Currency Mod

165
barter.lua Normal file

@ -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.env: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.env: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.env: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.env: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.env: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.env:get_meta(pos)
if not barter.chest.check_privilege(listname,player:get_player_name(),meta) then return 0 end
return stack:get_count()
end,
})

71
crafting.lua Normal file

@ -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,
})

26
craftitems.lua Normal file

@ -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,
})

1
depends.txt Normal file

@ -0,0 +1 @@
default

40
income.lua Normal file

@ -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)

13
init.lua Normal file

@ -0,0 +1,13 @@
print(" Currency mod loading... ")
dofile(minetest.get_modpath("currency").."/craftitems.lua")
print("[Currency] Craft_items Loaded!")
dofile(minetest.get_modpath("currency").."/shop.lua")
print("[Currency] Shop Loaded!")
dofile(minetest.get_modpath("currency").."/barter.lua")
print("[Currency] Barter Loaded!")
dofile(minetest.get_modpath("currency").."/safe.lua")
print("[Currency] Safe Loaded!")
dofile(minetest.get_modpath("currency").."/crafting.lua")
print("[Currency] Crafting Loaded!")
dofile(minetest.get_modpath("currency").."/income.lua")
print("[Currency] Income Loaded!")

103
safe.lua Normal file

@ -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 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,
})

196
shop.lua Normal file

@ -0,0 +1,196 @@
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.env: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.env: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.env: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.env: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.env: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.env: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.env: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)
print(dump(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.env: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)

BIN
textures/barter_base.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

BIN
textures/barter_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
textures/barter_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

BIN
textures/minegeld.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
textures/minegeld_10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
textures/minegeld_5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
textures/safe_front.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

BIN
textures/safe_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
textures/shop_front.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

BIN
textures/shop_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

BIN
textures/shop_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B