mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-23 14:42:27 +01:00
features
on take item remove shop_item on punch call get_stonks() can_dig defined fix owner in get_stonks()
This commit is contained in:
parent
180dbbbf34
commit
bfe60227d4
41
shop.lua
41
shop.lua
@ -77,13 +77,22 @@ local function set_item(pos, listname, index, 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 get_stonks(pos, clicker)
|
local function check_empty(pos, listname, index, stack, player)
|
||||||
local name = clicker:get_player_name()
|
|
||||||
local owner = clicker:get_player_name()
|
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
if inv:is_empty("stock") then
|
||||||
|
meta:set_string("shop_item", "")
|
||||||
|
end
|
||||||
|
core.show_formspec(player:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, player) )
|
||||||
|
end
|
||||||
|
|
||||||
|
local function 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")
|
local stonks = meta:get_int("stonks")
|
||||||
if name == owner and stonks > 0 then
|
if name == owner and stonks > 0 then
|
||||||
emeraldbank.add_emeralds(clicker, stonks)
|
emeraldbank.add_emeralds(player, stonks)
|
||||||
meta:set_int("stonks", 0)
|
meta:set_int("stonks", 0)
|
||||||
core.chat_send_player(name, S("You've earned @1 Emeralds with this shop.", stonks) )
|
core.chat_send_player(name, S("You've earned @1 Emeralds with this shop.", stonks) )
|
||||||
end
|
end
|
||||||
@ -119,24 +128,24 @@ core.register_node("emeraldbank:shop", {
|
|||||||
get_stonks(pos, clicker)
|
get_stonks(pos, clicker)
|
||||||
core.show_formspec(clicker:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker) )
|
core.show_formspec(clicker:get_player_name(), formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker) )
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
on_punch = function(pos, node, puncher, pointed_thing)
|
||||||
|
get_stonks(pos, puncher)
|
||||||
|
end,
|
||||||
|
|
||||||
on_metadata_inventory_put = set_item,
|
on_metadata_inventory_put = set_item,
|
||||||
-- on_metadata_inventory_take = set_item,
|
|
||||||
|
on_metadata_inventory_take = check_empty,
|
||||||
|
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
can_dig = function(pos, player)
|
||||||
|
local name = player:get_player_name()
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local meta2 = meta
|
local owner = meta:get_string("owner")
|
||||||
meta:from_table(oldmetadata)
|
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
for _, listname in ipairs({"stock"}) do
|
if inv:is_empty("stock") and name == owner then
|
||||||
local stack = inv:get_stack(listname, 1)
|
return true
|
||||||
if not stack:is_empty() then
|
|
||||||
local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5}
|
|
||||||
core.add_item(p, stack)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
meta:from_table(meta2:to_table())
|
end
|
||||||
end,
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user