add max balance and adjust store list
parent
fbc88fa68d
commit
2d02264662
6
api.lua
6
api.lua
|
@ -61,7 +61,11 @@ function x_marketplace.set_player_balance(name, amount)
|
||||||
local new_balance = balance + amount
|
local new_balance = balance + amount
|
||||||
|
|
||||||
if new_balance < 0 then
|
if new_balance < 0 then
|
||||||
return false
|
return false, "below"
|
||||||
|
end
|
||||||
|
|
||||||
|
if new_balance > x_marketplace.max_balance then
|
||||||
|
return false, "above"
|
||||||
end
|
end
|
||||||
|
|
||||||
player:set_attribute("balance", new_balance)
|
player:set_attribute("balance", new_balance)
|
||||||
|
|
|
@ -104,7 +104,11 @@ minetest.register_chatcommand("mp", {
|
||||||
player:set_wielded_item(ItemStack(""))
|
player:set_wielded_item(ItemStack(""))
|
||||||
|
|
||||||
local sell_price = store_item.sell * item_count
|
local sell_price = store_item.sell * item_count
|
||||||
local new_balance = x_marketplace.set_player_balance(caller, sell_price)
|
local new_balance, msg = x_marketplace.set_player_balance(caller, sell_price)
|
||||||
|
|
||||||
|
if msg == "above" then
|
||||||
|
return false, minetest.colorize(colors.yellow, "MARKET PLACE: You will go above the maximum balance if you sell this item. Transaction cancelled.")
|
||||||
|
end
|
||||||
|
|
||||||
return true, minetest.colorize(colors.green, "MARKET PLACE: You sold "..item_count.." item(s) of "..item_name.." for "..sell_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
return true, minetest.colorize(colors.green, "MARKET PLACE: You sold "..item_count.." item(s) of "..item_name.." for "..sell_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||||
else
|
else
|
||||||
|
@ -215,23 +219,33 @@ minetest.register_chatcommand("mp", {
|
||||||
if store_item then
|
if store_item then
|
||||||
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 new_balance = 0
|
||||||
local amount = 0
|
local amount = 0
|
||||||
|
|
||||||
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
|
||||||
local amount_removed = v:get_count()
|
local amount_to_remove = v:get_count()
|
||||||
inv:remove_item("main", v)
|
|
||||||
|
|
||||||
if amount_removed > itemstack:get_stack_max() then
|
if amount_to_remove > itemstack:get_stack_max() then
|
||||||
amount_removed = itemstack:get_stack_max()
|
amount_to_remove = itemstack:get_stack_max()
|
||||||
end
|
end
|
||||||
|
|
||||||
amount = amount + amount_removed
|
amount = amount + amount_to_remove
|
||||||
|
|
||||||
|
if balance + amount * store_item.sell > x_marketplace.max_balance then
|
||||||
|
amount = amount - amount_to_remove
|
||||||
|
minetest.chat_send_player(caller, minetest.colorize(colors.yellow, "MARKET PLACE: We couldn't buy all your items without going above your maximum balance."))
|
||||||
|
break
|
||||||
|
else
|
||||||
|
new_balance = balance + amount * store_item.sell
|
||||||
|
inv:remove_item("main", v)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local sell_price = amount * store_item.sell
|
local sell_price = amount * store_item.sell
|
||||||
local new_balance = x_marketplace.set_player_balance(caller, sell_price)
|
new_balance, msg = x_marketplace.set_player_balance(caller, sell_price)
|
||||||
|
|
||||||
return true, minetest.colorize(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(colors.green, "MARKET PLACE: You sold "..amount.." item(s) of "..params[2].." for "..sell_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||||
else
|
else
|
||||||
|
|
1
init.lua
1
init.lua
|
@ -2,6 +2,7 @@
|
||||||
-- @module x_marketplace
|
-- @module x_marketplace
|
||||||
-- @author SaKeL
|
-- @author SaKeL
|
||||||
x_marketplace = {}
|
x_marketplace = {}
|
||||||
|
x_marketplace.max_balance = 1000000 -- one million
|
||||||
|
|
||||||
local path = minetest.get_modpath("x_marketplace")
|
local path = minetest.get_modpath("x_marketplace")
|
||||||
|
|
||||||
|
|
|
@ -144,10 +144,10 @@ x_marketplace.store_list = {
|
||||||
-- buy = 0.00,
|
-- buy = 0.00,
|
||||||
-- sell = 0.00
|
-- sell = 0.00
|
||||||
-- },
|
-- },
|
||||||
["default:diamondblock"] = {
|
-- ["default:diamondblock"] = {
|
||||||
buy = 16200.00,
|
-- buy = 16200.00,
|
||||||
sell = 1.00
|
-- sell = 1.00
|
||||||
},
|
-- },
|
||||||
["default:dirt"] = {
|
["default:dirt"] = {
|
||||||
buy = 1.00,
|
buy = 1.00,
|
||||||
sell = 0.25
|
sell = 0.25
|
||||||
|
@ -264,10 +264,10 @@ x_marketplace.store_list = {
|
||||||
buy = 4.00,
|
buy = 4.00,
|
||||||
sell = 1.00
|
sell = 1.00
|
||||||
},
|
},
|
||||||
["default:mese"] = {
|
-- ["default:mese"] = {
|
||||||
buy = 16200.00,
|
-- buy = 16200.00,
|
||||||
sell = 1.00
|
-- sell = 1.00
|
||||||
},
|
-- },
|
||||||
["default:mese_post_light"] = {
|
["default:mese_post_light"] = {
|
||||||
buy = 128.00,
|
buy = 128.00,
|
||||||
sell = 0.25
|
sell = 0.25
|
||||||
|
@ -380,10 +380,10 @@ x_marketplace.store_list = {
|
||||||
buy = 0.80,
|
buy = 0.80,
|
||||||
sell = 0.20
|
sell = 0.20
|
||||||
},
|
},
|
||||||
["default:steelblock"] = {
|
-- ["default:steelblock"] = {
|
||||||
buy = 2430.00,
|
-- buy = 2430.00,
|
||||||
sell = 1
|
-- sell = 1
|
||||||
},
|
-- },
|
||||||
["default:stone"] = {
|
["default:stone"] = {
|
||||||
buy = 2.00,
|
buy = 2.00,
|
||||||
sell = 0.50
|
sell = 0.50
|
||||||
|
|
Loading…
Reference in New Issue