1
0
mirror of https://github.com/MinetestForFun/minercantile.git synced 2024-12-22 15:50:20 +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,49 +1,67 @@
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.register_craftitem("minercantile:copper_coin", {
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", {
description = "Copper Coin",
inventory_image = "minercantile_copper_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000,
groups = {not_in_creative_inventory = 0},
})
})
minetest.register_craftitem("minercantile:silver_coin", {
minetest.register_craftitem("minercantile:silver_coin", {
description = "Silver Coin",
inventory_image = "minercantile_silver_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000,
groups = {not_in_creative_inventory = 0},
})
})
minetest.register_craftitem("minercantile:gold_coin", {
minetest.register_craftitem("minercantile:gold_coin", {
description = "Gold Coin",
inventory_image = "minercantile_gold_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000,
groups = {not_in_creative_inventory = 0},
})
})
minetest.register_alias("maptools:copper_coin", "minercantile:copper_coin")
minetest.register_alias("maptools:silver_coin", "minercantile:silver_coin")
minetest.register_alias("maptools:gold_coin", "minercantile:gold_coin")
end
minetest.register_alias("maptools:copper_coin", "minercantile:copper_coin")
minetest.register_alias("maptools:silver_coin", "minercantile:silver_coin")
minetest.register_alias("maptools:gold_coin", "minercantile:gold_coin")
local function get_bancomatic_formspec(pos, name)
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
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[2,1;Put your coins to convert on your wallet]" ..
"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]" ..
"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]" ..
"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[current_player;main;0,4.85;8,1;]" ..
@ -87,8 +105,8 @@ minetest.register_node("minercantile:bancomatic", {
return 0
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local item = stack:get_name()
if item == "minercantile:copper_coin" or item == "minercantile:silver_coin" or item == "minercantile:gold_coin" then
local itname = stack:get_name()
if coins_convert[itname] ~= nil then
return stack:get_count()
end
return 0
@ -97,21 +115,19 @@ minetest.register_node("minercantile:bancomatic", {
return 0
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local item = stack:get_name()
if item == "minercantile:copper_coin" or item == "minercantile:silver_coin" or item == "minercantile:gold_coin" then
local itname = stack:get_name()
if coins_convert[itname] ~= nil then
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local nb = stack:get_count()
local amount = convertion[item]*nb
local amount = coins_convert[itname]*nb
minercantile.wallet.give_money(name, amount)
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.show_formspec(name, "minercantile:bancomatic", get_bancomatic_formspec(pos, name))
end
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
end,
on_rightclick = function(pos, node, clicker)
minetest.show_formspec(clicker:get_player_name(), "minercantile:bancomatic", get_bancomatic_formspec(pos, clicker:get_player_name()))
end,

View File

@ -1,2 +1,3 @@
default
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
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 minercantile.shop.get_money()
return (minercantile.stock.money or 0)
@ -69,13 +70,13 @@ end
-- table of sellable/buyable items,ignore admin stuff
function minercantile.shop.register_items()
minercantile.registered_items = {}
for name, def in pairs(minetest.registered_items) do
if not name:find("maptools:") --ignore maptools
for itname, def in pairs(minetest.registered_items) do
if not itname:find("maptools:") --ignore maptools
and not itname:find("_coin")
and not def.groups.not_in_creative_inventory
and not def.groups.unbreakable
and def.description and def.description ~= "" then
--and minetest.get_all_craft_recipes(name) then
minercantile.registered_items[name] = {groups = def.groups, desc = def.description}
and (def.description and def.description ~= "") then
minercantile.registered_items[itname] = {groups = def.groups, desc = def.description}
end
end
end
@ -167,9 +168,6 @@ end
-- sell fonction
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 money = minercantile.shop.get_money()
if not minercantile.stock.items[itname] then
@ -189,9 +187,6 @@ end
-- sell fonction
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 money = minercantile.shop.get_money()
if not minercantile.stock.items[itname] then
@ -267,7 +262,7 @@ local function get_shop_inventory_by_page(name)
if nb > 0 then
local price = minercantile.shop.get_buy_price(itname)
if price and price > 0 then
table.insert(inv_list, {name=itname,nb=nb,price=price})
table.insert(inv_list, {name=itname, nb=nb, price=price})
end
end
end