Delete 16px textures, clean up bank and variable names
							
								
								
									
										109
									
								
								bank.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,109 @@ | |||||||
|  | bitchange.bank = {} | ||||||
|  | bitchange.bank.players = {} | ||||||
|  | bitchange.bank.file_path = "" | ||||||
|  | bitchange.bank.exchange_worth = 0 | ||||||
|  | bitchange.bank.changes_made = false | ||||||
|  |  | ||||||
|  | minetest.after(1, function() | ||||||
|  | 	local file = io.open(bitchange.bank.file_path, "r") | ||||||
|  | 	if not file then | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  | 	bitchange.bank.exchange_worth = tonumber(file:read("*l")) | ||||||
|  | 	io.close(file) | ||||||
|  | end) | ||||||
|  |  | ||||||
|  | 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 | ||||||
|  |  | ||||||
|  | function bitchange.bank.save() | ||||||
|  | 	if not bitchange.bank.changes_made then | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  | 	local file = io.open(bitchange.bank.file_path, "w") | ||||||
|  | 	file:write(tostring(bitchange.bank.exchange_worth)) | ||||||
|  | 	io.close(file) | ||||||
|  | 	bitchange.bank.changes_made = false | ||||||
|  | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | local ttime = 0 | ||||||
|  | minetest.register_globalstep(function(t) | ||||||
|  | 	ttime = ttime + t | ||||||
|  | 	if ttime < 240 then --every 4min' | ||||||
|  | 			return | ||||||
|  | 	end | ||||||
|  | 	bitchange.bank.save() | ||||||
|  | 	ttime = 0 | ||||||
|  | end) | ||||||
|  |  | ||||||
|  | minetest.register_on_shutdown(function()  | ||||||
|  | 	bitchange.bank.save() | ||||||
|  | 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 | ||||||
|  | 		bitchange.bank.players[player_name] = pos | ||||||
|  | 		if clicker:get_player_control().aux1 then | ||||||
|  | 			view = 2 | ||||||
|  | 		end | ||||||
|  | 		minetest.show_formspec(player_name, "bitchange:bank_formspec", bitchange.bank.get_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 bitchange_has_access(meta:get_string("owner"), player:get_player_name()) then | ||||||
|  | 			return count | ||||||
|  | 		end | ||||||
|  | 		return 0 | ||||||
|  | 	end, | ||||||
|  | 	allow_metadata_inventory_put = function(pos, listname, index, stack, player) | ||||||
|  | 		local meta = minetest.get_meta(pos) | ||||||
|  | 		if bitchange_has_access(meta:get_string("owner"), player:get_player_name()) 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 bitchange_has_access(meta:get_string("owner"), player:get_player_name()) then | ||||||
|  | 			return stack:get_count() | ||||||
|  | 		end | ||||||
|  | 		return 0 | ||||||
|  | 	end, | ||||||
|  | }) | ||||||
| @@ -1,69 +1,26 @@ | |||||||
| --Created by Krock for the BitChange mod | -- Bank node for the mod: currency (by Dan Duncombe) | ||||||
| --	Bank node for the mod: currency (by Dan Duncombe) |  | ||||||
| --License: WTFPL |  | ||||||
|  |  | ||||||
| local file_path = minetest.get_worldpath() .. "/bitchange_bank_currency" | -- default worth in "money" for 10 MineCoins | ||||||
| local exchange_worth = 8 -- default worth in "money" for 10 MineCoins, change if not okay | bitchange.bank.exchange_worth = 8 | ||||||
| local bank = {} |  | ||||||
| local changes_made = false |  | ||||||
|  |  | ||||||
| local fs_1 = io.open(file_path, "r") | function bitchange.bank.get_formspec(number, pos) | ||||||
| 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 |  | ||||||
| 			changes_made = false |  | ||||||
| 			save_exchange_rate() |  | ||||||
| 		end |  | ||||||
| 		ttime = 0 |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| minetest.register_on_shutdown(function()  |  | ||||||
| 	if(changes_made) then |  | ||||||
| 		save_exchange_rate() |  | ||||||
| 	end |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| local function get_bank_formspec(number, pos) |  | ||||||
| 	local formspec = "" | 	local formspec = "" | ||||||
| 	local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z | 	local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z | ||||||
| 	if(number == 1) then | 	if number == 1 then | ||||||
| 		-- customer | 		-- customer | ||||||
| 		formspec = ("size[8,8]".. | 		formspec = ("size[8,8]".. | ||||||
| 				"label[0,0;Bank]".. | 				"label[0,0;Bank]".. | ||||||
| 				"label[2,0;(View reserve with (E) + (Right click))]".. | 				"label[2,0;View reserve with (E) + (Right click)]".. | ||||||
| 				"label[1,1;Current worth of a MineCoin:]".. | 				"label[1,1;Current worth of a MineCoin:]".. | ||||||
| 				"label[3,1.5;~ "..round(exchange_worth / 10, 2).." MineGeld]".. | 				"label[3,1.5;~ "..round(bitchange.bank.exchange_worth / 10, 2).." MineGeld]".. | ||||||
| 				"button[2,3;3,1;sell10;Buy 10 MineCoins]".. | 				"button[2,3;3,1;sell10;Buy 10 MineCoins]".. | ||||||
| 				"button[2,2;3,1;buy10;Sell 10 MineCoins]".. | 				"button[2,2;3,1;buy10;Sell 10 MineCoins]".. | ||||||
| 				"list[current_player;main;0,4;8,4;]") | 				"list[current_player;main;0,4;8,4;]") | ||||||
| 	elseif(number == 2) then | 	elseif number == 2 then | ||||||
| 		-- owner | 		-- owner | ||||||
| 		formspec = ("size[8,9;]".. | 		formspec = ("size[8,9;]".. | ||||||
| 				"label[0,0;Bank]".. | 				"label[0,0;Bank]".. | ||||||
| 				"label[1,0.5;Current MineCoin and MineGeld reserve: (Editable by owner)]".. | 				"label[1,0.5;Current MineCoin and MineGeld reserve: (editable by owner)]".. | ||||||
| 				"list["..name..";coins;0,1;8,3;]".. | 				"list["..name..";coins;0,1;8,3;]".. | ||||||
| 				"list[current_player;main;0,5;8,4;]") | 				"list[current_player;main;0,5;8,4;]") | ||||||
| 	end | 	end | ||||||
| @@ -71,146 +28,86 @@ local function get_bank_formspec(number, pos) | |||||||
| end | end | ||||||
|  |  | ||||||
| minetest.register_on_player_receive_fields(function(sender, formname, fields) | minetest.register_on_player_receive_fields(function(sender, formname, fields) | ||||||
| 	if(formname == "bitchange:bank_formspec") then | 	if formname ~= "bitchange:bank_formspec" then | ||||||
| 		local player_name = sender:get_player_name() | 		return | ||||||
| 		if(fields.quit)  then | 	end | ||||||
| 			bank[player_name] = nil | 	local player_name = sender:get_player_name() | ||||||
| 			return | 	if fields.quit then | ||||||
|  | 		bitchange.bank.players[player_name] = nil | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  | 	if bitchange.bank.exchange_worth < 1 then | ||||||
|  | 		bitchange.bank.exchange_worth = 1 | ||||||
|  | 	end | ||||||
|  | 	local pos = bitchange.bank.players[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 = false | ||||||
|  | 	 | ||||||
|  | 	if fields.buy10 then | ||||||
|  | 		local new_worth = bitchange.bank.exchange_worth * 0.995 | ||||||
|  | 		geld_stack = geld_stack..math.floor(new_worth + 0.5) | ||||||
|  | 		if not player_inv:contains_item("main", coin_stack) then | ||||||
|  | 			err_msg = "You do not have the needed MineCoins." | ||||||
| 		end | 		end | ||||||
| 		if(exchange_worth < 1) then | 		if not err_msg == "" then | ||||||
| 			exchange_worth = 1 | 			if not bank_inv:room_for_item("coins", coin_stack) then | ||||||
| 		end | 				err_msg = "This bank has no space to buy more MineCoins." | ||||||
| 		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)) |  | ||||||
| 			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) |  | ||||||
| 				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) |  | ||||||
| 			geld_stack = geld_stack..price) |  | ||||||
| 			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 | ||||||
| 		end | 		end | ||||||
| 		if(err_msg ~= "") then | 		if not err_msg == "" then | ||||||
| 			minetest.chat_send_player(player_name, "Bank: "..err_msg) | 			if not bank_inv:contains_item("coins", geld_stack) then | ||||||
|  | 				err_msg = "This bank has no MineGeld ready to sell." | ||||||
|  | 			end | ||||||
|  | 		end | ||||||
|  | 		if not 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 not err_msg == "" then | ||||||
|  | 			bitchange.bank.exchange_worth = new_worth | ||||||
|  | 			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) | ||||||
|  | 			bitchange.bank.changes_made = true | ||||||
|  | 			err_msg = "Sold 10 MineCoins for "..math.floor(new_worth + 0.5).." MineGeld" | ||||||
|  | 		end | ||||||
|  | 	elseif fields.sell10 then | ||||||
|  | 		local price = math.floor(bitchange.bank.exchange_worth + 0.5) | ||||||
|  | 		geld_stack = geld_stack..price | ||||||
|  | 		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 not 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 not 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 not 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 not 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) | ||||||
|  | 			bitchange.bank.exchange_worth = bitchange.bank.exchange_worth * 1.005 | ||||||
|  | 			bitchange.bank.changes_made = true | ||||||
|  | 			err_msg = "Bought 10 MineCoins for "..price.." MineGeld" | ||||||
| 		end | 		end | ||||||
| 	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(bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then |  | ||||||
| 			return count |  | ||||||
| 		end |  | ||||||
| 		return 0 |  | ||||||
| 	end, |  | ||||||
| 	allow_metadata_inventory_put = function(pos, listname, index, stack, player) |  | ||||||
| 		local meta = minetest.get_meta(pos) |  | ||||||
| 		if (bitchange_has_access(meta:get_string("owner"), player:get_player_name())) 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 (bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then |  | ||||||
| 			return stack:get_count() |  | ||||||
| 		end |  | ||||||
| 		return 0 |  | ||||||
| 	end, |  | ||||||
| }) |  | ||||||
							
								
								
									
										238
									
								
								bank_money.lua
									
									
									
									
									
								
							
							
						
						| @@ -1,69 +1,26 @@ | |||||||
