shops: get stonks meta if player offline

This commit is contained in:
Freeman
2025-01-25 12:00:22 +01:00
parent 05dfef5153
commit d53b14ad13

View File

@ -163,7 +163,7 @@ end
-- Shops API
function emeraldbank.inv_emeralds_to_stonks(pos)
local function inv_emeralds_to_stonks(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local stonks = meta:get_int("stonks")
@ -173,7 +173,7 @@ function emeraldbank.inv_emeralds_to_stonks(pos)
if has_emerald then
meta:set_int("stonks", stonks+1)
inv:remove_item("main", "mcl_core:emerald 1")
emeraldbank.inv_emeralds_to_stonks(pos)
inv_emeralds_to_stonks(pos)
return true
else
return false
@ -183,20 +183,22 @@ end
function emeraldbank.get_stonks(pos)
local meta = core.get_meta(pos)
local owner = meta:get_string("owner")
local player = core.get_player_by_name(owner)
local is_online = core.player_exists(owner)
emeraldbank.inv_emeralds_to_stonks(pos)
inv_emeralds_to_stonks(pos)
local stonks = meta:get_int("stonks")
if not player or player.is_fake_player then return end
if is_online and stonks > 0 then
core.sound_play("cash", {
to_player = owner,
gain = 1.0,
fade = 0.0,
pitch = 1.0,
})
emeraldbank.add_emeralds(player, stonks)
if stonks > 0 then
-- keep stonks in bank account
emeraldbank.add_emeralds(owner, stonks)
meta:set_int("stonks", 0)
core.chat_send_player(owner, S("You've earned @1 Emeralds with your shops.", stonks))
-- only if players is online send notification
if is_online then
core.sound_play("cash", {
to_player = owner,
gain = 1.0,
fade = 0.0,
pitch = 1.0,
})
core.chat_send_player(owner, S("You've earned @1 Emeralds with your shops.", stonks))
end
end
end