master
Juraj Vajda 2018-11-10 19:14:16 -05:00
parent 7f2c3b059d
commit 9f6bc70e7b
2 changed files with 17 additions and 11 deletions

View File

@ -119,8 +119,6 @@ function x_marketplace.find_signs(player_pos, text)
local sign_text = sign_meta:get_string("text"):trim() local sign_text = sign_meta:get_string("text"):trim()
if sign_text == text then if sign_text == text then
print("sign_text", sign_text)
print("text", text)
found = true found = true
break break
end end

View File

@ -80,7 +80,6 @@ minetest.register_chatcommand("mp", {
item_count = itemstack:get_stack_max() item_count = itemstack:get_stack_max()
end end
player:set_wielded_item(ItemStack(""))
local sell_price = store_item.sell * item_count local sell_price = store_item.sell * item_count
local new_balance, msg = x_marketplace.set_player_balance(caller, sell_price) local new_balance, msg = x_marketplace.set_player_balance(caller, sell_price)
@ -89,6 +88,8 @@ minetest.register_chatcommand("mp", {
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: You will go above the maximum balance if you sell this item. Transaction cancelled.") return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: You will go above the maximum balance if you sell this item. Transaction cancelled.")
end end
player:set_wielded_item(ItemStack(""))
minetest.sound_play("x_marketplace_gold", { minetest.sound_play("x_marketplace_gold", {
object = player, object = player,
max_hear_distance = 10, max_hear_distance = 10,
@ -177,7 +178,7 @@ minetest.register_chatcommand("mp", {
if leftover_item:get_count() > 0 then if leftover_item:get_count() > 0 then
local p = table.copy(player:get_pos()) local p = table.copy(player:get_pos())
p.y = p.y + 1.2 p.y = p.y + 1.2
local obj = minetest.add_item(p, itemstack) local obj = minetest.add_item(p, leftover_item)
if obj then if obj then
local dir = player:get_look_dir() local dir = player:get_look_dir()
@ -224,8 +225,8 @@ minetest.register_chatcommand("mp", {
local inv = player:get_inventory("main") local inv = player:get_inventory("main")
local itemstack = ItemStack(params[2]) local itemstack = ItemStack(params[2])
local balance = x_marketplace.get_player_balance(caller) local balance = x_marketplace.get_player_balance(caller)
local new_balance = 0
local amount = 0 local amount = 0
local over_max_balance = false
for k, v in ipairs(inv:get_list("main")) do for k, v in ipairs(inv:get_list("main")) do
if v:get_name() == params[2] then if v:get_name() == params[2] then
@ -237,19 +238,26 @@ minetest.register_chatcommand("mp", {
amount = amount + amount_to_remove amount = amount + amount_to_remove
if balance + amount * store_item.sell > x_marketplace.max_balance then if (balance + amount * store_item.sell) > x_marketplace.max_balance then
amount = amount - amount_to_remove amount = amount - amount_to_remove
minetest.chat_send_player(caller, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: We couldn't buy all your items without going above your maximum balance.")) over_max_balance = true
break break
else else
new_balance = balance + amount * store_item.sell
inv:remove_item("main", v) inv:remove_item("main", v)
end end
end end
end end
local sell_price = amount * store_item.sell local sell_price = amount * store_item.sell
new_balance, msg = x_marketplace.set_player_balance(caller, sell_price) local new_balance = x_marketplace.set_player_balance(caller, sell_price)
if amount == 0 then
return false, minetest.chat_send_player(caller, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: We couldn't buy all your items without going above your maximum balance."))
end
if over_max_balance then
minetest.chat_send_player(caller, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: We couldn't buy all your items without going above your maximum balance."))
end
minetest.sound_play("x_marketplace_gold", { minetest.sound_play("x_marketplace_gold", {
object = player, object = player,
@ -257,7 +265,7 @@ minetest.register_chatcommand("mp", {
gain = 1.0 gain = 1.0
}) })
return true, minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: You sold "..amount.." item(s) of "..params[2].." for "..sell_price.." BitGold. Your new balance is: "..new_balance.." BitGold") return true, minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: You sold "..amount.." item(s) of "..params[2].." for "..sell_price.." BitGold. Your new balance is: "..x_marketplace.get_player_balance(caller).." BitGold")
else else
-- item does not exists in the store -- item does not exists in the store
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: 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() return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: 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()
@ -392,7 +400,7 @@ minetest.register_chatcommand("mp", {
if leftover_item:get_count() > 0 then if leftover_item:get_count() > 0 then
local p = table.copy(player:get_pos()) local p = table.copy(player:get_pos())
p.y = p.y + 1.2 p.y = p.y + 1.2
local obj = minetest.add_item(p, itemstack) local obj = minetest.add_item(p, leftover_item)
if obj then if obj then
local dir = player:get_look_dir() local dir = player:get_look_dir()