Browse Source

added whitelist item

added function additem/delitem
pull/3/head
crabman77 4 years ago
parent
commit
9ead7cc839
3 changed files with 110 additions and 4 deletions
  1. +7
    -3
      init.lua
  2. +100
    -1
      shop.lua
  3. +3
    -0
      whitelist.lua

+ 7
- 3
init.lua View File

@@ -8,10 +8,13 @@ minercantile.file_stock = minercantile.path.."/minercantile_stock.txt"
minetest.mkdir(minercantile.path_wallet)

--items
minercantile.stock_base = {}
minercantile.stock = {} -- table saved money, items list
minercantile.shop = {}
minercantile.shop.items_inventory = {}
minercantile.shop.items_whitelist = {}

--stock items
minercantile.stock_base = {}
minercantile.stock = {} -- table saved money, items list
minercantile.stock.items = {}
minercantile.stock.money = 8000
minercantile.stock.transac_b = 0
@@ -23,6 +26,7 @@ minercantile.wallet = {}
minercantile.wallets = {}

--load money
dofile(minetest.get_modpath("minercantile") .. "/whitelist.lua")
dofile(minetest.get_modpath("minercantile") .. "/wallets.lua")
dofile(minetest.get_modpath("minercantile") .. "/change.lua")
dofile(minetest.get_modpath("minercantile") .. "/shop.lua")
@@ -30,7 +34,7 @@ dofile(minetest.get_modpath("minercantile") .. "/shop.lua")

--load items base and available
minercantile.load_stock_base()
minetest.after(1, function()
minetest.after(10, function()
minercantile.shop.register_items()
minercantile.load_stock()
end


+ 100
- 1
shop.lua View File

@@ -79,6 +79,41 @@ function minercantile.shop.register_items()
minercantile.registered_items[itname] = {groups = def.groups, desc = def.description}
end
end
minercantile.shop.register_whitelist()
end


function minercantile.shop.register_whitelist()
for _, itname in pairs(minercantile.shop.items_whitelist) do
local def = minetest.registered_items[itname]
if def then
minercantile.registered_items[itname] = {groups = def.groups, desc = def.description}
end
end
end


function minercantile.shop.add_item(itname, nb)
if minercantile.shop.is_available(itname) then
if not minercantile.stock.items[itname] then
minercantile.stock.items[itname] = {nb=0}
end
minercantile.stock.items[itname].nb = minercantile.stock.items[itname].nb + nb
minercantile.save_stock()
end
end

function minercantile.shop.del_item(itname, nb)
if minercantile.shop.is_available(itname) then
if not minercantile.stock.items[itname] then
minercantile.stock.items[itname] = {nb=0}
end
minercantile.stock.items[itname].nb = minercantile.stock.items[itname].nb - nb
if minercantile.stock.items[itname].nb < 0 then
minercantile.stock.items[itname].nb = 0
end
minercantile.save_stock()
end
end


@@ -809,7 +844,7 @@ minetest.register_chatcommand("shop_addmoney",{

minetest.register_chatcommand("shop_delmoney",{
params = "money",
description = "del money to the shop",
description = "del money from the shop",
privs = {shop = true},
func = function(name, param)
param = string.gsub(param, " ", "")
@@ -822,3 +857,67 @@ minetest.register_chatcommand("shop_delmoney",{
minetest.chat_send_player(name, "you delete "..amount.. ", new total:".. minercantile.shop.get_money())
end,
})

minetest.register_chatcommand("shop_additem",{
params = "name number",
description = "give item to the shop",
privs = {shop = true},
func = function(name, param)
if ( param == nil ) then
minetest.chat_send_player(name, "invalid, no param")
return
end
local itname, amount = param:match("^(%S+)%s(%S+)$")
if itname == nil then
minetest.chat_send_player(name, "invalid param item")
return
end
if not minercantile.shop.is_available(itname) then
minetest.chat_send_player(name, "invalid param item unknow")
return
end
if amount == nil or not tonumber(amount) then
minetest.chat_send_player(name, "invalid param amount")
return
end
local amount = tonumber(amount)
if amount < 1 then
minetest.chat_send_player(name, "invalid param amount")
return
end
minercantile.shop.add_item(itname, amount)
minetest.chat_send_player(name, "you add "..amount.. " items, new total:".. minercantile.shop.get_nb(itname))
end,
})

minetest.register_chatcommand("shop_delitem",{
params = "name number",
description = "del item from the shop",
privs = {shop = true},
func = function(name, param)
if ( param == nil ) then
minetest.chat_send_player(name, "invalid, no param")
return
end
local itname, amount = param:match("^(%S+)%s(%S+)$")
if itname == nil then
minetest.chat_send_player(name, "invalid param item")
return
end
if not minercantile.shop.is_available(itname) then
minetest.chat_send_player(name, "invalid param item unknow")
return
end
if amount == nil or not tonumber(amount) then
minetest.chat_send_player(name, "invalid param amount")
return
end
local amount = tonumber(amount)
if amount < 1 then
minetest.chat_send_player(name, "invalid param amount")
return
end
minercantile.shop.del_item(itname, amount)
minetest.chat_send_player(name, "you delete "..amount.. " items, new total:".. minercantile.shop.get_nb(itname))
end,
})

+ 3
- 0
whitelist.lua View File

@@ -0,0 +1,3 @@
minercantile.shop.items_whitelist = {
"maptools:superapple",
}

Loading…
Cancel
Save