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,50 +1,68 @@
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", {
description = "Copper Coin", inventory_image = "minercantile_silver_coin.png",
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.override_item("maptools:gold_coin", {
description = "Silver Coin", inventory_image = "minercantile_gold_coin.png",
inventory_image = "minercantile_silver_coin.png", })
wield_scale = {x = 0.5, y = 0.5, z = 0.25}, else
stack_max = 10000, minetest.register_craftitem("minercantile:copper_coin", {
groups = {not_in_creative_inventory = 0}, 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:gold_coin", { minetest.register_craftitem("minercantile:silver_coin", {
description = "Gold Coin", description = "Silver Coin",
inventory_image = "minercantile_gold_coin.png", inventory_image = "minercantile_silver_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25}, wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000, stack_max = 10000,
groups = {not_in_creative_inventory = 0}, groups = {not_in_creative_inventory = 0},
}) })
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 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;]" ..
"list[current_player;main;0,6.08;8,3;8]" .. "list[current_player;main;0,6.08;8,3;8]" ..
@ -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,
@ -119,7 +135,7 @@ minetest.register_node("minercantile:bancomatic", {
}) })
--nodes --nodes
minetest.register_craft({ minetest.register_craft({
output = "minercantile:bancomatic", output = "minercantile:bancomatic",
recipe = { recipe = {

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
@ -102,7 +103,7 @@ function minercantile.load_stock_base()
minercantile.stock_base = table.copy(data) minercantile.stock_base = table.copy(data)
if minercantile.stock_base.money then if minercantile.stock_base.money then
minercantile.stock.money = minercantile.stock_base.money minercantile.stock.money = minercantile.stock_base.money
end end
if minercantile.stock_base.items then if minercantile.stock_base.items then
for itname, def in pairs(minercantile.stock_base.items) do for itname, def in pairs(minercantile.stock_base.items) do
minercantile.stock.items[itname] = table.copy(def) minercantile.stock.items[itname] = table.copy(def)
@ -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
@ -267,7 +262,7 @@ local function get_shop_inventory_by_page(name)
if nb > 0 then if nb > 0 then
local price = minercantile.shop.get_buy_price(itname) local price = minercantile.shop.get_buy_price(itname)
if price and price > 0 then 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 end
end end

View File

@ -126,7 +126,7 @@ function minercantile.get_formspec_wallet(name)
table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]") table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]")
table.insert(formspec,"label[0.5,1;Sold: ".. tostring(minercantile.wallet.get_money(name)) .."$]") table.insert(formspec,"label[0.5,1;Sold: ".. tostring(minercantile.wallet.get_money(name)) .."$]")
table.insert(formspec,"label[4,2.3;10 last transactions]") table.insert(formspec,"label[4,2.3;10 last transactions]")
local transactions = minercantile.wallet.get_transactions(name) local transactions = minercantile.wallet.get_transactions(name)
if #transactions < 1 then if #transactions < 1 then
table.insert(formspec,"label[3.5,4;There are no transactions]") table.insert(formspec,"label[3.5,4;There are no transactions]")
@ -149,7 +149,7 @@ function minercantile.get_formspec_wallet_transfert(name)
local formspec = {} local formspec = {}
table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]") table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]")
table.insert(formspec,"label[0.5,1;Sold: ".. tostring(money) .."$]") table.insert(formspec,"label[0.5,1;Sold: ".. tostring(money) .."$]")
if money < 5 then if money < 5 then
table.insert(formspec, "label[2,4.5;Sorry you can't send money, minimum amount is 5$]") table.insert(formspec, "label[2,4.5;Sorry you can't send money, minimum amount is 5$]")
else else
@ -178,7 +178,7 @@ function minercantile.get_formspec_wallet_transfert(name)
table.insert(formspec, "dropdown[3,3.5;3,1;receiver;"..table.concat(states[name].players_list, ",")..";"..states[name].selected_id.."]") table.insert(formspec, "dropdown[3,3.5;3,1;receiver;"..table.concat(states[name].players_list, ",")..";"..states[name].selected_id.."]")
table.insert(formspec, "label[3.5,6.4;Send "..states[name]["amount"].."$ to "..(states[name]["receiver"] or "").." ?]") table.insert(formspec, "label[3.5,6.4;Send "..states[name]["amount"].."$ to "..(states[name]["receiver"] or "").." ?]")
table.insert(formspec,"button[4.1,7;1.5,1;send;send]") table.insert(formspec,"button[4.1,7;1.5,1;send;send]")
table.insert(formspec,"button[6,3.4;1.5,1;refresh;refresh list]") table.insert(formspec,"button[6,3.4;1.5,1;refresh;refresh list]")
table.insert(formspec, "label[3.5,4.5;Amount to send (minimum 5$)]") table.insert(formspec, "label[3.5,4.5;Amount to send (minimum 5$)]")
table.insert(formspec, "button[1.7,5;1,1;amount;-1]") table.insert(formspec, "button[1.7,5;1,1;amount;-1]")
table.insert(formspec, "button[2.7,5;1,1;amount;-10]") table.insert(formspec, "button[2.7,5;1,1;amount;-10]")