fixes for NaN and negative numbers
parent
c2a9489666
commit
622113238c
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue