mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-23 06:32:25 +01:00
dont trade air / exchange fields comments
This commit is contained in:
parent
1b19afc799
commit
a08c989040
16
shop.lua
16
shop.lua
@ -278,6 +278,7 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
-- set or reset timer
|
||||
core.get_node_timer(pos):start(shop_timer)
|
||||
|
||||
-- set item count
|
||||
if fields.count and string.find(fields.count, "^[0-9]+$") then
|
||||
if new_count >= 1 and new_count <= 64 and new_count ~= meta:get_int("count") then
|
||||
meta:set_int("count", new_count)
|
||||
@ -285,31 +286,40 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
end
|
||||
end
|
||||
|
||||
-- set price
|
||||
if fields.price and string.find(fields.price, "^[0-9]+$") then
|
||||
if new_price >= 1 and new_price <= 10000 and new_price ~= meta:get_int("price") then
|
||||
meta:set_int("price", new_price)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- someone hit exchange button
|
||||
if fields.exchange ~= nil and fields.exchange ~= "" then
|
||||
|
||||
-- owner try exchanges
|
||||
if meta:get_string("owner") == name then
|
||||
|
||||
core.chat_send_player(name, S("This is your own shop, you can't exchange to yourself!"))
|
||||
|
||||
else
|
||||
|
||||
local can_exchange = true
|
||||
|
||||
-- have u money?
|
||||
if bankemeralds < old_price then
|
||||
can_exchange = false
|
||||
core.chat_send_player(name, S("Not enough Emeralds in your account") )
|
||||
end
|
||||
|
||||
|
||||
--there are enough items?
|
||||
if not minv:contains_item("stock", shop_item.." "..old_count, true) then
|
||||
can_exchange = false
|
||||
core.chat_send_player(name, S("Out of Stock!") )
|
||||
end
|
||||
|
||||
-- do not trade air
|
||||
if shop_item == "" or shop_item == "air" then
|
||||
can_exchange = false
|
||||
end
|
||||
|
||||
if can_exchange then
|
||||
minv:remove_item("stock", shop_item.." "..old_count)
|
||||
|
Loading…
Reference in New Issue
Block a user