fixes for NaN and negative numbers

master
Juraj Vajda 2018-11-06 10:24:01 -05:00
parent c2a9489666
commit 622113238c
1 changed files with 23 additions and 3 deletions

View File

@ -48,7 +48,7 @@ minetest.register_chatcommand("mp", {
local itemstack = ItemStack({ name = item_name })
-- check what is the max items we can sell
if item_count > (itemstack:get_stack_max()) then
if item_count > itemstack:get_stack_max() then
return false, "You can sell this item by max. of "..itemstack:get_stack_max().." item(s) at the time."
end
@ -110,10 +110,20 @@ minetest.register_chatcommand("mp", {
end
-- check what is the max items we can buy
if tonumber(amount) > (itemstack:get_stack_max()) then
if tonumber(amount) > itemstack:get_stack_max() then
return false, "You can buy this item by max. of "..itemstack:get_stack_max().." item(s) at the time."
end
-- check amount is positive number
if tonumber(amount) <= 0 then
amount = 1
end
-- check for NaN, returns true if given value is not a number (NaN)
if (amount ~= amount) then
return false
end
local buy_price = amount * store_item.buy
local new_balance = x_marketplace.set_player_balance(caller, buy_price * -1)
@ -275,10 +285,20 @@ minetest.register_chatcommand("mp", {
end
-- check what is the max items we can buy
if tonumber(amount) > (itemstack:get_stack_max()) then
if tonumber(amount) > itemstack:get_stack_max() then
return false, "You can buy this item by max. of "..itemstack:get_stack_max().." item(s) at the time."
end
-- check amount is positive number
if tonumber(amount) <= 0 then
amount = 1
end
-- check for NaN, returns true if given value is not a number (NaN)
if (amount ~= amount) then
return false
end
local buy_price = amount * store_item.buy
local new_balance = x_marketplace.set_player_balance(caller, buy_price * -1)