check_empty func do not show formspec

This commit is contained in:
Freeman 2022-12-20 20:19:33 +01:00
parent 560cc4a7a7
commit 41fa30ee22

@ -102,7 +102,7 @@ local function set_item(pos, stack, player)
core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) ) core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) )
end end
local function check_empty(pos, player) local function check_empty(pos)
local meta = core.get_meta(pos) local meta = core.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local count = meta:get_int("count") local count = meta:get_int("count")
@ -115,7 +115,6 @@ local function check_empty(pos, player)
else else
swap_shop(pos) swap_shop(pos)
end end
core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) )
end end
local function get_stonks(pos, player) local function get_stonks(pos, player)
@ -165,15 +164,19 @@ end
local function on_metadata_inventory_put(pos, listname, index, stack, player) local function on_metadata_inventory_put(pos, listname, index, stack, player)
set_item(pos, stack, player) set_item(pos, stack, player)
check_empty(pos, player) check_empty(pos)
--core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) )
end end
local function on_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) local function on_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
check_empty(pos, player) check_empty(pos)
--core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) )
end end
local function on_metadata_inventory_take(pos, listname, index, stack, player) local function on_metadata_inventory_take(pos, listname, index, stack, player)
check_empty(pos, player) check_empty(pos)
core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) )
end end
@ -182,6 +185,7 @@ local function on_timer(pos, elapsed)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local is_online = core.player_exists(owner) local is_online = core.player_exists(owner)
core.get_node_timer(pos):start(shop_timer) core.get_node_timer(pos):start(shop_timer)
check_empty(pos)
if is_online then if is_online then
local player = core.get_player_by_name(owner) local player = core.get_player_by_name(owner)
if not player or player.is_fake_player then return end if not player or player.is_fake_player then return end
@ -279,7 +283,7 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
if fields.count and string.find(fields.count, "^[0-9]+$") then 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 if new_count >= 1 and new_count <= 64 and new_count ~= meta:get_int("count") then
meta:set_int("count", new_count) meta:set_int("count", new_count)
check_empty(pos, sender) check_empty(pos)
end end
end end
@ -315,8 +319,8 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
emeraldbank.add_emeralds(sender, -old_price) emeraldbank.add_emeralds(sender, -old_price)
meta:set_int("stonks", meta:get_int("stonks")+old_price) meta:set_int("stonks", meta:get_int("stonks")+old_price)
core.chat_send_player(name, S("Exchanged!")) core.chat_send_player(name, S("Exchanged!"))
check_empty(pos, sender) --this func already shows formspec, so I comment it bellow check_empty(pos)
--core.show_formspec(sender:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, sender) ) core.show_formspec(sender:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, sender) )
end end
end end