Commit 45931b87 authored by SmallJoker's avatar SmallJoker
Browse files

It needed an update - there's it.

parent 808593bf
...@@ -87,153 +87,154 @@ local function get_exchange_shop_tube_config(mode) ...@@ -87,153 +87,154 @@ local function get_exchange_shop_tube_config(mode)
end end
minetest.register_on_player_receive_fields(function(sender, formname, fields) minetest.register_on_player_receive_fields(function(sender, formname, fields)
if (formname == "bitchange:shop_formspec") then if (formname ~= "bitchange:shop_formspec") then
local player_name = sender:get_player_name() return
local pos = exchange_shop[player_name] end
local meta = minetest.get_meta(pos) local player_name = sender:get_player_name()
local title = meta:get_string("title") or "" local pos = exchange_shop[player_name]
local shop_owner = meta:get_string("owner") local meta = minetest.get_meta(pos)
if(fields.quit) then local title = meta:get_string("title") or ""
exchange_shop[player_name] = nil local shop_owner = meta:get_string("owner")
if(fields.quit) then
exchange_shop[player_name] = nil
return
end
if(fields.set_title) then
if(fields.title and title ~= fields.title) then
if(fields.title ~= "") then
meta:set_string("infotext", "'"..fields.title.."' (owned by "..shop_owner..")")
else
meta:set_string("infotext", "Exchange shop (owned by "..shop_owner..")")
end
meta:set_string("title", fields.title)
end
end
if(fields.exchange) then
local shop_inv = meta:get_inventory()
if shop_inv:is_empty("cust_ow") and shop_inv:is_empty("cust_og") then
return return
end end
if not shop_inv:is_empty("cust_ej") or not shop_inv:is_empty("custm_ej") then
if(fields.set_title) then minetest.chat_send_player(player_name, "Exchange shop: Error, ejected items detected!")
if(fields.title and title ~= fields.title) then
if(fields.title ~= "") then
meta:set_string("infotext", "'"..fields.title.."' (owned by "..shop_owner..")")
else
meta:set_string("infotext", "Exchange shop (owned by "..shop_owner..")")
end
meta:set_string("title", fields.title)
end
end end
local player_inv = sender:get_inventory()
if(fields.exchange) then local err_msg = ""
local shop_inv = meta:get_inventory() local cust_ow = shop_inv:get_list("cust_ow")
if shop_inv:is_empty("cust_ow") and shop_inv:is_empty("cust_og") then local cust_og = shop_inv:get_list("cust_og")
return local cust_ow_legal = true
end local cust_og_legal = true
if not shop_inv:is_empty("cust_ej") or not shop_inv:is_empty("custm_ej") then --?shop configured well
minetest.chat_send_player(player_name, "Exchange shop: Error, ejected items detected!") for i1, item1 in pairs(cust_ow) do
end for i2, item2 in pairs(cust_ow) do
local player_inv = sender:get_inventory() if (item1:get_name() == item2:get_name() and i1 ~= i2 and item1:get_name() ~= "") then
local err_msg = "" cust_ow_legal = false
local cust_ow = shop_inv:get_list("cust_ow") --break
local cust_og = shop_inv:get_list("cust_og")
local cust_ow_legal = true
local cust_og_legal = true
--?shop configured well
for i1, item1 in pairs(cust_ow) do
for i2, item2 in pairs(cust_ow) do
if (item1:get_name() == item2:get_name() and i1 ~= i2 and item1:get_name() ~= "") then
cust_ow_legal = false
--break
end
end
if(not cust_ow_legal) then
break
end end
end end
if(not cust_ow_legal) then if(not cust_ow_legal) then
err_msg = "The 'Owner needs' field can not contain multiple times the same items, contact the shop owner." break
end end
if(err_msg == "") then --?shop configured well end
for i1, item1 in pairs(cust_og) do if(not cust_ow_legal) then
for i2, item2 in pairs(cust_og) do err_msg = "The 'Owner needs' field can not contain multiple times the same items, contact the shop owner."
if (item1:get_name() == item2:get_name() and i1 ~= i2 and item1:get_name() ~= "") then end
cust_og_legal = false if(err_msg == "") then --?shop configured well
break for i1, item1 in pairs(cust_og) do
end for i2, item2 in pairs(cust_og) do
end if (item1:get_name() == item2:get_name() and i1 ~= i2 and item1:get_name() ~= "") then
if(not cust_og_legal) then cust_og_legal = false
break break
end end
end end
if(not cust_og_legal) then if(not cust_og_legal) then
err_msg = "The 'Owner gives' field can not contain multiple times the same items, contact the shop owner." break
end end
end end
if(err_msg == "") then --?player has space if(not cust_og_legal) then
local player_has_space = true err_msg = "The 'Owner gives' field can not contain multiple times the same items, contact the shop owner."
for i, item in pairs(cust_og) do
if (not player_inv:room_for_item("main",item)) then
player_has_space = false
break
end
end
if(not player_has_space) then
err_msg = "You do not have the space in your inventory."
end
end end
if(err_msg == "") then --?player has items end
local player_has_items = true if(err_msg == "") then --?shop has space
for i, item in pairs(cust_ow) do local shop_has_space = true
if (not player_inv:contains_item("main",item)) then for i, item in pairs(cust_ow) do
player_has_items = false if (not shop_inv:room_for_item("custm",item)) then
break shop_has_space = false
end break
end
if(not player_has_items) then
err_msg = "You do not have the needed items."
end end
end end
if(err_msg == "") then --?shop has space if(not shop_has_space) then
local shop_has_space = true err_msg = "The stock in the shop is full."
for i, item in pairs(cust_ow) do
if (not shop_inv:room_for_item("custm",item)) then
shop_has_space = false
break
end
end
if(not shop_has_space) then
err_msg = "Exchange shop: The stock in the shop is full."
end
end end
if(err_msg == "") then --?shop has items end
local shop_has_items = true if(err_msg == "") then --?shop has items
for i, item in pairs(cust_og) do local shop_has_items = true
if (not shop_inv:contains_item("stock",item)) then for i, item in pairs(cust_og) do
shop_has_items = false if (not shop_inv:contains_item("stock",item)) then
break shop_has_items = false
end break
end end
if(not shop_has_items) then end
err_msg = "The shop is empty and can not give you anything." if(not shop_has_items) then
err_msg = "The shop is empty and can not give you anything."
end
end
if(err_msg == "") then --?player has space
local player_has_space = true
for i, item in pairs(cust_og) do
if (not player_inv:room_for_item("main",item)) then
player_has_space = false
break
end end
end end
if(err_msg == "") then --?exchange if(not player_has_space) then
local fully_exchanged = true err_msg = "You do not have the space in your inventory."
for i, item in pairs(cust_ow) do end
player_inv:remove_item("main", item) --player inv. to stock else to eject fields end
if (shop_inv:room_for_item("custm",item)) then if(err_msg == "") then --?player has items
shop_inv:add_item("custm", item) local player_has_items = true
else for i, item in pairs(cust_ow) do
shop_inv:add_item("custm_ej", item) if (not player_inv:contains_item("main",item)) then
fully_exchanged = false player_has_items = false
end break
end end
for i, item in pairs(cust_og) do end
shop_inv:remove_item("stock", item) --stock to player inv. else to eject fields if(not player_has_items) then
if (player_inv:room_for_item("main",item)) then err_msg = "You do not have the needed items."
player_inv:add_item("main", item) end
else end
shop_inv:add_item("cust_ej", item) if(err_msg == "") then --?exchange
fully_exchanged = false local fully_exchanged = true
end for i, item in pairs(cust_ow) do
player_inv:remove_item("main", item) --player inv. to stock else to eject fields
if (shop_inv:room_for_item("custm",item)) then
shop_inv:add_item("custm", item)
else
shop_inv:add_item("custm_ej", item)
fully_exchanged = false
end end
if(not fully_exchanged) then end
err_msg = "Fatal error! Stocks are overflowing somewhere!" for i, item in pairs(cust_og) do
shop_inv:remove_item("stock", item) --stock to player inv. else to eject fields
if (player_inv:room_for_item("main",item)) then
player_inv:add_item("main", item)
else
shop_inv:add_item("cust_ej", item)
fully_exchanged = false
end end
end end
if(err_msg ~= "") then if(not fully_exchanged) then
minetest.chat_send_player(player_name, "Exchange shop: "..err_msg) err_msg = "Fatal error! Stocks are overflowing somewhere!"
end end
elseif(fields.vstock and bitchange_has_access(shop_owner, player_name) and not fields.quit) then
minetest.show_formspec(sender:get_player_name(),"bitchange:shop_formspec",get_exchange_shop_formspec(3, pos, title))
elseif(fields.vcustm and bitchange_has_access(shop_owner, player_name) and not fields.quit) then
minetest.show_formspec(sender:get_player_name(),"bitchange:shop_formspec",get_exchange_shop_formspec(2, pos, title))
end end
if(err_msg ~= "") then
minetest.chat_send_player(player_name, "Exchange shop: "..err_msg)
end
elseif(fields.vstock and bitchange_has_access(shop_owner, player_name) and not fields.quit) then
minetest.show_formspec(sender:get_player_name(),"bitchange:shop_formspec",get_exchange_shop_formspec(3, pos, title))
elseif(fields.vcustm and bitchange_has_access(shop_owner, player_name) and not fields.quit) then
minetest.show_formspec(sender:get_player_name(),"bitchange:shop_formspec",get_exchange_shop_formspec(2, pos, title))
end end
end) end)
...@@ -268,7 +269,9 @@ minetest.register_node("bitchange:shop", { ...@@ -268,7 +269,9 @@ minetest.register_node("bitchange:shop", {
can_dig = function(pos,player) 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()
if(inv:is_empty("stock") and inv:is_empty("custm") and inv:is_empty("custm_ej") and inv:is_empty("cust_ow") and inv:is_empty("cust_og") and inv:is_empty("cust_ej")) then if(inv:is_empty("stock") and inv:is_empty("custm") and
inv:is_empty("custm_ej") and inv:is_empty("cust_ow") and
inv:is_empty("cust_og") and inv:is_empty("cust_ej")) then
return true return true
else else
minetest.chat_send_player(player:get_player_name(), "Can not dig exchange shop, one or multiple stocks are in use.") minetest.chat_send_player(player:get_player_name(), "Can not dig exchange shop, one or multiple stocks are in use.")
...@@ -289,16 +292,23 @@ minetest.register_node("bitchange:shop", { ...@@ -289,16 +292,23 @@ minetest.register_node("bitchange:shop", {
else else
view = 1 view = 1
end end
minetest.show_formspec(player_name,"bitchange:shop_formspec",get_exchange_shop_formspec(view, pos, meta:get_string("title"))) minetest.show_formspec(player_name, "bitchange:shop_formspec", get_exchange_shop_formspec(view, pos, meta:get_string("title")))
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 (not bitchange_has_access(meta:get_string("owner"), player:get_player_name())) then if bitchange_has_access(meta:get_string("owner"), player:get_player_name()) then
return 0 return count
end end
return count return 0
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if player:get_player_name() == ":pipeworks" then
return stack:get_count()
end
if listname == "custm" then
minetest.chat_send_player(player:get_player_name(), "Exchange shop: Please press 'Customers stock' and insert your items there.")
return 0
end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if (bitchange_has_access(meta:get_string("owner"), player:get_player_name()) and (listname ~= "cust_ej") and (listname ~= "custm_ej")) then if (bitchange_has_access(meta:get_string("owner"), player:get_player_name()) and (listname ~= "cust_ej") and (listname ~= "custm_ej")) then
return stack:get_count() return stack:get_count()
...@@ -306,6 +316,9 @@ minetest.register_node("bitchange:shop", { ...@@ -306,6 +316,9 @@ minetest.register_node("bitchange:shop", {
return 0 return 0
end, end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if player:get_player_name() == ":pipeworks" then
return stack:get_count()
end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if (bitchange_has_access(meta:get_string("owner"), player:get_player_name()) or (listname == "cust_ej")) then if (bitchange_has_access(meta:get_string("owner"), player:get_player_name()) or (listname == "cust_ej")) then
return stack:get_count() return stack:get_count()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment