Commit 807754a6 authored by SmallJoker's avatar SmallJoker

Upload

parent 1258e0a4
==> How to enable ...
-> Open 'config.txt' with your editor and modify it
==> Add special access to nodes, how?
-> Exchange shop: open 'shop.lua' and edit the function 'has_exchange_shop_privilege',
return 'true' to grant access to the contents, return 'false' to disallow
-> Warehouse: same like exchange shop, this time 'warehouse.lua' and 'has_locked_chest_privilege'
==> Can I ...
-> Suggest things: Sure, I'm happy about (almost) every suggestion, just I'm pretty new, which
means I can't realize all of them
-> Report a fault: I hope this will not happen too much, post it at the topic in the MT forums
-> Edit the files: Yes sure, the license is 'WTFPL' but I'm always happy about credits :smile:
-> Delete this mod: Stupid question
-> Exchange textures: Yes, it's WFTPL! Maybe you need to ask the original creator of the images
==> Give me informations about the converting!
Burning:
1 Gold block -> 2 MineCoin block
2 MineCoin block -> 1 Gold block
1 Coin base -> 1 MineNinth
Crafting:
1 Zinc block -> 8 Coin base
1 Tin block -> 20 Coin base
\ No newline at end of file
--Created by Krock for the BitChange mod
-- Bank node for the mod: currency (by Dan Duncombe)
--License: WTFPL
local file_path = minetest.get_worldpath() .. "/bitchange_bank_currency"
local exchange_worth = 15 -- default worth in "money" for one MineCoin, change if not okay
local bank = {}
local changes_made = false
local fs_1 = io.open(file_path, "r")
if fs_1 then
exchange_worth = tonumber(fs_1:read("*l"))
io.close(fs_1)
end
local function round(num, idp)
if idp and idp>0 then
local mult = 10^idp
return math.floor(num * mult + 0.5) / mult
end
return math.floor(num + 0.5)
end
local function save_exchange_rate()
local fs_2 = io.open(file_path, "w")
fs_2:write(tostring(exchange_worth))
io.close(fs_2)
end
local ttime = 0
minetest.register_globalstep(function(t)
ttime = ttime + t
if ttime < 240 then --every 4min'
return
end
if(changes_made) then
save_exchange_rate()
end
ttime = 0
end)
minetest.register_on_shutdown(function()
save_exchange_rate()
end)
local function has_bank_privilege(meta, player)
local player_name = player:get_player_name()
return ((player_name == meta:get_string("owner")) or minetest.get_player_privs(player_name).server)
end
local function get_bank_formspec(number, pos)
local formspec = ""
local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z
if(number == 1) then
-- customer
formspec = ("size[8,8]"..
"label[0,0;Bank]"..
"label[2,0;(View reserve with (E) + (Right click))]"..
"label[1,1;Current worth of a MineCoin:]"..
"label[3,1.5;~ "..round(exchange_worth, 2).." MineGeld]"..
"button[2,3;3,1;sell10;Buy 10 MineCoins]"..
"button[2,2;3,1;buy10;Sell 10 MineCoins]"..
"list[current_player;main;0,4;8,4;]")
elseif(number == 2) then
-- owner
formspec = ("size[8,9;]"..
"label[0,0;Bank]"..
"label[1,0.5;Current MineCoin reserve: (Editable by owner)]"..
"list["..name..";coins;0,1;8,3;]"..
"list[current_player;main;0,5;8,4;]")
end
return formspec
end
minetest.register_on_player_receive_fields(function(sender, formname, fields)
if(formname == "bitchange:bank_formspec") then
local player_name = sender:get_player_name()
if(fields.quit) then
bank[player_name] = nil
return
end
if(exchange_worth < 1) then
exchange_worth = 1
end
local pos = bank[player_name]
local bank_inv = minetest.get_meta(pos):get_inventory()
local player_inv = sender:get_inventory()
local coin_stack = "bitchange:minecoin 10"
local geld_stack = "currency:minegeld "
local err_msg = ""
if(fields.buy10) then
geld_stack = geld_stack..(round(exchange_worth * 0.995, 1) * 10)
if(not player_inv:contains_item("main", coin_stack)) then
err_msg = "You do not have the needed MineCoins."
end
if(err_msg == "") then
if(not bank_inv:room_for_item("coins", coin_stack)) then
err_msg = "This bank has no space to buy more MineCoins."
end
end
if(err_msg == "") then
if(not bank_inv:contains_item("coins", geld_stack)) then
err_msg = "This bank has no MineGeld ready to sell."
end
end
if(err_msg == "") then
if(not player_inv:room_for_item("main", geld_stack)) then
err_msg = "You do not have enough space in your inventory."
end
end
if(err_msg == "") then
exchange_worth = exchange_worth * 0.995
local price = round(exchange_worth - 0.01, 1) * 10
bank_inv:remove_item("coins", geld_stack)
player_inv:add_item("main", geld_stack)
player_inv:remove_item("main", coin_stack)
bank_inv:add_item("coins", coin_stack)
changes_made = true
err_msg = "Sold 10 MineCoins for "..price.." MineGeld"
end
elseif(fields.sell10) then
local price = round(exchange_worth, 1) * 10
geld_stack = geld_stack..(round(exchange_worth, 1) * 10)
if(not player_inv:contains_item("main", geld_stack)) then
err_msg = "You do not have the required money. ("..price.." x 1 MineGeld pieces)"
end
if(err_msg == "") then
if(not bank_inv:room_for_item("coins", geld_stack)) then
err_msg = "This bank has no space to buy more MineGeld."
end
end
if(err_msg == "") then
if(not bank_inv:contains_item("coins", coin_stack)) then
err_msg = "This bank has no MineCoins ready to sell."
end
end
if(err_msg == "") then
if(not player_inv:room_for_item("main", coin_stack)) then
err_msg = "You do not have enough space in your inventory."
end
end
if(err_msg == "") then
player_inv:remove_item("main", geld_stack)
bank_inv:add_item("coins", geld_stack)
bank_inv:remove_item("coins", coin_stack)
player_inv:add_item("main", coin_stack)
exchange_worth = exchange_worth * 1.005
changes_made = true
err_msg = "Bought 10 MineCoins for "..price.." MineGeld"
end
end
if(err_msg ~= "") then
minetest.chat_send_player(player_name, "Bank: "..err_msg)
end
end
end)
minetest.register_node("bitchange:bank", {
description = "Bank",
tiles = {"bitchange_bank_side.png", "bitchange_bank_side.png",
"bitchange_bank_side.png", "bitchange_bank_side.png",
"bitchange_bank_side.png", "bitchange_bank_front.png"},
paramtype2 = "facedir",
groups = {cracky=1,level=1},
sounds = default.node_sound_stone_defaults(),
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "Bank (owned by "..
meta:get_string("owner")..")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Bank (constructing)")
meta:set_string("formspec", "")
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("coins", 8*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
if(meta:get_string("owner") == player:get_player_name()) then
return meta:get_inventory():is_empty("coins")
else
return false
end
end,
on_rightclick = function(pos, node, clicker, itemstack)
local player_name = clicker:get_player_name()
local view = 1
bank[player_name] = pos
if(clicker:get_player_control().aux1) then
view = 2
end
minetest.show_formspec(player_name,"bitchange:bank_formspec",get_bank_formspec(view, pos))
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if(has_bank_privilege(meta, player)) then
return count
end
return 0
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if (has_bank_privilege(meta, player)) then
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if (has_bank_privilege(meta, player)) then
return stack:get_count()
end
return 0
end,
})
\ No newline at end of file
--Created by Krock for the BitChange mod
-- Bank node for the mod: money (by kotolegokot)
--License: WTFPL
local file_path = minetest.get_worldpath() .. "/bitchange_bank_money"
local exchange_worth = 100.0 -- default worth in "money" for one MineCoin, change if not okay
local bank = {}
local changes_made = false
local fs_1 = io.open(file_path, "r")
if fs_1 then
exchange_worth = tonumber(fs_1:read("*l"))
io.close(fs_1)
end
local function round(num, idp)
if idp and idp>0 then
local mult = 10^idp
return math.floor(num * mult + 0.5) / mult
end
return math.floor(num + 0.5)
end
local function save_exchange_rate()
local fs_2 = io.open(file_path, "w")
fs_2:write(tostring(exchange_worth))
io.close(fs_2)
end
local ttime = 0
minetest.register_globalstep(function(t)
ttime = ttime + t
if ttime < 240 then --every 4min'
return
end
if(changes_made) then
save_exchange_rate()
end
ttime = 0
end)
minetest.register_on_shutdown(function()
save_exchange_rate()
end)
local function has_bank_privilege(meta, player)
local player_name = player:get_player_name()
return ((player_name == meta:get_string("owner")) or minetest.get_player_privs(player_name).server)
end
local function get_bank_formspec(number, pos)
local formspec = ""
local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z
if(number == 1) then
-- customer
formspec = ("size[8,8]"..
"label[0,0;Bank]"..
"label[2,0;(View reserve with (E) + (Right click))]"..
"label[1,1;Current worth of a MineCoin:]"..
"label[3,1.5;~ "..round(exchange_worth, 4).." money]"..
"button[2,3;3,1;sell10;Buy 10 MineCoins]"..
"button[2,2;3,1;buy10;Sell 10 MineCoins]"..
"list[current_player;main;0,4;8,4;]")
elseif(number == 2) then
-- owner
formspec = ("size[8,9;]"..
"label[0,0;Bank]"..
"label[1,0.5;Current MineCoin reserve: (Editable by owner)]"..
"list["..name..";coins;0,1;8,3;]"..
"list[current_player;main;0,5;8,4;]")
end
return formspec
end
minetest.register_on_player_receive_fields(function(sender, formname, fields)
if(formname == "bitchange:bank_formspec") then
local player_name = sender:get_player_name()
if(fields.quit) then
bank[player_name] = nil
return
end
if(exchange_worth < 1) then
exchange_worth = 1
end
local pos = bank[player_name]
local bank_inv = minetest.get_meta(pos):get_inventory()
local player_inv = sender:get_inventory()
local coin_stack = "bitchange:minecoin 10"
local err_msg = ""
if(fields.buy10) then
if(not player_inv:contains_item("main", coin_stack)) then
err_msg = "You do not have the needed MineCoins."
end
if(err_msg == "") then
if(not bank_inv:room_for_item("coins", coin_stack)) then
err_msg = "This bank has no space to buy more MineCoins."
end
end
if(err_msg == "") then
exchange_worth = exchange_worth * 0.995
local price = round(exchange_worth - 0.1, 1) * 10
local cur_money = money.get_money(player_name)
money.set_money(player_name, cur_money + price)
player_inv:remove_item("main", coin_stack)
bank_inv:add_item("coins", coin_stack)
changes_made = true
err_msg = "Sold 10 MineCoins for "..price.." money"
end
elseif(fields.sell10) then
local price = round(exchange_worth, 1) * 10
local cur_money = money.get_money(player_name)
if(cur_money < price) then
err_msg = "You do not have the required money. ("..price.." money)"
end
if(err_msg == "") then
if(not bank_inv:contains_item("coins", coin_stack)) then
err_msg = "This bank has no MineCoins ready to sell."
end
end
if(err_msg == "") then
if(not player_inv:room_for_item("main", coin_stack)) then
err_msg = "You do not have enough space in your inventory."
end
end
if(err_msg == "") then
money.set_money(player_name, cur_money - price)
bank_inv:remove_item("coins", coin_stack)
player_inv:add_item("main", coin_stack)
exchange_worth = exchange_worth * 1.005
changes_made = true
err_msg = "Bought 10 MineCoins for "..price.." money"
end
end
if(err_msg ~= "") then
minetest.chat_send_player(player_name, "Bank: "..err_msg)
end
end
end)
minetest.register_node("bitchange:bank", {
description = "Bank",
tiles = {"bitchange_bank_side.png", "bitchange_bank_side.png",
"bitchange_bank_side.png", "bitchange_bank_side.png",
"bitchange_bank_side.png", "bitchange_bank_front.png"},
paramtype2 = "facedir",
groups = {cracky=1,level=1},
sounds = default.node_sound_stone_defaults(),
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "Bank (owned by "..
meta:get_string("owner")..")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Bank (constructing)")
meta:set_string("formspec", "")
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("coins", 8*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
if(meta:get_string("owner") == player:get_player_name()) then
return meta:get_inventory():is_empty("coins")
else
return false
end
end,
on_rightclick = function(pos, node, clicker, itemstack)
local player_name = clicker:get_player_name()
local view = 1
bank[player_name] = pos
if(clicker:get_player_control().aux1) then
view = 2
end
minetest.show_formspec(player_name,"bitchange:bank_formspec",get_bank_formspec(view, pos))
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if(has_bank_privilege(meta, player)) then
return count
end
return 0
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if (has_bank_privilege(meta, player)) then
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if (has_bank_privilege(meta, player)) then
return stack:get_count()
end
return 0
end,
})
\ No newline at end of file
--Created by Krock for the BitChange mod
-- Bank node for the mod: money2 (by Bad Command)
--License: WTFPL
local file_path = minetest.get_worldpath() .. "/bitchange_bank_money2"
local exchange_worth = 100.0 -- default worth in "cr" for one MineCoin, change if not okay
local bank = {}
local changes_made = false
local fs_1 = io.open(file_path, "r")
if fs_1 then
exchange_worth = tonumber(fs_1:read("*l"))
io.close(fs_1)
end
local function round(num, idp)
if idp and idp>0 then
local mult = 10^idp
return math.floor(num * mult + 0.5) / mult
end
return math.floor(num + 0.5)
end
local function save_exchange_rate()
local fs_2 = io.open(file_path, "w")
fs_2:write(tostring(exchange_worth))
io.close(fs_2)
end
local ttime = 0
minetest.register_globalstep(function(t)
ttime = ttime + t
if ttime < 240 then --every 4min'
return
end
if(changes_made) then
save_exchange_rate()
end
ttime = 0
end)
minetest.register_on_shutdown(function()
save_exchange_rate()
end)
local function has_bank_privilege(meta, player)
local player_name = player:get_player_name()
return ((player_name == meta:get_string("owner")) or minetest.get_player_privs(player_name).server)
end
local function get_bank_formspec(number, pos)
local formspec = ""
local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z
if(number == 1) then
-- customer
formspec = ("size[8,8]"..
"label[0,0;Bank]"..
"label[2,0;(View reserve with (E) + (Right click))]"..
"label[1,1;Current worth of a MineCoin:]"..
"label[3,1.5;~ "..round(exchange_worth, 4).." cr]"..
"button[2,3;3,1;sell10;Buy 10 MineCoins]"..
"button[2,2;3,1;buy10;Sell 10 MineCoins]"..
"list[current_player;main;0,4;8,4;]")
elseif(number == 2) then
-- owner
formspec = ("size[8,9;]"..
"label[0,0;Bank]"..
"label[1,0.5;Current MineCoin reserve: (Editable by owner)]"..
"list["..name..";coins;0,1;8,3;]"..
"list[current_player;main;0,5;8,4;]")
end
return formspec
end
minetest.register_on_player_receive_fields(function(sender, formname, fields)
if(formname == "bitchange:bank_formspec") then
local player_name = sender:get_player_name()
if(fields.quit) then
bank[player_name] = nil
return
end
if(exchange_worth < 1) then
exchange_worth = 1
end
local pos = bank[player_name]
local bank_inv = minetest.get_meta(pos):get_inventory()
local player_inv = sender:get_inventory()
local coin_stack = "bitchange:minecoin 10"
local err_msg = ""
if(fields.buy10) then
if(not player_inv:contains_item("main", coin_stack)) then
err_msg = "You do not have the needed MineCoins."
end
if(err_msg == "") then
if(not bank_inv:room_for_item("coins", coin_stack)) then
err_msg = "This bank has no space to buy more MineCoins."
end
end
if(err_msg == "") then
exchange_worth = exchange_worth * 0.995
local price = round(exchange_worth - 0.1, 1) * 10
local cur_money = money.get(player_name, amount)
money.set(player_name, cur_money + price)
player_inv:remove_item("main", coin_stack)
bank_inv:add_item("coins", coin_stack)
changes_made = true
err_msg = "Sold 10 MineCoins for "..price.." cr"
end
elseif(fields.sell10) then
local price = round(exchange_worth, 1) * 10
local cur_money = money.get(player_name)
if(cur_money < price) then
err_msg = "You do not have the required money. ("..price.." cr)"
end
if(err_msg == "") then
if(not bank_inv:contains_item("coins", coin_stack)) then
err_msg = "This bank has no MineCoins ready to sell."
end
end
if(err_msg == "") then
if(not player_inv:room_for_item("main", coin_stack)) then
err_msg = "You do not have enough space in your inventory."
end
end
if(err_msg == "") then
money.set(player_name, cur_money - price)
bank_inv:remove_item("coins", coin_stack)
player_inv:add_item("main", coin_stack)
exchange_worth = exchange_worth * 1.005
changes_made = true
err_msg = "Bought 10 MineCoins for "..price.." cr"
end
end
if(err_msg ~= "") then
minetest.chat_send_player(player_name, "Bank: "..err_msg)
end
end
end)
minetest.register_node("bitchange:bank", {
description = "Bank",
tiles = {"bitchange_bank_side.png", "bitchange_bank_side.png",
"bitchange_bank_side.png", "bitchange_bank_side.png",
"bitchange_bank_side.png", "bitchange_bank_front.png"},
paramtype2 = "facedir",
groups = {cracky=1,level=1},
sounds = default.node_sound_stone_defaults(),
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", "Bank (owned by "..
meta:get_string("owner")..")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Bank (constructing)")
meta:set_string("formspec", "")
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("coins", 8*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
if(meta:get_string("owner") == player:get_player_name()) then
return meta:get_inventory():is_empty("coins")
else
return false
end
end,
on_rightclick = function(pos, node, clicker, itemstack)
local player_name = clicker:get_player_name()
local view = 1
bank[player_name] = pos
if(clicker:get_player_control().aux1) then
view = 2
end
minetest.show_formspec(player_name,"bitchange:bank_formspec",get_bank_formspec(view, pos))
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if(has_bank_privilege(meta, player)) then
return count
end
return 0
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if (has_bank_privilege(meta, player)) then
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if (has_bank_privilege(meta, player)) then
return stack:get_count()
end
return 0
end,
})
\ No newline at end of file
-- General configuration - BitChange
-- Created by Krock
bitchange_initial_give = 2
-- Enable/Disable whole nodes
bitchange_enable_exchangeshop = true
bitchange_enable_moneychanger = true
bitchange_enable_warehouse = false
-- Set this variable to the modname of the other currency mod.
-- Let it empty if no other currency is installed.
-- Supported: money (by kotolegokot), money2 (by Bad Command), currency (by Dan Duncombe)
bitchange_bank_type = ""
-- Tin converting/generation
bitchange_use_moreores_tin = false -- Activate using
bitchange_need_generate_tin = false -- Generate only if needed
-- Zinc converting/generation
bitchange_use_technic_zinc = false -- Activate using
bitchange_need_generate_zinc = false -- Generate only if needed
-- Pipeworks support
bitchange_exchangeshop_pipeworks = false
bitchange_warehouse_pipeworks = false
-- Advanced generation settings
-- Change in 'minecoins.lua', starting at line 101
\ No newline at end of file
default
moreores?
technic?
pipeworks?
money?
money2?
currency?
\ No newline at end of file
--Created by Krock for the BitChange mod
local mod_path = minetest.get_modpath("bitchange")
dofile(mod_path.."/config.txt")
dofile(mod_path.."/minecoins.lua")
if(bitchange_use_moreores_tin or bitchange_use_technic_zinc or bitchange_use_gold) then
dofile(mod_path.."/moreores.lua")
end
if(bitchange_enable_exchangeshop) then
dofile(mod_path.."/shop.lua")
end
if(bitchange_enable_moneychanger) then
dofile(mod_path.."/moneychanger.lua")
end
if(bitchange_enable_warehouse) then
dofile(mod_path.."/warehouse.lua")
end
if(bitchange_bank_type ~= "") then
if(minetest.get_modpath(bitchange_bank_type) ~= nil) then
dofile(mod_path.."/bank_"..bitchange_bank_type..".lua")
else
print("[BitChange] Bank: Type or mod not found or enabled: "..bitchange_bank_type)
end
end
if(not minetest.setting_getbool("creative_mode") and bitchange_initial_give > 0) then
-- Giving initial money
minetest.register_on_newplayer(function(player)
player:get_inventory():add_item("main", "bitchange:mineninth "..bitchange_initial_give)
end)
end