| --Created by Krock for the BitChange mod | -- Bank node for the mod: money (by kotolegokot) | ||||||
| --	Bank node for the mod: money (by kotolegokot) |  | ||||||
| --License: WTFPL |  | ||||||
|  |  | ||||||
| local file_path = minetest.get_worldpath() .. "/bitchange_bank_money" | -- default worth in "money" for one MineCoin | ||||||
| local exchange_worth = 70.0 -- default worth in "money" for one MineCoin, change if not okay | bitchange.bank.exchange_worth = 70.0 | ||||||
| local bank = {} |  | ||||||
| local changes_made = false |  | ||||||
|  |  | ||||||
| local fs_1 = io.open(file_path, "r") | function bitchange.bank.get_formspec(number, pos) | ||||||
| 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 |  | ||||||
| 			changes_made = false |  | ||||||
| 			save_exchange_rate() |  | ||||||
| 		end |  | ||||||
| 		ttime = 0 |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| minetest.register_on_shutdown(function()  |  | ||||||
| 	if(changes_made) then |  | ||||||
| 		save_exchange_rate() |  | ||||||
| 	end |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| local function get_bank_formspec(number, pos) |  | ||||||
| 	local formspec = "" | 	local formspec = "" | ||||||
| 	local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z | 	local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z | ||||||
| 	if(number == 1) then | 	if number == 1 then | ||||||
| 		-- customer | 		-- customer | ||||||
| 		formspec = ("size[8,8]".. | 		formspec = ("size[8,8]".. | ||||||
| 				"label[0,0;Bank]".. | 				"label[0,0;Bank]".. | ||||||
| 				"label[2,0;(View reserve with (E) + (Right click))]".. | 				"label[2,0;View reserve with (E) + (Right click)]".. | ||||||
| 				"label[1,1;Current worth of a MineCoin:]".. | 				"label[1,1;Current worth of a MineCoin:]".. | ||||||
| 				"label[3,1.5;~ "..round(exchange_worth, 4).." money]".. | 				"label[3,1.5;~ "..round(bitchange.bank.exchange_worth, 4).." money]".. | ||||||
| 				"button[2,3;3,1;sell10;Buy 10 MineCoins]".. | 				"button[2,3;3,1;sell10;Buy 10 MineCoins]".. | ||||||
| 				"button[2,2;3,1;buy10;Sell 10 MineCoins]".. | 				"button[2,2;3,1;buy10;Sell 10 MineCoins]".. | ||||||
| 				"list[current_player;main;0,4;8,4;]") | 				"list[current_player;main;0,4;8,4;]") | ||||||
| 	elseif(number == 2) then | 	elseif number == 2 then | ||||||
| 		-- owner | 		-- owner | ||||||
| 		formspec = ("size[8,9;]".. | 		formspec = ("size[8,9;]".. | ||||||
| 				"label[0,0;Bank]".. | 				"label[0,0;Bank]".. | ||||||
| 				"label[1,0.5;Current MineCoin reserve: (Editable by owner)]".. | 				"label[1,0.5;Current MineCoin reserve: (editable by owner)]".. | ||||||
| 				"list["..name..";coins;0,1;8,3;]".. | 				"list["..name..";coins;0,1;8,3;]".. | ||||||
| 				"list[current_player;main;0,5;8,4;]") | 				"list[current_player;main;0,5;8,4;]") | ||||||
| 	end | 	end | ||||||
| @@ -71,128 +28,69 @@ local function get_bank_formspec(number, pos) | |||||||
| end | end | ||||||
|  |  | ||||||
| minetest.register_on_player_receive_fields(function(sender, formname, fields) | minetest.register_on_player_receive_fields(function(sender, formname, fields) | ||||||
| 	if(formname == "bitchange:bank_formspec") then | 	if formname ~= "bitchange:bank_formspec" then | ||||||
| 		local player_name = sender:get_player_name() | 		return | ||||||
| 		if(fields.quit)  then | 	end | ||||||
| 			bank[player_name] = nil | 	local player_name = sender:get_player_name() | ||||||
| 			return | 	if fields.quit then | ||||||
|  | 		bitchange.bank.players[player_name] = nil | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  | 	if bitchange.bank.exchange_worth < 1 then | ||||||
|  | 		bitchange.bank.exchange_worth = 1 | ||||||
|  | 	end | ||||||
|  | 	local pos = bitchange.bank.players[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 = false | ||||||
|  | 	 | ||||||
|  | 	if fields.buy10 then | ||||||
|  | 		local new_worth = bitchange.bank.exchange_worth / 1.0059 | ||||||
|  | 		if not player_inv:contains_item("main", coin_stack) then | ||||||
|  | 			err_msg = "You do not have the needed MineCoins." | ||||||
| 		end | 		end | ||||||
| 		if(exchange_worth < 1) then | 		if not err_msg == "" then | ||||||
| 			exchange_worth = 1 | 			if not bank_inv:room_for_item("coins", coin_stack) then | ||||||
|  | 				err_msg = "This bank has no space to buy more MineCoins." | ||||||
|  | 			end | ||||||
| 		end | 		end | ||||||
| 		local pos = bank[player_name] | 		if not err_msg == "" then | ||||||
| 		local bank_inv = minetest.get_meta(pos):get_inventory() | 			bitchange.bank.exchange_worth = bitchange.bank.exchange_worth / 1.0059 | ||||||
| 		local player_inv = sender:get_inventory() | 			local price = round(bitchange.bank.exchange_worth - 0.1, 1) * 10 | ||||||
| 		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 / 1.0059 |  | ||||||
| 				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) | 			local cur_money = money.get_money(player_name) | ||||||
| 			if(cur_money < price) then | 			money.set_money(player_name, cur_money + price) | ||||||
| 				err_msg = "You do not have the required money. ("..price.." money)" | 			player_inv:remove_item("main", coin_stack) | ||||||
| 			end | 			bank_inv:add_item("coins", coin_stack) | ||||||
| 			if(err_msg == "") then | 			bitchange.bank.changes_made = true | ||||||
| 				if(not bank_inv:contains_item("coins", coin_stack)) then | 			err_msg = "Sold 10 MineCoins for "..price.." money" | ||||||
| 					err_msg = "This bank has no MineCoins ready to sell." | 		end | ||||||
| 				end | 	elseif fields.sell10 then | ||||||
| 			end | 		local price = round(bitchange.bank.exchange_worth, 1) * 10 | ||||||
| 			if(err_msg == "") then | 		local cur_money = money.get_money(player_name) | ||||||
| 				if(not player_inv:room_for_item("main", coin_stack)) then | 		if cur_money < price  then | ||||||
| 					err_msg = "You do not have enough space in your inventory." | 			err_msg = "You do not have the required money. ("..price.." money)" | ||||||
| 				end | 		end | ||||||
| 			end | 		if not err_msg == "" then | ||||||
| 			if(err_msg == "") then | 			if not bank_inv:contains_item("coins", coin_stack) then | ||||||
| 				money.set_money(player_name, cur_money - price) | 				err_msg = "This bank has no MineCoins ready to sell." | ||||||
| 				bank_inv:remove_item("coins", coin_stack) |  | ||||||
| 				player_inv:add_item("main", coin_stack) |  | ||||||
| 				exchange_worth = exchange_worth * 1.006 |  | ||||||
| 				changes_made = true |  | ||||||
| 				err_msg = "Bought 10 MineCoins for "..price.." money" |  | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
| 		if(err_msg ~= "") then | 		if not err_msg == "" then | ||||||
| 			minetest.chat_send_player(player_name, "Bank: "..err_msg) | 			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 not 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) | ||||||
|  | 			bitchange.bank.exchange_worth = bitchange.bank.exchange_worth * 1.006 | ||||||
|  | 			bitchange.bank.changes_made = true | ||||||
|  | 			err_msg = "Bought 10 MineCoins for "..price.." money" | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| end) | 	if err_msg then | ||||||
|  | 		minetest.chat_send_player(player_name, "Bank: "..err_msg) | ||||||
| minetest.register_node("bitchange:bank", { | 	end | ||||||
| 	description = "Bank", | end) | ||||||
| 	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(bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then |  | ||||||
| 			return count |  | ||||||
| 		end |  | ||||||
| 		return 0 |  | ||||||
| 	end, |  | ||||||
| 	allow_metadata_inventory_put = function(pos, listname, index, stack, player) |  | ||||||
| 		local meta = minetest.get_meta(pos) |  | ||||||
| 		if (bitchange_has_access(meta:get_string("owner"), player:get_player_name())) 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 (bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then |  | ||||||
| 			return stack:get_count() |  | ||||||
| 		end |  | ||||||
| 		return 0 |  | ||||||
| 	end, |  | ||||||
| }) |  | ||||||
							
								
								
									
										241
									
								
								bank_money2.lua
									
									
									
									
									
								
							
							
						
						| @@ -1,69 +1,26 @@ | |||||||
| --Created by Krock for the BitChange mod | -- Bank node for the mod: money2 (by Bad Command) | ||||||
| --	Bank node for the mod: money2 (by Bad Command) |  | ||||||
| --License: WTFPL |  | ||||||
|  |  | ||||||
| local file_path = minetest.get_worldpath() .. "/bitchange_bank_money2" | -- default worth in "cr" for one MineCoin | ||||||
| local exchange_worth = 70.0 -- default worth in "cr" for one MineCoin, change if not okay | bitchange.bank.exchange_worth = 70.0 | ||||||
| local bank = {} |  | ||||||
| local changes_made = false |  | ||||||
|  |  | ||||||
| local fs_1 = io.open(file_path, "r") | function bitchange.bank.get_formspec(number, pos) | ||||||
| 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 |  | ||||||
| 			changes_made = false |  | ||||||
| 			save_exchange_rate() |  | ||||||
| 		end |  | ||||||
| 		ttime = 0 |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| minetest.register_on_shutdown(function()  |  | ||||||
| 	if(changes_made) then |  | ||||||
| 		save_exchange_rate() |  | ||||||
| 	end |  | ||||||
| end) |  | ||||||
|  |  | ||||||
| local function get_bank_formspec(number, pos) |  | ||||||
| 	local formspec = "" | 	local formspec = "" | ||||||
| 	local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z | 	local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z | ||||||
| 	if(number == 1) then | 	if number == 1 then | ||||||
| 		-- customer | 		-- customer | ||||||
| 		formspec = ("size[8,8]".. | 		formspec = ("size[8,8]".. | ||||||
| 				"label[0,0;Bank]".. | 				"label[0,0;Bank]".. | ||||||
| 				"label[2,0;(View reserve with (E) + (Right click))]".. | 				"label[2,0;View reserve with (E) + (Right click)]".. | ||||||
| 				"label[1,1;Current worth of a MineCoin:]".. | 				"label[1,1;Current worth of a MineCoin:]".. | ||||||
| 				"label[3,1.5;~ "..round(exchange_worth, 4).." cr]".. | 				"label[3,1.5;~ "..round(bitchange.bank.exchange_worth, 4).." cr]".. | ||||||
| 				"button[2,3;3,1;sell10;Buy 10 MineCoins]".. | 				"button[2,3;3,1;sell10;Buy 10 MineCoins]".. | ||||||
| 				"button[2,2;3,1;buy10;Sell 10 MineCoins]".. | 				"button[2,2;3,1;buy10;Sell 10 MineCoins]".. | ||||||
| 				"list[current_player;main;0,4;8,4;]") | 				"list[current_player;main;0,4;8,4;]") | ||||||
| 	elseif(number == 2) then | 	elseif number == 2 then | ||||||
| 		-- owner | 		-- owner | ||||||
| 		formspec = ("size[8,9;]".. | 		formspec = ("size[8,9;]".. | ||||||
| 				"label[0,0;Bank]".. | 				"label[0,0;Bank]".. | ||||||
| 				"label[1,0.5;Current MineCoin reserve: (Editable by owner)]".. | 				"label[1,0.5;Current MineCoin reserve: (editable by owner)]".. | ||||||
| 				"list["..name..";coins;0,1;8,3;]".. | 				"list["..name..";coins;0,1;8,3;]".. | ||||||
| 				"list[current_player;main;0,5;8,4;]") | 				"list[current_player;main;0,5;8,4;]") | ||||||
| 	end | 	end | ||||||
| @@ -71,128 +28,68 @@ local function get_bank_formspec(number, pos) | |||||||
| end | end | ||||||
|  |  | ||||||
| minetest.register_on_player_receive_fields(function(sender, formname, fields) | minetest.register_on_player_receive_fields(function(sender, formname, fields) | ||||||
| 	if(formname == "bitchange:bank_formspec") then | 	if formname ~= "bitchange:bank_formspec" then | ||||||
| 		local player_name = sender:get_player_name() | 		return | ||||||
| 		if(fields.quit)  then | 	end | ||||||
| 			bank[player_name] = nil | 	local player_name = sender:get_player_name() | ||||||
| 			return | 	if fields.quit then | ||||||
|  | 		bitchange.bank.players[player_name] = nil | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  | 	if bitchange.bank.exchange_worth < 1 then | ||||||
|  | 		bitchange.bank.exchange_worth = 1 | ||||||
|  | 	end | ||||||
|  | 	local pos = bitchange.bank.players[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 = false | ||||||
|  | 	 | ||||||
|  | 	if fields.buy10 then | ||||||
|  | 		local new_worth = bitchange.bank.exchange_worth / 1.0059 | ||||||
|  | 		if not player_inv:contains_item("main", coin_stack) then | ||||||
|  | 			err_msg = "You do not have the needed MineCoins." | ||||||
| 		end | 		end | ||||||
| 		if(exchange_worth < 1) then | 		if not err_msg == "" then | ||||||
| 			exchange_worth = 1 | 			if not bank_inv:room_for_item("coins", coin_stack) then | ||||||
| 		end | 				err_msg = "This bank has no space to buy more MineCoins." | ||||||
| 		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 / 1.0059 |  | ||||||
| 				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.006 |  | ||||||
| 				changes_made = true |  | ||||||
| 				err_msg = "Bought 10 MineCoins for "..price.." cr" |  | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
| 		if(err_msg ~= "") then | 		if not err_msg == "" then | ||||||
| 			minetest.chat_send_player(player_name, "Bank: "..err_msg) | 			bitchange.bank.exchange_worth = bitchange.bank.exchange_worth / 1.0059 | ||||||
|  | 			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) | ||||||
|  | 			bitchange.bank.changes_made = true | ||||||
|  | 			err_msg = "Sold 10 MineCoins for "..price.." cr" | ||||||
|  | 		end | ||||||
|  | 	elseif fields.sell10 then | ||||||
|  | 		local price = round(bitchange.bank.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.." cr)" | ||||||
|  | 		end | ||||||
|  | 		if not 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 not 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 not err_msg == "" then | ||||||
|  | 			money.set(player_name, cur_money - price) | ||||||
|  | 			bank_inv:remove_item("coins", coin_stack) | ||||||
|  | 			player_inv:add_item("main", coin_stack) | ||||||
|  | 			bitchange.bank.exchange_worth = bitchange.bank.exchange_worth * 1.006 | ||||||
|  | 			bitchange.bank.changes_made = true | ||||||
|  | 			err_msg = "Bought 10 MineCoins for "..price.." cr" | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| end) | 	if err_msg then | ||||||
|  | 		minetest.chat_send_player(player_name, "Bank: "..err_msg) | ||||||
| minetest.register_node("bitchange:bank", { | 	end | ||||||
| 	description = "Bank", | end) | ||||||
| 	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(bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then |  | ||||||
| 			return count |  | ||||||
| 		end |  | ||||||
| 		return 0 |  | ||||||
| 	end, |  | ||||||
| 	allow_metadata_inventory_put = function(pos, listname, index, stack, player) |  | ||||||
| 		local meta = minetest.get_meta(pos) |  | ||||||
| 		if (bitchange_has_access(meta:get_string("owner"), player:get_player_name())) 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 (bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then |  | ||||||
| 			return stack:get_count() |  | ||||||
| 		end |  | ||||||
| 		return 0 |  | ||||||
| 	end, |  | ||||||
| }) |  | ||||||
							
								
								
									
										60
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						| @@ -1,15 +1,16 @@ | |||||||
| --Created by Krock for the BitChange mod | --Created by Krock for the BitChange mod | ||||||
| local mod_path = minetest.get_modpath("bitchange") | bitchange = {} | ||||||
|  | bitchange.mod_path = minetest.get_modpath("bitchange") | ||||||
| local world_path = minetest.get_worldpath() | local world_path = minetest.get_worldpath() | ||||||
|  |  | ||||||
| if freeminer then | if freeminer then | ||||||
| 	minetest = freeminer | 	minetest = freeminer | ||||||
| end | end | ||||||
|  |  | ||||||
| dofile(mod_path.."/config.default.txt") | dofile(bitchange.mod_path.."/config.default.txt") | ||||||
| -- Copied from moretrees mod | -- Copied from moretrees mod | ||||||
| if io.open(world_path.."/bitchange_config.txt","r") == nil then | if not io.open(world_path.."/bitchange_config.txt", "r") then | ||||||
| 	io.input(mod_path.."/config.default.txt") | 	io.input(bitchange.mod_path.."/config.default.txt") | ||||||
| 	io.output(world_path.."/bitchange_config.txt") | 	io.output(world_path.."/bitchange_config.txt") | ||||||
| 	 | 	 | ||||||
| 	while true do | 	while true do | ||||||
| @@ -24,43 +25,40 @@ else | |||||||
| 	dofile(world_path.."/bitchange_config.txt") | 	dofile(world_path.."/bitchange_config.txt") | ||||||
| end | end | ||||||
|  |  | ||||||
| dofile(mod_path.."/minecoins.lua") | dofile(bitchange.mod_path.."/minecoins.lua") | ||||||
| if(bitchange_use_moreores_tin or bitchange_use_technic_zinc or bitchange_use_gold) then | dofile(bitchange.mod_path.."/moreores.lua") | ||||||
| 	dofile(mod_path.."/moreores.lua") | if bitchange_enable_exchangeshop then | ||||||
|  | 	dofile(bitchange.mod_path.."/shop.lua") | ||||||
| end | end | ||||||
| if(bitchange_enable_exchangeshop) then | if bitchange_enable_moneychanger then | ||||||
| 	dofile(mod_path.."/shop.lua") | 	dofile(bitchange.mod_path.."/moneychanger.lua") | ||||||
| end | end | ||||||
| if(bitchange_enable_moneychanger) then | if bitchange_enable_warehouse then | ||||||
| 	dofile(mod_path.."/moneychanger.lua") | 	dofile(bitchange.mod_path.."/warehouse.lua") | ||||||
| end | end | ||||||
| if(bitchange_enable_warehouse) then | if bitchange_enable_toolrepair then | ||||||
| 	dofile(mod_path.."/warehouse.lua") | 	dofile(bitchange.mod_path.."/toolrepair.lua") | ||||||
| end | end | ||||||
| if(bitchange_enable_toolrepair) then | if bitchange_enable_donationbox then | ||||||
| 	dofile(mod_path.."/toolrepair.lua") | 	dofile(bitchange.mod_path.."/donationbox.lua") | ||||||
| end | end | ||||||
| if(bitchange_enable_donationbox) then | if bitchange_enable_bank then | ||||||
| 	dofile(mod_path.."/donationbox.lua") | 	local loaded_bank = false | ||||||
| end | 	for i, v in ipairs({"money", "money2", "currency"}) do | ||||||
| if(bitchange_enable_bank) then | 		if minetest.get_modpath(v) then | ||||||
| 	local loaded_bank = "" | 			loaded_bank = v | ||||||
| 	if(minetest.get_modpath("money") ~= nil) then | 			break | ||||||
| 		loaded_bank = "money" | 		end | ||||||
| 		dofile(mod_path.."/bank_"..loaded_bank..".lua") |  | ||||||
| 	elseif(minetest.get_modpath("money2") ~= nil) then |  | ||||||
| 		loaded_bank = "money2" |  | ||||||
| 		dofile(mod_path.."/bank_"..loaded_bank..".lua") |  | ||||||
| 	elseif(minetest.get_modpath("currency") ~= nil) then |  | ||||||
| 		loaded_bank = "currency" |  | ||||||
| 		dofile(mod_path.."/bank_"..loaded_bank..".lua") |  | ||||||
| 	end | 	end | ||||||
| 	if(loaded_bank ~= "") then | 	if loaded_bank then | ||||||
|  | 		dofile(bitchange.mod_path.."/bank.lua") | ||||||
|  | 		bitchange.bank.file_path = world_path.."/bitchange_bank_"..loaded_bank | ||||||
|  | 		dofile(bitchange.mod_path.."/bank_"..loaded_bank..".lua") | ||||||
| 		print("[BitChange] Bank loaded: "..loaded_bank) | 		print("[BitChange] Bank loaded: "..loaded_bank) | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| if(not minetest.setting_getbool("creative_mode") and bitchange_initial_give > 0) then | if not minetest.setting_getbool("creative_mode") and bitchange_initial_give > 0 then | ||||||
| 	-- Giving initial money | 	-- Giving initial money | ||||||
| 	minetest.register_on_newplayer(function(player) | 	minetest.register_on_newplayer(function(player) | ||||||
| 		player:get_inventory():add_item("main", "bitchange:mineninth "..bitchange_initial_give) | 		player:get_inventory():add_item("main", "bitchange:mineninth "..bitchange_initial_give) | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								moreores.lua
									
									
									
									
									
								
							
							
						
						| @@ -1,38 +1,29 @@ | |||||||
| --Created by Krock | --Created by Krock | ||||||
| --License: WTFPL | --License: WTFPL | ||||||
|  |  | ||||||
| if(bitchange_use_moreores_tin) then | if bitchange_use_moreores_tin and minetest.get_modpath("moreores") then | ||||||
| if(minetest.get_modpath("moreores")) then |  | ||||||
| 	minetest.register_craft({ | 	minetest.register_craft({ | ||||||
| 		output = "bitchange:coinbase 18", | 		output = "bitchange:coinbase 18", | ||||||
| 		recipe = { | 		recipe = { | ||||||
| 			{"moreores:tin_block", "default:pick_diamond"}, | 			{"moreores:tin_block", "default:pick_diamond"}, | ||||||
| 			{"moreores:tin_block", ""} | 			{"moreores:tin_block", ""} | ||||||
| 		}, | 		}, | ||||||
| 		replacements = { {"default:pick_diamond", "default:pick_diamond"} }, | 		replacements = { {"default:pick_diamond", "default:pick_diamond"} } | ||||||
| 	}) | 	}) | ||||||
| else |  | ||||||
| 	print("[BitChange] Error: tin support disabled, missing mod: 'moreores'" |  | ||||||
| end |  | ||||||
| end | end | ||||||
|  |  | ||||||
| if(bitchange_use_technic_zinc) then | if bitchange_use_technic_zinc and minetest.get_modpath("technic_worldgen") then | ||||||
| if(minetest.get_modpath("technic_worldgen")) then |  | ||||||
| 	minetest.register_craft({ | 	minetest.register_craft({ | ||||||
| 		output = "bitchange:coinbase 8", | 		output = "bitchange:coinbase 8", | ||||||
| 		recipe = { | 		recipe = { | ||||||
| 			{"technic:zinc_block", "default:pick_diamond"}, | 			{"technic:zinc_block", "default:pick_diamond"}, | ||||||
| 			{"technic:zinc_block", ""} | 			{"technic:zinc_block", ""} | ||||||
| 		}, | 		}, | ||||||
| 		replacements = { {"default:pick_diamond", "default:pick_diamond"} }, | 		replacements = { {"default:pick_diamond", "default:pick_diamond"} } | ||||||
| 	}) | 	}) | ||||||
| else |  | ||||||
| 	print("[BitChange] Warning: zinc support disabled, missing mod: 'technic_worldgen'" |  | ||||||
| end |  | ||||||
| end | end | ||||||
|  |  | ||||||
| if(bitchange_use_quartz) then | if bitchange_use_quartz and minetest.get_modpath("quartz") then | ||||||
| if(minetest.get_modpath("quartz")) then |  | ||||||
| 	minetest.register_craft({ | 	minetest.register_craft({ | ||||||
| 		output = "bitchange:coinbase", | 		output = "bitchange:coinbase", | ||||||
| 		recipe = { | 		recipe = { | ||||||
| @@ -40,9 +31,6 @@ if(minetest.get_modpath("quartz")) then | |||||||
| 			{"quartz:quartz_crystal", "quartz:quartz_crystal"}, | 			{"quartz:quartz_crystal", "quartz:quartz_crystal"}, | ||||||
| 			{"quartz:quartz_crystal", "quartz:quartz_crystal"} | 			{"quartz:quartz_crystal", "quartz:quartz_crystal"} | ||||||
| 		}, | 		}, | ||||||
| 		replacements = { {"default:pick_diamond", "default:pick_diamond"} }, | 		replacements = { {"default:pick_diamond", "default:pick_diamond"} } | ||||||
| 	}) | 	}) | ||||||
| else |  | ||||||
| 	print("[BitChange] Error: quartz support disabled, missing mod: 'quartz'" |  | ||||||
| end |  | ||||||
| end | end | ||||||
| Before Width: | Height: | Size: 522 B | 
| Before Width: | Height: | Size: 343 B | 
| Before Width: | Height: | Size: 363 B | 
| Before Width: | Height: | Size: 334 B | 
| Before Width: | Height: | Size: 456 B | 
| Before Width: | Height: | Size: 282 B | 
| Before Width: | Height: | Size: 361 B | 
| Before Width: | Height: | Size: 822 B | 
| Before Width: | Height: | Size: 755 B | 
| Before Width: | Height: | Size: 734 B | 
| Before Width: | Height: | Size: 485 B | 
| Before Width: | Height: | Size: 444 B | 
| Before Width: | Height: | Size: 441 B | 
							
								
								
									
										90
									
								
								version.txt
									
									
									
									
									
								
							
							
						
						| @@ -1,90 +0,0 @@ | |||||||
| ======>- Version 1.7.0 -<====== |  | ||||||
| - donation box |  | ||||||
| - more money in money-ores |  | ||||||
| - possible cheating fixes |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.9 -<====== |  | ||||||
| - optional quartz converting support |  | ||||||
| - some other little changes (also in the configuration) |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.8 -<====== |  | ||||||
| - tool repair node |  | ||||||
| - privilege: bitchange |  | ||||||
| - more cleanups |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.7 -<====== |  | ||||||
| - cleanups, adjustments |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.6 -<====== |  | ||||||
| - default config 'config.default.txt' |  | ||||||
| - generation adjustments (coins are alot cheaper now) |  | ||||||
| - recommended: enable converting of gold |  | ||||||
| - new item: "Coin base" to burn into a MineNinth |  | ||||||
| - changed some codes in the converting |  | ||||||
|   * 'HELP_ME.txt' for more information |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.5u1 -<====== |  | ||||||
| - read more in 'config.txt' how to configure it |  | ||||||
| - added currency support for bank |  | ||||||
| - added money2 support for bank |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.5 -<====== |  | ||||||
| - initial money |  | ||||||
| - 32px textures updated |  | ||||||
| - money exchange rate optimized (needs a bugtest) |  | ||||||
| - added a bank (depends on money mod) |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.2 -<====== |  | ||||||
| - some graphic edits |  | ||||||
| - editable exchange shop title |  | ||||||
|  |  | ||||||
| ======>- Version 1.6.0 -<====== |  | ||||||
| - 32px textures |  | ||||||
| - fixed money changer bug |  | ||||||
| - some generation rarity changes |  | ||||||
| - mineninths now digable below -32 |  | ||||||
|  |  | ||||||
| ======>- Version 1.5.5 -<====== |  | ||||||
| - added converting gold into MineCoins |  | ||||||
| - MineNinths now also can be found under -64m |  | ||||||
| - putted together 'crafting.lua' and 'minecoins.lua' |  | ||||||
| - added 'config.txt' |  | ||||||
| - some fixes |  | ||||||
|  |  | ||||||
| ======>- Version 1.5.0 -<====== |  | ||||||
| - added 'HELP_ME.txt', name sais all |  | ||||||
| - pipework support for the exchange shop |  | ||||||
| - pipework support for the warehouse |  | ||||||
|  |  | ||||||
| ======>- Version 1.4.0 -<====== |  | ||||||
| - built shop.lua from scratch |  | ||||||
| - added warehouse.lua for people which have troubles with the space |  | ||||||
|   * enable the warehouse in init.lua |  | ||||||
|  |  | ||||||
| ======>- Version 1.3.0 -<====== |  | ||||||
| - fixes in moneychanger.lua |  | ||||||
| - added moneychanger.lua (might still contain fails) |  | ||||||
|  |  | ||||||
| ======>- Version 1.2.0 -<====== |  | ||||||
| - changed some textures |  | ||||||
| - serval bigfixes |  | ||||||
| - added converting moreores:tin to MineCoin Ninths |  | ||||||
| - added converting technic:zink to MineCoin Ninths |  | ||||||
| - added generation of zink and tin |  | ||||||
|   * enable the support for zinc and/or zinc in moreores.lua |  | ||||||
|  |  | ||||||
| ======>- Version 1.1.0 -<====== |  | ||||||
| - modifed parts of generation |  | ||||||
| - renamed Bitcoins to MineCoins |  | ||||||
| - destroyed all existing "Bitcoins" by setting them a new name |  | ||||||
| - about 30 letters of new codes |  | ||||||
|  |  | ||||||
| ======>- Version 1.0.0 -<====== |  | ||||||
| - first release |  | ||||||
| - exteneded stack limit for bitcoins to 30'000 |  | ||||||
| - bigger stocks in the exchange shop |  | ||||||
| - ore generation added/replaced |  | ||||||
| - Bitninth added |  | ||||||
| - copied "Currency and Economy" from: https://forum.minetest.net/viewtopic.php?pid=106971#p106971 |  | ||||||
| - copied "Bitcoins" mod from: https://forum.minetest.net/viewtopic.php?pid=119354#p119354 |  | ||||||
| =============================== |  | ||||||