added /mp buyinv command
parent
7585349be4
commit
0af5559015
|
@ -17,5 +17,6 @@ Commands:
|
|||
- `/mp infohand`, show more information about the item(s) you are currently holding in hand from the store
|
||||
- `/mp buy <item name> [<amount>]`, buy `<amount>` of `<item name>` from store, if `<amount>` is not provided then amount is 1
|
||||
- `/mp sellinv <item name>`, sell all items `<item name>` from the 'main' inventory list
|
||||
- `/mp buyinv <item name>`, buy full inventory of items `<item name>`, empty slots in the 'main' inventory are required
|
||||
- `/mp top`, show top 5 richest players currently online
|
||||
- `/mp help`, print out this help
|
||||
|
|
|
@ -175,6 +175,58 @@ minetest.register_chatcommand("mp", {
|
|||
return false, "You cannot sell this item. Search in store for items you can sell, example: /mp find stone. See some suggestion from the store: "..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
--
|
||||
-- buy inventory
|
||||
--
|
||||
elseif params[1] == "buyinv" then
|
||||
-- item name is missing from param[2]
|
||||
if not params[2] then
|
||||
return false, "You need to write the item name you want to buy. example: /mp buyinv default:stone, or check out other items in the store: "..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
local inv = player:get_inventory("main")
|
||||
local store_item = x_marketplace.store_list[params[2]]
|
||||
local amount = 0
|
||||
local itemstack = ItemStack({
|
||||
name = params[2]
|
||||
})
|
||||
|
||||
itemstack:set_count(itemstack:get_stack_max())
|
||||
|
||||
if store_item then
|
||||
|
||||
for k, v in ipairs(inv:get_list("main")) do
|
||||
if v:get_name() == "" and v:get_count() == 0 then
|
||||
amount = amount + itemstack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
if amount == 0 then
|
||||
return false, "You don't have empty space in your inventory. Transaction cancelled."
|
||||
end
|
||||
|
||||
local buy_price = amount * store_item.buy
|
||||
local new_balance = x_marketplace.set_player_balance(caller, buy_price * -1)
|
||||
|
||||
-- not enough money
|
||||
if not new_balance then
|
||||
return false, "You don't have enought BitGold. Price for "..amount.." item(s) of "..params[2].." is "..buy_price.." BitGold, but your current balance is: "..x_marketplace.get_player_balance(caller).." BitGold."
|
||||
end
|
||||
|
||||
for k, v in ipairs(inv:get_list("main")) do
|
||||
if v:get_name() == "" and v:get_count() == 0 then
|
||||
inv:add_item("main", itemstack)
|
||||
end
|
||||
end
|
||||
|
||||
return true, "You bought "..amount.." item(s) of "..params[2].." for "..buy_price.." BitGold. Your new balance is: "..new_balance.." BitGold"
|
||||
|
||||
else
|
||||
-- item not in store
|
||||
return false, "This item is not in store, check out other items from the store: "..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
--
|
||||
-- buy
|
||||
--
|
||||
|
@ -290,6 +342,7 @@ minetest.register_chatcommand("mp", {
|
|||
minetest.colorize("#00FFFF", "/mp infohand")..", show more information about the item(s) you are currently holding in hand from the store\n"..
|
||||
minetest.colorize("#00FFFF", "/mp buy").." <item name> [<amount>], buy <amount> of <item name> from store, if <amount> is not provided then amount is 1\n"..
|
||||
minetest.colorize("#00FFFF", "/mp sellinv").." <item name>, sell all items <item name> from the 'main' inventory list\n"..
|
||||
minetest.colorize("#00FFFF", "/mp buyinv").." <item name>, buy full inventory of items <item name>, empty slots in the 'main' inventory are required\n"..
|
||||
minetest.colorize("#00FFFF", "/mp top")..", show top 5 richest players currently online\n"..
|
||||
minetest.colorize("#00FFFF", "/mp help")..", print out this help\n"
|
||||
|
||||
|
|
Loading…
Reference in New Issue