sounds, textures, head item, loosing balance when player dies
parent
2d02264662
commit
7f2c3b059d
145
api.lua
145
api.lua
|
@ -1,3 +1,34 @@
|
|||
--- Returns true if given value is a finite number; otherwise false or nil if value is not of type string nor number.
|
||||
function x_marketplace.isfinite(value)
|
||||
if type(value) == "string" then
|
||||
value = tonumber(value)
|
||||
if value == nil then return nil end
|
||||
elseif type(value) ~= "number" then
|
||||
return nil
|
||||
end
|
||||
return value > -math.huge and value < math.huge
|
||||
end
|
||||
|
||||
--- Returns true if given value is not a number (NaN); otherwise false or nil if value is not of type string nor number.
|
||||
function x_marketplace.isnan(value)
|
||||
if type(value) == "string" then
|
||||
value = tonumber(value)
|
||||
if value == nil then return nil end
|
||||
elseif type(value) ~= "number" then
|
||||
return nil
|
||||
end
|
||||
return value ~= value
|
||||
end
|
||||
|
||||
-- rounds a number to the nearest decimal places
|
||||
local function round(val, decimal)
|
||||
if (decimal) then
|
||||
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
|
||||
else
|
||||
return math.floor(val+0.5)
|
||||
end
|
||||
end
|
||||
|
||||
-- Search items in marketplace object
|
||||
-- @param string the string
|
||||
-- @return string with found items, if no items found returns boolean false
|
||||
|
@ -72,3 +103,117 @@ function x_marketplace.set_player_balance(name, amount)
|
|||
|
||||
return new_balance
|
||||
end
|
||||
|
||||
function x_marketplace.find_signs(player_pos, text)
|
||||
local pos0 = vector.subtract(player_pos, 2)
|
||||
local pos1 = vector.add(player_pos, 2)
|
||||
local positions = minetest.find_nodes_in_area(pos0, pos1, "default:sign_wall_steel")
|
||||
local found = false
|
||||
|
||||
if #positions <= 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
for k, v in pairs(positions) do
|
||||
local sign_meta = minetest.get_meta(v)
|
||||
local sign_text = sign_meta:get_string("text"):trim()
|
||||
|
||||
if sign_text == text then
|
||||
print("sign_text", sign_text)
|
||||
print("text", text)
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return found
|
||||
end
|
||||
|
||||
minetest.register_craftitem("x_marketplace:head", {
|
||||
description = "head",
|
||||
inventory_image = "x_marketplace_head-front.png",
|
||||
wield_image = "x_marketplace_head-front.png",
|
||||
stack_max = 1,
|
||||
wield_scale = {x=1.5, y=1.5, z=6},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
||||
minetest.chat_send_player(user:get_player_name(), minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: If you want to sell the head, you have to punch steel sign with text '/mp sellhead' on it."))
|
||||
|
||||
if pointed_thing.type == "node" then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
|
||||
if node.name == "default:sign_wall_steel" then
|
||||
local node_meta = minetest.get_meta(pointed_thing.under)
|
||||
|
||||
if node_meta:get_string("text"):trim() == "/mp sellhead" then
|
||||
local stack_meta = itemstack:to_table().meta
|
||||
local stack_meta_value = tonumber(stack_meta.value)
|
||||
local stack_meta_owner = stack_meta.owner
|
||||
|
||||
-- sell item
|
||||
local new_balance = x_marketplace.set_player_balance(user:get_player_name(), stack_meta_value)
|
||||
|
||||
if new_balance then
|
||||
minetest.sound_play("x_marketplace_gold", {
|
||||
object = user,
|
||||
max_hear_distance = 10,
|
||||
gain = 1.0
|
||||
})
|
||||
|
||||
minetest.chat_send_player(user:get_player_name(), minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: You sold "..stack_meta_owner.." head for "..stack_meta_value.." BitGold. Your new balance is: "..new_balance.." BitGold"))
|
||||
|
||||
itemstack:take_item()
|
||||
else
|
||||
minetest.chat_send_player(user:get_player_name(), minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: You will go above the maximum balance if you sell this item. Transaction cancelled."))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
local balance = tonumber(x_marketplace.get_player_balance(player_name))
|
||||
local lost_value, new_balance
|
||||
|
||||
if balance then
|
||||
-- no money, nothing to loose
|
||||
if balance == 0 then
|
||||
return
|
||||
-- almost no money, drop everything
|
||||
elseif balance <= 10 then
|
||||
lost_value = balance
|
||||
-- loose between 5-10% from balance
|
||||
else
|
||||
lost_value = (balance / 100) * math.random(5, 10)
|
||||
end
|
||||
|
||||
lost_value = round(lost_value, 2)
|
||||
|
||||
new_balance = x_marketplace.set_player_balance(player_name, lost_value * -1)
|
||||
|
||||
local pos = vector.round(player:getpos())
|
||||
local itemstack = ItemStack("x_marketplace:head")
|
||||
local meta = itemstack:get_meta()
|
||||
local item_description = minetest.registered_items["x_marketplace:head"]["description"]
|
||||
|
||||
meta:set_string("owner", player_name)
|
||||
meta:set_string("value", lost_value)
|
||||
meta:set_string("description", player_name.." "..item_description.."\nvalue: "..lost_value.." BitGold")
|
||||
|
||||
local obj = minetest.add_item(pos, itemstack)
|
||||
if obj then
|
||||
obj:set_velocity({
|
||||
x = math.random(-10, 10) / 9,
|
||||
y = 5,
|
||||
z = math.random(-10, 10) / 9,
|
||||
})
|
||||
end
|
||||
|
||||
minetest.chat_send_player(player_name, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: When you died you lost "..lost_value.." BitGold"))
|
||||
end
|
||||
end)
|
||||
|
|
184
chatcommands.lua
184
chatcommands.lua
|
@ -1,32 +1,3 @@
|
|||
--- Returns true if given value is a finite number; otherwise false or nil if value is not of type string nor number.
|
||||
function isfinite(value)
|
||||
if type(value) == "string" then
|
||||
value = tonumber(value)
|
||||
if value == nil then return nil end
|
||||
elseif type(value) ~= "number" then
|
||||
return nil
|
||||
end
|
||||
return value > -math.huge and value < math.huge
|
||||
end
|
||||
|
||||
--- Returns true if given value is not a number (NaN); otherwise false or nil if value is not of type string nor number.
|
||||
function isnan(value)
|
||||
if type(value) == "string" then
|
||||
value = tonumber(value)
|
||||
if value == nil then return nil end
|
||||
elseif type(value) ~= "number" then
|
||||
return nil
|
||||
end
|
||||
return value ~= value
|
||||
end
|
||||
|
||||
local colors = {
|
||||
["yellow"] = "#FFEB3B", -- info
|
||||
["green"] = "#4CAF50", -- success
|
||||
["red"] = "#f44336", -- error
|
||||
["cyan"] = "#00BCD4" -- terminal info
|
||||
}
|
||||
|
||||
--- Minetest API method. Adds definition to minetest.registered_chatcommands.
|
||||
-- @param cmd the string - commnad name
|
||||
-- @param chatcommand definition the table
|
||||
|
@ -48,16 +19,16 @@ minetest.register_chatcommand("mp", {
|
|||
if params[1] == "find" then
|
||||
-- item name is missing from param[2]
|
||||
if not params[2] then
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: You need to write the item name you want to find. example: /mp find default:stone. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: You need to write the item name you want to find. example: /mp find default:stone. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
local items = x_marketplace.store_find(params[2])
|
||||
|
||||
if not items then
|
||||
return false, minetest.colorize(colors.yellow, "MARKET PLACE: Oops there is no item like this in the store. Check out other items in the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: Oops there is no item like this in the store. Check out other items in the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
return true, minetest.colorize(colors.cyan, items)
|
||||
return true, minetest.colorize(x_marketplace.colors.cyan, items)
|
||||
|
||||
--
|
||||
-- show balance
|
||||
|
@ -67,21 +38,29 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- check for number sanity, positive number
|
||||
if not balance or
|
||||
isnan(balance) or
|
||||
not isfinite(balance) then
|
||||
x_marketplace.isnan(balance) or
|
||||
not x_marketplace.isfinite(balance) then
|
||||
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
player:set_attribute("balance", 0)
|
||||
balance = 0
|
||||
end
|
||||
|
||||
return true, minetest.colorize(colors.green, "MARKET PLACE: Your balance is: "..balance.." BitGold")
|
||||
return true, minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: Your balance is: "..balance.." BitGold")
|
||||
|
||||
--
|
||||
-- sell hand
|
||||
--
|
||||
elseif params[1] == "sellhand" then
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
|
||||
local player_pos = player:get_pos()
|
||||
local find_signs = x_marketplace.find_signs(player:get_pos(), "/mp sell")
|
||||
|
||||
if not find_signs then
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: There are no steel signs around you with text '/mp sell' on them. Transaction cancelled.")
|
||||
end
|
||||
|
||||
local hand = player:get_wielded_item()
|
||||
local item_name = hand:get_name()
|
||||
local store_item = x_marketplace.store_list[item_name]
|
||||
|
@ -92,8 +71,8 @@ minetest.register_chatcommand("mp", {
|
|||
local itemstack = ItemStack(item_name)
|
||||
|
||||
-- check for number sanity, positive number
|
||||
if isnan(item_count) or
|
||||
not isfinite(item_count) then
|
||||
if x_marketplace.isnan(item_count) or
|
||||
not x_marketplace.isfinite(item_count) then
|
||||
item_count = 1
|
||||
end
|
||||
|
||||
|
@ -107,13 +86,19 @@ minetest.register_chatcommand("mp", {
|
|||
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.")
|
||||
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
|
||||
|
||||
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")
|
||||
minetest.sound_play("x_marketplace_gold", {
|
||||
object = player,
|
||||
max_hear_distance = 10,
|
||||
gain = 1.0
|
||||
})
|
||||
|
||||
return true, minetest.colorize(x_marketplace.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
|
||||
-- item does not exists in the store
|
||||
return false, minetest.colorize(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()
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -136,10 +121,10 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
local sell_price = store_item.sell * item_count
|
||||
|
||||
return true, minetest.colorize(colors.yellow, "MARKET PLACE: "..item_name.." buy: "..store_item.buy.." sell: "..store_item.sell..". You can sell the item(s) you are holding for: "..sell_price.." BitGold. example: /mp sellhand")
|
||||
return true, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: "..item_name.." buy: "..store_item.buy.." sell: "..store_item.sell..". You can sell the item(s) you are holding for: "..sell_price.." BitGold. example: /mp sellhand")
|
||||
else
|
||||
-- item does not exists in the store
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: This item is not in store. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: This item is not in store. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -147,6 +132,13 @@ minetest.register_chatcommand("mp", {
|
|||
--
|
||||
elseif params[1] == "buyhand" then
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
|
||||
local find_signs = x_marketplace.find_signs(player:get_pos(), "/mp buy")
|
||||
|
||||
if not find_signs then
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: There are no steel signs around you with text '/mp buy' on them. Transaction cancelled.")
|
||||
end
|
||||
|
||||
local hand = player:get_wielded_item()
|
||||
local item_name = hand:get_name()
|
||||
local store_item = x_marketplace.store_list[item_name]
|
||||
|
@ -159,8 +151,8 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- check for number sanity, positive number
|
||||
if not amount or
|
||||
isnan(amount) or
|
||||
not isfinite(amount) or
|
||||
x_marketplace.isnan(amount) or
|
||||
not x_marketplace.isfinite(amount) or
|
||||
amount <= 0 then
|
||||
|
||||
amount = 1
|
||||
|
@ -177,7 +169,7 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- not enough money
|
||||
if not new_balance then
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: You don't have enought BitGold. Price for "..amount.." item(s) of "..item_name.." is "..buy_price.." BitGold, but your current balance is: "..x_marketplace.get_player_balance(caller).." BitGold")
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: You don't have enought BitGold. Price for "..amount.." item(s) of "..item_name.." is "..buy_price.." BitGold, but your current balance is: "..x_marketplace.get_player_balance(caller).." BitGold")
|
||||
end
|
||||
|
||||
-- drop items what doesn't fit in the inventory
|
||||
|
@ -197,10 +189,16 @@ minetest.register_chatcommand("mp", {
|
|||
end
|
||||
end
|
||||
|
||||
return true, minetest.colorize(colors.green, "MARKET PLACE: You bought "..amount.." item(s) of "..item_name.." for "..buy_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||
minetest.sound_play("x_marketplace_gold", {
|
||||
object = player,
|
||||
max_hear_distance = 10,
|
||||
gain = 1.0
|
||||
})
|
||||
|
||||
return true, minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: You bought "..amount.." item(s) of "..item_name.." for "..buy_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||
else
|
||||
-- item does not exists in the store
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: This item is not in store. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: This item is not in store. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -209,10 +207,16 @@ minetest.register_chatcommand("mp", {
|
|||
elseif params[1] == "sellinv" then
|
||||
-- item name is missing from param[2]
|
||||
if not params[2] then
|
||||
return false, minetest.colorize(colors.yellow, "MARKET PLACE: You need to write the item name you want to sell. example: /mp sellinv default:stone. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: You need to write the item name you want to sell. example: /mp sellinv default:stone. See some suggestion from the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
local find_signs = x_marketplace.find_signs(player:get_pos(), "/mp sell")
|
||||
|
||||
if not find_signs then
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: There are no steel signs around you with text '/mp sell' on them. Transaction cancelled.")
|
||||
end
|
||||
|
||||
local store_item = x_marketplace.store_list[params[2]]
|
||||
|
||||
-- item exists in the store
|
||||
|
@ -235,7 +239,7 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
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."))
|
||||
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."))
|
||||
break
|
||||
else
|
||||
new_balance = balance + amount * store_item.sell
|
||||
|
@ -247,10 +251,16 @@ minetest.register_chatcommand("mp", {
|
|||
local sell_price = amount * store_item.sell
|
||||
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")
|
||||
minetest.sound_play("x_marketplace_gold", {
|
||||
object = player,
|
||||
max_hear_distance = 10,
|
||||
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")
|
||||
else
|
||||
-- item does not exists in the store
|
||||
return false, minetest.colorize(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()
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -259,10 +269,16 @@ minetest.register_chatcommand("mp", {
|
|||
elseif params[1] == "buyinv" then
|
||||
-- item name is missing from param[2]
|
||||
if not params[2] then
|
||||
return false, minetest.colorize(colors.yellow, "MARKET PLACE: 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()
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: 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 find_signs = x_marketplace.find_signs(player:get_pos(), "/mp buy")
|
||||
|
||||
if not find_signs then
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: There are no steel signs around you with text '/mp buy' on them. Transaction cancelled.")
|
||||
end
|
||||
|
||||
local store_item = x_marketplace.store_list[params[2]]
|
||||
|
||||
if store_item then
|
||||
|
@ -278,7 +294,7 @@ minetest.register_chatcommand("mp", {
|
|||
end
|
||||
|
||||
if amount == 0 then
|
||||
return false, minetest.colorize(colors.yellow, "MARKET PLACE: You don't have empty space in your inventory. Transaction cancelled.")
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: You don't have empty space in your inventory. Transaction cancelled.")
|
||||
end
|
||||
|
||||
local buy_price = amount * store_item.buy
|
||||
|
@ -286,7 +302,7 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- not enough money
|
||||
if not new_balance then
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: 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.")
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: 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
|
||||
|
@ -295,11 +311,17 @@ minetest.register_chatcommand("mp", {
|
|||
end
|
||||
end
|
||||
|
||||
return true, minetest.colorize(colors.green, "MARKET PLACE: You bought "..amount.." item(s) of "..params[2].." for "..buy_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||
minetest.sound_play("x_marketplace_gold", {
|
||||
object = player,
|
||||
max_hear_distance = 10,
|
||||
gain = 1.0
|
||||
})
|
||||
|
||||
return true, minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: 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, minetest.colorize(colors.red, "MARKET PLACE: This item is not in store, check out other items from the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: This item is not in store, check out other items from the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
--
|
||||
|
@ -311,7 +333,14 @@ minetest.register_chatcommand("mp", {
|
|||
-- check for param[2] - item name
|
||||
|
||||
if not params[2] then
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: You need to write the item name you want to buy. example: /mp buy default:stone 10, or check out other items in the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: You need to write the item name you want to buy. example: /mp buy default:stone 10, or check out other items in the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
local find_signs = x_marketplace.find_signs(player:get_pos(), "/mp buy")
|
||||
|
||||
if not find_signs then
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: There are no steel signs around you with text '/mp buy' on them. Transaction cancelled.")
|
||||
end
|
||||
|
||||
-- item not in store
|
||||
|
@ -320,11 +349,11 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- try suggest item from store, else show random items
|
||||
if suggestions then
|
||||
return false, minetest.colorize(colors.yellow, "MARKET PLACE: This item is not in store, check out other items from the store: \n")..suggestions
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: This item is not in store, check out other items from the store: \n")..suggestions
|
||||
|
||||
else
|
||||
-- still not found in the store - pick random
|
||||
return false, minetest.colorize(colors.yellow, "MARKET PLACE: This item is not in store, check out other items from the store: ")..x_marketplace.store_get_random()
|
||||
return false, minetest.colorize(x_marketplace.colors.yellow, "MARKET PLACE: This item is not in store, check out other items from the store: ")..x_marketplace.store_get_random()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -333,8 +362,8 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- check for number sanity, positive number
|
||||
if not amount or
|
||||
isnan(amount) or
|
||||
not isfinite(amount) or
|
||||
x_marketplace.isnan(amount) or
|
||||
not x_marketplace.isfinite(amount) or
|
||||
amount <= 0 then
|
||||
|
||||
amount = 1
|
||||
|
@ -347,7 +376,6 @@ minetest.register_chatcommand("mp", {
|
|||
itemstack:set_count(amount)
|
||||
|
||||
-- add items to main inventory
|
||||
local player = minetest.get_player_by_name(caller)
|
||||
local store_item = x_marketplace.store_list[params[2]]
|
||||
local inv = player:get_inventory("main")
|
||||
|
||||
|
@ -356,7 +384,7 @@ minetest.register_chatcommand("mp", {
|
|||
|
||||
-- not enough money
|
||||
if not new_balance then
|
||||
return false, minetest.colorize(colors.red, "MARKET PLACE: 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")
|
||||
return false, minetest.colorize(x_marketplace.colors.red, "MARKET PLACE: 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
|
||||
|
||||
-- drop items what doesn't fit in the inventory
|
||||
|
@ -376,7 +404,13 @@ minetest.register_chatcommand("mp", {
|
|||
end
|
||||
end
|
||||
|
||||
return true, minetest.colorize(colors.green, "MARKET PLACE: You bought "..amount.." item(s) of "..params[2].." for "..buy_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||
minetest.sound_play("x_marketplace_gold", {
|
||||
object = player,
|
||||
max_hear_distance = 10,
|
||||
gain = 1.0
|
||||
})
|
||||
|
||||
return true, minetest.colorize(x_marketplace.colors.green, "MARKET PLACE: You bought "..amount.." item(s) of "..params[2].." for "..buy_price.." BitGold. Your new balance is: "..new_balance.." BitGold")
|
||||
|
||||
--
|
||||
-- top 5 richest
|
||||
|
@ -405,23 +439,23 @@ minetest.register_chatcommand("mp", {
|
|||
end
|
||||
|
||||
-- print(dump(temp_tbl))
|
||||
return true, minetest.colorize(colors.yellow, msg)
|
||||
return true, minetest.colorize(x_marketplace.colors.yellow, msg)
|
||||
|
||||
--
|
||||
-- help
|
||||
--
|
||||
elseif params[1] == "help" then
|
||||
local msg =
|
||||
minetest.colorize(colors.cyan, "/mp find").." <item name>, find item in store\n"..
|
||||
minetest.colorize(colors.cyan, "/mp balance")..", show your current balance in BitGold\n"..
|
||||
minetest.colorize(colors.cyan, "/mp sellhand")..", sell item(s) currently holding in hand\n"..
|
||||
minetest.colorize(colors.cyan, "/mp buyhand").." [<amount>], buy <amount> of item(s) currently holding in hand, when <amount> is not provided then amount is 1\n"..
|
||||
minetest.colorize(colors.cyan, "/mp infohand")..", show more information about the item(s) you are currently holding in hand from the store\n"..
|
||||
minetest.colorize(colors.cyan, "/mp buy").." <item name> [<amount>], buy <amount> of <item name> from store, if <amount> is not provided then amount is 1\n"..
|
||||
minetest.colorize(colors.cyan, "/mp sellinv").." <item name>, sell all items <item name> from the 'main' inventory list\n"..
|
||||
minetest.colorize(colors.cyan, "/mp buyinv").." <item name>, buy full inventory of items <item name>, empty slots in the 'main' inventory are required\n"..
|
||||
minetest.colorize(colors.cyan, "/mp top")..", show top 5 richest players currently online\n"..
|
||||
minetest.colorize(colors.cyan, "/mp help")..", print out this help\n"
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp find").." <item name>, find item in store\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp balance")..", show your current balance in BitGold\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp sellhand")..", sell item(s) currently holding in hand, you must be near steel sign with text '/mp sell' on it\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp buyhand").." [<amount>], buy <amount> of item(s) currently holding in hand, when <amount> is not provided then amount is 1, you must be near steel sign with text '/mp buy' on it\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp infohand")..", show more information about the item(s) you are currently holding in hand from the store\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp buy").." <item name> [<amount>], buy <amount> of <item name> from store, if <amount> is not provided then amount is 1, you must be near steel sign with text '/mp buy' on it\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp sellinv").." <item name>, sell all items <item name> from the 'main' inventory list, you must be near steel sign with text '/mp sell' on it\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp buyinv").." <item name>, buy full inventory of items <item name>, empty slots in the 'main' inventory are required, you must be near steel sign with text '/mp buy' on it\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp top")..", show top 5 richest players currently online\n"..
|
||||
minetest.colorize(x_marketplace.colors.cyan, "/mp help")..", print out this help\n"
|
||||
|
||||
-- print(msg)
|
||||
return true, msg
|
||||
|
|
6
init.lua
6
init.lua
|
@ -3,6 +3,12 @@
|
|||
-- @author SaKeL
|
||||
x_marketplace = {}
|
||||
x_marketplace.max_balance = 1000000 -- one million
|
||||
x_marketplace.colors = {
|
||||
["yellow"] = "#FFEB3B", -- info
|
||||
["green"] = "#4CAF50", -- success
|
||||
["red"] = "#f44336", -- error
|
||||
["cyan"] = "#00BCD4" -- terminal info
|
||||
}
|
||||
|
||||
local path = minetest.get_modpath("x_marketplace")
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 207 B |
Loading…
Reference in New Issue