Browse Source

readd maptools in depends, use maptools coins or defines coins

pull/3/head
crabman77 4 years ago
parent
commit
3ba1431a70
4 changed files with 67 additions and 55 deletions
  1. +55
    -39
      change.lua
  2. +1
    -0
      depends.txt
  3. +8
    -13
      shop.lua
  4. +3
    -3
      wallets.lua

+ 55
- 39
change.lua 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}

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},
})
--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: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.override_item("maptools:silver_coin", {
inventory_image = "minercantile_silver_coin.png",
})

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.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", {
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", {
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;]" ..
"list[current_player;main;0,6.08;8,3;8]" ..
@@ -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,
@@ -119,7 +135,7 @@ minetest.register_node("minercantile:bancomatic", {
})


--nodes
--nodes
minetest.register_craft({
output = "minercantile:bancomatic",
recipe = {


+ 1
- 0
depends.txt View File

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

+ 8
- 13
shop.lua 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
@@ -102,7 +103,7 @@ function minercantile.load_stock_base()
minercantile.stock_base = table.copy(data)
if minercantile.stock_base.money then
minercantile.stock.money = minercantile.stock_base.money
end
end
if minercantile.stock_base.items then
for itname, def in pairs(minercantile.stock_base.items) do
minercantile.stock.items[itname] = table.copy(def)
@@ -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


+ 3
- 3
wallets.lua 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,"label[0.5,1;Sold: ".. tostring(minercantile.wallet.get_money(name)) .."$]")
table.insert(formspec,"label[4,2.3;10 last transactions]")
local transactions = minercantile.wallet.get_transactions(name)
if #transactions < 1 then
table.insert(formspec,"label[3.5,4;There are no transactions]")
@@ -149,7 +149,7 @@ function minercantile.get_formspec_wallet_transfert(name)
local formspec = {}
table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]")
table.insert(formspec,"label[0.5,1;Sold: ".. tostring(money) .."$]")
if money < 5 then
table.insert(formspec, "label[2,4.5;Sorry you can't send money, minimum amount is 5$]")
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, "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[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, "button[1.7,5;1,1;amount;-1]")
table.insert(formspec, "button[2.7,5;1,1;amount;-10]")


Loading…
Cancel
Save