mirror of
https://github.com/MinetestForFun/minercantile.git
synced 2024-12-22 15:50:20 +01:00
added whitelist item
added function additem/delitem
This commit is contained in:
parent
55d73c330e
commit
9ead7cc839
10
init.lua
10
init.lua
@ -8,10 +8,13 @@ minercantile.file_stock = minercantile.path.."/minercantile_stock.txt"
|
|||||||
minetest.mkdir(minercantile.path_wallet)
|
minetest.mkdir(minercantile.path_wallet)
|
||||||
|
|
||||||
--items
|
--items
|
||||||
minercantile.stock_base = {}
|
|
||||||
minercantile.stock = {} -- table saved money, items list
|
|
||||||
minercantile.shop = {}
|
minercantile.shop = {}
|
||||||
minercantile.shop.items_inventory = {}
|
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.items = {}
|
||||||
minercantile.stock.money = 8000
|
minercantile.stock.money = 8000
|
||||||
minercantile.stock.transac_b = 0
|
minercantile.stock.transac_b = 0
|
||||||
@ -23,6 +26,7 @@ minercantile.wallet = {}
|
|||||||
minercantile.wallets = {}
|
minercantile.wallets = {}
|
||||||
|
|
||||||
--load money
|
--load money
|
||||||
|
dofile(minetest.get_modpath("minercantile") .. "/whitelist.lua")
|
||||||
dofile(minetest.get_modpath("minercantile") .. "/wallets.lua")
|
dofile(minetest.get_modpath("minercantile") .. "/wallets.lua")
|
||||||
dofile(minetest.get_modpath("minercantile") .. "/change.lua")
|
dofile(minetest.get_modpath("minercantile") .. "/change.lua")
|
||||||
dofile(minetest.get_modpath("minercantile") .. "/shop.lua")
|
dofile(minetest.get_modpath("minercantile") .. "/shop.lua")
|
||||||
@ -30,7 +34,7 @@ dofile(minetest.get_modpath("minercantile") .. "/shop.lua")
|
|||||||
|
|
||||||
--load items base and available
|
--load items base and available
|
||||||
minercantile.load_stock_base()
|
minercantile.load_stock_base()
|
||||||
minetest.after(1, function()
|
minetest.after(10, function()
|
||||||
minercantile.shop.register_items()
|
minercantile.shop.register_items()
|
||||||
minercantile.load_stock()
|
minercantile.load_stock()
|
||||||
end
|
end
|
||||||
|
101
shop.lua
101
shop.lua
@ -79,6 +79,41 @@ function minercantile.shop.register_items()
|
|||||||
minercantile.registered_items[itname] = {groups = def.groups, desc = def.description}
|
minercantile.registered_items[itname] = {groups = def.groups, desc = def.description}
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -809,7 +844,7 @@ minetest.register_chatcommand("shop_addmoney",{
|
|||||||
|
|
||||||
minetest.register_chatcommand("shop_delmoney",{
|
minetest.register_chatcommand("shop_delmoney",{
|
||||||
params = "money",
|
params = "money",
|
||||||
description = "del money to the shop",
|
description = "del money from the shop",
|
||||||
privs = {shop = true},
|
privs = {shop = true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
param = string.gsub(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())
|
minetest.chat_send_player(name, "you delete "..amount.. ", new total:".. minercantile.shop.get_money())
|
||||||
end,
|
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
whitelist.lua
Normal file
3
whitelist.lua
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
minercantile.shop.items_whitelist = {
|
||||||
|
"maptools:superapple",
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user