mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-23 06:32:25 +01:00
func get_stonks(pos) improved
This commit is contained in:
parent
e96994bd98
commit
beb1cbb50a
@ -1292,6 +1292,7 @@ local vendor_template = {
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
core.get_node_timer(pos):start(shop_timer)
|
||||
emeraldbank.get_stonks(pos)
|
||||
end,
|
||||
on_dig = function(pos, node, digger)
|
||||
-- Set variables for access later (for various checks, etc.)
|
||||
@ -1651,19 +1652,12 @@ if old_vendor_mods_table["emeraldbank"] then
|
||||
local owner = meta:get_string("owner")
|
||||
local pname = clicker:get_player_name()
|
||||
core.get_node_timer(pos):start(shop_timer)
|
||||
emeraldbank.get_stonks(pos, clicker)
|
||||
emeraldbank.get_stonks(pos)
|
||||
core.show_formspec(pname, formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker))
|
||||
end
|
||||
emeraldbank_template.on_timer = function(pos, elapsed)
|
||||
local meta = core.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local is_online = core.player_exists(owner)
|
||||
core.get_node_timer(pos):start(shop_timer)
|
||||
if is_online then
|
||||
local player = core.get_player_by_name(owner)
|
||||
if not player or player.is_fake_player then return end
|
||||
emeraldbank.get_stonks(pos, player)
|
||||
end
|
||||
emeraldbank.get_stonks(pos)
|
||||
end
|
||||
minetest.override_item("emeraldbank:shop", emeraldbank_template)
|
||||
table.insert(clear_craft_vendors, "emeraldbank:shop")
|
||||
|
@ -99,6 +99,26 @@ function emeraldbank.add_emeralds(player, num)
|
||||
return false
|
||||
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)
|
||||
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)
|
||||
meta:set_int("stonks", 0)
|
||||
core.chat_send_player(owner, S("You've earned @1 Emeralds with your shops.", stonks))
|
||||
end
|
||||
end
|
||||
|
||||
function emeraldbank.transfer_emeralds(player1, player2, num)
|
||||
atm.readaccounts()
|
||||
local name = player1:get_player_name()
|
||||
|
33
shop.lua
33
shop.lua
@ -119,24 +119,6 @@ local function check_empty(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function emeraldbank.get_stonks(pos, player)
|
||||
local name = player:get_player_name()
|
||||
local meta = core.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local stonks = meta:get_int("stonks")
|
||||
if name == owner and stonks > 0 then
|
||||
core.sound_play("cash", {
|
||||
to_player = name,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
emeraldbank.add_emeralds(player, stonks)
|
||||
meta:set_int("stonks", 0)
|
||||
core.chat_send_player(name, S("You've earned @1 Emeralds with your shops.", stonks) )
|
||||
end
|
||||
end
|
||||
|
||||
local function after_place_node(pos, placer, itemstack)
|
||||
local owner = placer:get_player_name()
|
||||
local meta = core.get_meta(pos)
|
||||
@ -154,14 +136,14 @@ local function on_rightclick(pos, node, clicker, itemstack)
|
||||
local nodename = core.get_node(pos).name
|
||||
local owner = meta:get_string("owner")
|
||||
local pname = clicker:get_player_name()
|
||||
emeraldbank.get_stonks(pos, clicker)
|
||||
emeraldbank.get_stonks(pos)
|
||||
--if nodename == "emeraldbank:shop" or pname == owner then
|
||||
core.show_formspec(pname, formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker) )
|
||||
core.show_formspec(pname, formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker))
|
||||
--end
|
||||
end
|
||||
|
||||
local function on_punch(pos, node, puncher, pointed_thing)
|
||||
emeraldbank.get_stonks(pos, puncher)
|
||||
emeraldbank.get_stonks(pos)
|
||||
end
|
||||
|
||||
local function on_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
@ -181,16 +163,9 @@ end
|
||||
|
||||
|
||||
local function on_timer(pos, elapsed)
|
||||
local meta = core.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local is_online = core.player_exists(owner)
|
||||
core.get_node_timer(pos):start(shop_timer)
|
||||
check_empty(pos)
|
||||
if is_online then
|
||||
local player = core.get_player_by_name(owner)
|
||||
if not player or player.is_fake_player then return end
|
||||
emeraldbank.get_stonks(pos, player)
|
||||
end
|
||||
emeraldbank.get_stonks(pos)
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
|
Loading…
Reference in New Issue
Block a user