1
0
mirror of https://github.com/MinetestForFun/minercantile.git synced 2024-12-23 00:00:21 +01:00

readd maptools in depends, use maptools coins or defines coins

This commit is contained in:
crabman77 2016-06-11 02:04:11 +02:00
parent ebe17cc9e3
commit 3ba1431a70
4 changed files with 67 additions and 55 deletions

View File

@ -1,7 +1,24 @@
local coins_convert = {
["minercantile:copper_coin"]=1, ["minercantile:silver_coin"]=100, ["minercantile:gold_coin"]=10000,
["maptools:copper_coin"]=1, ["maptools:silver_coin"]=100, ["maptools:gold_coin"]=10000,
}
local convertion = { ["minercantile:copper_coin"]=1, ["minercantile:silver_coin"]=100, ["minercantile:gold_coin"]=10000} --if maptools then use maptools coins else use minercantile coins
if minetest.get_modpath("maptools") ~= nil then
minetest.override_item("maptools:copper_coin", {
inventory_image = "minercantile_copper_coin.png",
})
minetest.override_item("maptools:silver_coin", {
inventory_image = "minercantile_silver_coin.png",
})
minetest.override_item("maptools:gold_coin", {
inventory_image = "minercantile_gold_coin.png",
})
else
minetest.register_craftitem("minercantile:copper_coin", { minetest.register_craftitem("minercantile:copper_coin", {
description = "Copper Coin", description = "Copper Coin",
inventory_image = "minercantile_copper_coin.png", inventory_image = "minercantile_copper_coin.png",
@ -26,24 +43,25 @@ minetest.register_craftitem("minercantile:gold_coin", {
groups = {not_in_creative_inventory = 0}, groups = {not_in_creative_inventory = 0},
}) })
minetest.register_alias("maptools:copper_coin", "minercantile:copper_coin") minetest.register_alias("maptools:copper_coin", "minercantile:copper_coin")
minetest.register_alias("maptools:silver_coin", "minercantile:silver_coin") minetest.register_alias("maptools:silver_coin", "minercantile:silver_coin")
minetest.register_alias("maptools:gold_coin", "minercantile:gold_coin") minetest.register_alias("maptools:gold_coin", "minercantile:gold_coin")
end
local function get_bancomatic_formspec(pos, name) local function get_bancomatic_formspec(pos, name)
local spos = pos.x .. "," .. pos.y .. "," .. pos.z local spos = pos.x .. "," .. pos.y .. "," .. pos.z
local formspec = local formspec =
"size[8,9]label[3.35,0;Bancomatic]" .. "size[8,9]bgcolor[#2A2A2A;]label[3.35,0;Bancomatic]" ..
"label[0,0;Your money:"..minercantile.wallet.get_money(name).."$]" .. "label[0,0;Your money:"..minercantile.wallet.get_money(name).."$]" ..
"label[2,1;Put your coins to convert on your wallet]" .. "label[2,1;Put your coins to convert on your wallet]" ..
"image[0,1.5;1,1;minercantile_gold_coin.png]" .. "image[0,1.5;1,1;minercantile_gold_coin.png]" ..
"label[1,1.7;= "..convertion["minercantile:gold_coin"].."$]" .. "label[1,1.7;= "..coins_convert["minercantile:gold_coin"].."$]" ..
"image[0,2.5;1,1;minercantile_silver_coin.png]" .. "image[0,2.5;1,1;minercantile_silver_coin.png]" ..
"label[1,2.7;= "..convertion["minercantile:silver_coin"].."$]" .. "label[1,2.7;= "..coins_convert["minercantile:silver_coin"].."$]" ..
"image[0,3.5;1,1;minercantile_copper_coin.png]" .. "image[0,3.5;1,1;minercantile_copper_coin.png]" ..
"label[1,3.7;= "..convertion["minercantile:copper_coin"].."$]" .. "label[1,3.7;= "..coins_convert["minercantile:copper_coin"].."$]" ..
"list[nodemeta:" .. spos .. ";main;3.5,2.5;1,1;]" .. "list[nodemeta:" .. spos .. ";main;3.5,2.5;1,1;]" ..
"list[current_player;main;0,4.85;8,1;]" .. "list[current_player;main;0,4.85;8,1;]" ..
@ -87,8 +105,8 @@ minetest.register_node("minercantile:bancomatic", {
return 0 return 0
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local item = stack:get_name() local itname = stack:get_name()
if item == "minercantile:copper_coin" or item == "minercantile:silver_coin" or item == "minercantile:gold_coin" then if coins_convert[itname] ~= nil then
return stack:get_count() return stack:get_count()
end end
return 0 return 0
@ -97,21 +115,19 @@ minetest.register_node("minercantile:bancomatic", {
return 0 return 0
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
local item = stack:get_name() local itname = stack:get_name()
if item == "minercantile:copper_coin" or item == "minercantile:silver_coin" or item == "minercantile:gold_coin" then if coins_convert[itname] ~= nil then
local name = player:get_player_name() local name = player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local nb = stack:get_count() local nb = stack:get_count()
local amount = convertion[item]*nb local amount = coins_convert[itname]*nb
minercantile.wallet.give_money(name, amount) minercantile.wallet.give_money(name, amount)
inv:set_stack(listname, index, nil) inv:set_stack(listname, index, nil)
minetest.log("action", player:get_player_name() .. " put " .. stack:get_name() .. " to bancomatic at " .. minetest.pos_to_string(pos)) minetest.log("action", player:get_player_name() .. " put " .. stack:get_name() .. " to bancomatic at " .. minetest.pos_to_string(pos))
minetest.show_formspec(name, "minercantile:bancomatic", get_bancomatic_formspec(pos, name)) minetest.show_formspec(name, "minercantile:bancomatic", get_bancomatic_formspec(pos, name))
end end
end, end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
end,
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
minetest.show_formspec(clicker:get_player_name(), "minercantile:bancomatic", get_bancomatic_formspec(pos, clicker:get_player_name())) minetest.show_formspec(clicker:get_player_name(), "minercantile:bancomatic", get_bancomatic_formspec(pos, clicker:get_player_name()))
end, end,

View File

@ -1,2 +1,3 @@
default default
unified_inventory? unified_inventory?
maptools?

View File

@ -6,6 +6,7 @@ minercantile.shop.max_stock = 20000 --shop don't buy infinity items
--shop type, only if item name contains word --shop type, only if item name contains word
minercantile.shop.shop_type = {"all", "3d_armor", "beds", "boats", "brick", "carts", "chest", "cobble", "dye", "doors", "farming", "food", "signs", "fishing", "glass", "decor", "mesecons", "nether", "pipeworks", "runes", "spears", "stone", "tree", "walls", "wood", "wool"} minercantile.shop.shop_type = {"all", "3d_armor", "beds", "boats", "brick", "carts", "chest", "cobble", "dye", "doors", "farming", "food", "signs", "fishing", "glass", "decor", "mesecons", "nether", "pipeworks", "runes", "spears", "stone", "tree", "walls", "wood", "wool"}
--function shop money --function shop money
function minercantile.shop.get_money() function minercantile.shop.get_money()
return (minercantile.stock.money or 0) return (minercantile.stock.money or 0)
@ -69,13 +70,13 @@ end
-- table of sellable/buyable items,ignore admin stuff -- table of sellable/buyable items,ignore admin stuff
function minercantile.shop.register_items() function minercantile.shop.register_items()
minercantile.registered_items = {} minercantile.registered_items = {}
for name, def in pairs(minetest.registered_items) do for itname, def in pairs(minetest.registered_items) do
if not name:find("maptools:") --ignore maptools if not itname:find("maptools:") --ignore maptools
and not itname:find("_coin")
and not def.groups.not_in_creative_inventory and not def.groups.not_in_creative_inventory
and not def.groups.unbreakable and not def.groups.unbreakable
and def.description and def.description ~= "" then and (def.description and def.description ~= "") then
--and minetest.get_all_craft_recipes(name) then minercantile.registered_items[itname] = {groups = def.groups, desc = def.description}
minercantile.registered_items[name] = {groups = def.groups, desc = def.description}
end end
end end
end end
@ -167,9 +168,6 @@ end
-- sell fonction -- sell fonction
function minercantile.shop.get_buy_price(itname) function minercantile.shop.get_buy_price(itname)
if itname == "minercantile:copper_coin" or itname == "minercantile:silver_coin" or itname == "minercantile:gold_coin" then -- dont's buy/sell coins
return nil
end
local price = nil local price = nil
local money = minercantile.shop.get_money() local money = minercantile.shop.get_money()
if not minercantile.stock.items[itname] then if not minercantile.stock.items[itname] then
@ -189,9 +187,6 @@ end
-- sell fonction -- sell fonction
function minercantile.shop.get_sell_price(itname, wear) function minercantile.shop.get_sell_price(itname, wear)
if itname == "minercantile:copper_coin" or itname == "minercantile:silver_coin" or itname == "minercantile:gold_coin" then -- dont's buy/sell coins
return nil
end
local price = nil local price = nil
local money = minercantile.shop.get_money() local money = minercantile.shop.get_money()
if not minercantile.stock.items[itname] then if not minercantile.stock.items[itname] then