mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2025-01-08 22:37:36 +01:00
vendor upgrade system with old shops
This commit is contained in:
parent
f2f9cf9fc7
commit
c2b42ae51b
122
fancyshop.lua
122
fancyshop.lua
@ -27,6 +27,8 @@ local settings = minetest.settings
|
|||||||
|
|
||||||
local shopcraft = core.settings:get_bool("emeraldbank.shop_craft") or true
|
local shopcraft = core.settings:get_bool("emeraldbank.shop_craft") or true
|
||||||
|
|
||||||
|
local formspec_prefix = "emeraldbank:shop_formspec"
|
||||||
|
|
||||||
local display_node = (settings:get("fancy_vend.display_node") or "mcl_core:glass")
|
local display_node = (settings:get("fancy_vend.display_node") or "mcl_core:glass")
|
||||||
local max_logs = (tonumber(settings:get("fancy_vend.log_max")) or 40)
|
local max_logs = (tonumber(settings:get("fancy_vend.log_max")) or 40)
|
||||||
local autorotate_speed = (tonumber(settings:get("fancy_vend.autorotate_speed")) or 1)
|
local autorotate_speed = (tonumber(settings:get("fancy_vend.autorotate_speed")) or 1)
|
||||||
@ -1602,7 +1604,7 @@ minetest.register_craft({
|
|||||||
-- Vendor Upgrade System --
|
-- Vendor Upgrade System --
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
local old_vendor_mods = string.split((minetest.setting_get("fancy_vend_old_vendor_mods") or ""), ",")
|
local old_vendor_mods = string.split((minetest.setting_get("fancy_vend_old_vendor_mods") or "emeraldbank"), ",")
|
||||||
local old_vendor_mods_table = {}
|
local old_vendor_mods_table = {}
|
||||||
|
|
||||||
for i in pairs(old_vendor_mods) do
|
for i in pairs(old_vendor_mods) do
|
||||||
@ -1621,70 +1623,86 @@ local base_upgrade_template = {
|
|||||||
sounds = mcl_sounds.node_sound_wood_defaults(),
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
||||||
drop = drop_vendor,
|
drop = drop_vendor,
|
||||||
tiles = {
|
tiles = {
|
||||||
"player_vend.png", "player_vend.png",
|
"player_vend.png^mcl_core_emerald.png",
|
||||||
"player_vend.png^mcl_core_emerald.png", "player_vend.png^mcl_core_emerald.png",
|
"player_vend.png^mcl_core_emerald.png",
|
||||||
"player_vend.png^mcl_core_emerald.png", "upgrade_front.png",
|
"upgrade_front.png",
|
||||||
},
|
},
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
return ItemStack(drop_vendor.." "..itemstack:get_count())
|
return ItemStack(drop_vendor.." "..itemstack:get_count())
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||||
return count
|
return count
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local clear_craft_vendors = {}
|
local clear_craft_vendors = {}
|
||||||
|
|
||||||
if old_vendor_mods_table["emeraldbank"] then
|
if old_vendor_mods_table["emeraldbank"] then
|
||||||
emeraldbank.shop_drop = drop_vendor
|
local emeraldbank_template = table.copy(base_upgrade_template)
|
||||||
emeraldbank.shop_empty_drop = drop_vendor
|
emeraldbank_template.can_dig = function(pos, player)
|
||||||
else
|
local pname = player:get_player_name()
|
||||||
emeraldbank.shop_drop = "emeraldbank:shop"
|
local is_admin = core.check_player_privs(pname, {admin_shop=true})
|
||||||
emeraldbank.shop_empty_drop = "emeraldbank:shop"
|
local meta = core.get_meta(pos)
|
||||||
|
local owner = meta:get_string("owner")
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return inv:is_empty("stock") and (pname == owner or is_admin)
|
||||||
|
end
|
||||||
|
emeraldbank_template.on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
|
local meta = core.get_meta(pos)
|
||||||
|
local nodename = core.get_node(pos).name
|
||||||
|
local owner = meta:get_string("owner")
|
||||||
|
local pname = clicker:get_player_name()
|
||||||
|
emeraldbank.get_stonks(pos, clicker)
|
||||||
|
core.show_formspec(pname, formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker))
|
||||||
|
end
|
||||||
|
minetest.override_item("emeraldbank:shop", emeraldbank_template)
|
||||||
|
table.insert(clear_craft_vendors, "emeraldbank:shop")
|
||||||
|
minetest.override_item("emeraldbank:shop_empty", emeraldbank_template)
|
||||||
|
table.insert(clear_craft_vendors, "emeraldbank:shop_empty")
|
||||||
end
|
end
|
||||||
|
|
||||||
if old_vendor_mods_table["currency"] then
|
if old_vendor_mods_table["currency"] then
|
||||||
local currency_template = table.copy(base_upgrade_template)
|
local currency_template = table.copy(base_upgrade_template)
|
||||||
|
|
||||||
currency_template.can_dig = function(pos, player)
|
currency_template.can_dig = function(pos, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives") and (meta:get_string("owner") == player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
|
return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives") and (meta:get_string("owner") == player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
|
||||||
end
|
end
|
||||||
currency_template.on_rightclick = function(pos, node, clicker, itemstack)
|
currency_template.on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||||
if clicker:get_player_name() == meta:get_string("owner") then
|
if clicker:get_player_name() == meta:get_string("owner") then
|
||||||
minetest.show_formspec(clicker:get_player_name(),"fancy_vend:currency_shop_formspec",
|
minetest.show_formspec(clicker:get_player_name(),"fancy_vend:currency_shop_formspec",
|
||||||
"size[8,9.5]"..
|
"size[8,9.5]"..
|
||||||
"label[0,0;" .. "Customers gave:" .. "]"..
|
"label[0,0;" .. "Customers gave:" .. "]"..
|
||||||
"list["..list_name..";customers_gave;0,0.5;3,2;]"..
|
"list["..list_name..";customers_gave;0,0.5;3,2;]"..
|
||||||
"label[0,2.5;" .. "Your stock:" .. "]"..
|
"label[0,2.5;" .. "Your stock:" .. "]"..
|
||||||
"list["..list_name..";stock;0,3;3,2;]"..
|
"list["..list_name..";stock;0,3;3,2;]"..
|
||||||
"label[5,0;" .. "You want:" .. "]"..
|
"label[5,0;" .. "You want:" .. "]"..
|
||||||
"list["..list_name..";owner_wants;5,0.5;3,2;]"..
|
"list["..list_name..";owner_wants;5,0.5;3,2;]"..
|
||||||
"label[5,2.5;" .. "In exchange, you give:" .. "]"..
|
"label[5,2.5;" .. "In exchange, you give:" .. "]"..
|
||||||
"list["..list_name..";owner_gives;5,3;3,2;]"..
|
"list["..list_name..";owner_gives;5,3;3,2;]"..
|
||||||
"list[current_player;main;0,5.5;8,4;]"
|
"list[current_player;main;0,5.5;8,4;]"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node(":currency:shop", currency_template)
|
minetest.register_node(":currency:shop", currency_template)
|
||||||
|
|
||||||
table.insert(clear_craft_vendors, "currency:shop")
|
table.insert(clear_craft_vendors, "currency:shop")
|
||||||
end
|
end
|
||||||
|
|
||||||
if old_vendor_mods_table["easyvend"] then
|
if old_vendor_mods_table["easyvend"] then
|
||||||
|
Loading…
Reference in New Issue
Block a user