un timer recauda el dinero de las tiendas si el jugador esta online

This commit is contained in:
GNU Hacker 2021-12-16 19:41:21 +01:00
parent 3d21c146b1
commit e8189b3641

@ -23,6 +23,8 @@ local S = core.get_translator(core.get_current_modname())
local shopcraft = core.settings:get_bool("emeraldbank.shop_craft") or true local shopcraft = core.settings:get_bool("emeraldbank.shop_craft") or true
local shop_timer = 5
local stock_h = 3 local stock_h = 3
local stock_w = 5 local stock_w = 5
@ -126,6 +128,7 @@ core.register_node("emeraldbank:shop", {
local meta = core.get_meta(pos) local meta = core.get_meta(pos)
meta:set_string("infotext", S("Exchange shop (owned by @1)", owner)) meta:set_string("infotext", S("Exchange shop (owned by @1)", owner))
meta:set_string("owner", owner) meta:set_string("owner", owner)
core.get_node_timer(pos):start(shop_timer)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("stock", stock_w*stock_h) inv:set_size("stock", stock_w*stock_h)
end, end,
@ -144,6 +147,18 @@ core.register_node("emeraldbank:shop", {
on_metadata_inventory_take = check_empty, on_metadata_inventory_take = check_empty,
on_timer = function(pos, elapsed)
local meta = core.get_meta(pos)
local owner = meta:get_string("owner")
local is_online = core.player_exists(owner)
if is_online then
local player = core.get_player_by_name(owner)
if not player or player.is_fake_player then return end
get_stonks(pos, player)
end
core.get_node_timer(pos):start(shop_timer)
end,
can_dig = function(pos, player) can_dig = function(pos, player)
local pname = player:get_player_name() local pname = player:get_player_name()
local is_admin = core.check_player_privs(pname, {server=true}) local is_admin = core.check_player_privs(pname, {server=true})
@ -177,6 +192,9 @@ core.register_on_player_receive_fields(function(sender, formname, fields)
local pinv = sender:get_inventory() local pinv = sender:get_inventory()
local bankemeralds = playermeta:get_int("emeraldbank:emerald") local bankemeralds = playermeta:get_int("emeraldbank:emerald")
-- set or reset timer
core.get_node_timer(pos):start(shop_timer)
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)