Minor changes
1
depends.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
default
|
7
init.lua
@ -1,13 +1,10 @@
|
|||||||
if not minetest.get_translator then
|
|
||||||
error("exchange_shop requires at least Minetest 5.0.0-dev.")
|
|
||||||
end
|
|
||||||
|
|
||||||
exchange_shop = {}
|
exchange_shop = {}
|
||||||
exchange_shop.storage_size = 5 * 4
|
exchange_shop.storage_size = 5 * 4
|
||||||
exchange_shop.shopname = "exchange_shop:shop"
|
exchange_shop.shopname = "exchange_shop:shop"
|
||||||
|
|
||||||
-- Internationalisaton
|
-- Internationalisaton
|
||||||
exchange_shop.S = minetest.get_translator("exchange_shop")
|
--exchange_shop.S = minetest.get_translator("exchange_shop")
|
||||||
|
exchange_shop.S = intllib.make_gettext_pair()
|
||||||
exchange_shop.FS = function(...)
|
exchange_shop.FS = function(...)
|
||||||
return minetest.formspec_escape(exchange_shop.S(...))
|
return minetest.formspec_escape(exchange_shop.S(...))
|
||||||
end
|
end
|
||||||
|
17
shop.lua
@ -18,7 +18,7 @@ local function get_exchange_shop_formspec(mode, pos, meta)
|
|||||||
"listring[current_player;main]"
|
"listring[current_player;main]"
|
||||||
end
|
end
|
||||||
local function make_slots(x, y, list, label)
|
local function make_slots(x, y, list, label)
|
||||||
local arrow = "exchange_shop_arrow.png"
|
local arrow = "default_arrow_bg.png"
|
||||||
if list == "cust_ow" then
|
if list == "cust_ow" then
|
||||||
arrow = arrow .. "\\^\\[transformFY"
|
arrow = arrow .. "\\^\\[transformFY"
|
||||||
end
|
end
|
||||||
@ -79,7 +79,7 @@ local function get_exchange_shop_formspec(mode, pos, meta)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local arrow = "exchange_shop_arrow.png"
|
local arrow = "default_arrow_bg.png"
|
||||||
if mode == "owner_custm" then
|
if mode == "owner_custm" then
|
||||||
formspec = (formspec..
|
formspec = (formspec..
|
||||||
"button[7.5,0.2;2.5,0.5;view_stock;" .. FS("Income") .. "]"..
|
"button[7.5,0.2;2.5,0.5;view_stock;" .. FS("Income") .. "]"..
|
||||||
@ -261,16 +261,3 @@ minetest.register_craft({
|
|||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
shop_positions[player:get_player_name()] = nil
|
shop_positions[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if minetest.get_modpath("wrench") and wrench then
|
|
||||||
local STRING = wrench.META_TYPE_STRING
|
|
||||||
wrench:register_node("exchange_shop:shop", {
|
|
||||||
lists = {"stock", "custm", "custm_ej", "cust_ow", "cust_og", "cust_ej"},
|
|
||||||
metas = {
|
|
||||||
owner = STRING,
|
|
||||||
infotext = STRING,
|
|
||||||
title = STRING,
|
|
||||||
},
|
|
||||||
owned = true
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
@ -20,7 +20,7 @@ function exchange_shop.list_contains_item(inv, listname, stack)
|
|||||||
local list = inv:get_list(listname)
|
local list = inv:get_list(listname)
|
||||||
local name = stack:get_name()
|
local name = stack:get_name()
|
||||||
local wear = stack:get_wear()
|
local wear = stack:get_wear()
|
||||||
for _, list_stack in pairs(list) do
|
for _, list_stack in ipairs(list) do
|
||||||
if list_stack:get_name() == name and
|
if list_stack:get_name() == name and
|
||||||
list_stack:get_wear() <= wear then
|
list_stack:get_wear() <= wear then
|
||||||
if list_stack:get_count() >= count then
|
if list_stack:get_count() >= count then
|
||||||
@ -45,7 +45,7 @@ function exchange_shop.list_remove_item(inv, listname, stack)
|
|||||||
local remaining = wanted
|
local remaining = wanted
|
||||||
local removed_wear = 0
|
local removed_wear = 0
|
||||||
|
|
||||||
for index, list_stack in pairs(list) do
|
for index, list_stack in ipairs(list) do
|
||||||
if list_stack:get_name() == name and
|
if list_stack:get_name() == name and
|
||||||
list_stack:get_wear() <= wear then
|
list_stack:get_wear() <= wear then
|
||||||
local taken_stack = list_stack:take_item(remaining)
|
local taken_stack = list_stack:take_item(remaining)
|
||||||
@ -76,35 +76,35 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
local owner_gives = shop_inv:get_list("cust_og")
|
local owner_gives = shop_inv:get_list("cust_og")
|
||||||
|
|
||||||
-- Check validness of stack "owner wants"
|
-- Check validness of stack "owner wants"
|
||||||
for i1, item1 in pairs(owner_wants) do
|
for i1, item1 in ipairs(owner_wants) do
|
||||||
local name1 = item1:get_name()
|
local name1 = item1:get_name()
|
||||||
for i2, item2 in pairs(owner_wants) do
|
for i2, item2 in ipairs(owner_wants) do
|
||||||
if name1 == "" then
|
if name1 == "" then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if i1 ~= i2 and name1 == item2:get_name() then
|
if i1 ~= i2 and name1 == item2:get_name() then
|
||||||
return S("The field '@1' can not contain multiple times the same items.", S("You need")) .. " " ..
|
return S("The field '@1' can not contain multiple times the same items.",
|
||||||
S("Please contact the shop owner.")
|
S("You need")) .. " " .. S("Please contact the shop owner.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check validness of stack "owner gives"
|
-- Check validness of stack "owner gives"
|
||||||
for i1, item1 in pairs(owner_gives) do
|
for i1, item1 in ipairs(owner_gives) do
|
||||||
local name1 = item1:get_name()
|
local name1 = item1:get_name()
|
||||||
for i2, item2 in pairs(owner_gives) do
|
for i2, item2 in ipairs(owner_gives) do
|
||||||
if name1 == "" then
|
if name1 == "" then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
if i1 ~= i2 and name1 == item2:get_name() then
|
if i1 ~= i2 and name1 == item2:get_name() then
|
||||||
return S("The field '@1' can not contain multiple times the same items.", S("You give")) .. " " ..
|
return S("The field '@1' can not contain multiple times the same items.",
|
||||||
S("Please contact the shop owner.")
|
S("You give")) .. " " .. S("Please contact the shop owner.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for space in the shop
|
-- Check for space in the shop
|
||||||
for i, item in pairs(owner_wants) do
|
for _, item in ipairs(owner_wants) do
|
||||||
if not shop_inv:room_for_item("custm", item) then
|
if not shop_inv:room_for_item("custm", item) then
|
||||||
return S("The stock in this shop is full.") .. " " ..
|
return S("The stock in this shop is full.") .. " " ..
|
||||||
S("Please contact the shop owner.")
|
S("Please contact the shop owner.")
|
||||||
@ -114,21 +114,21 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
local list_contains_item = exchange_shop.list_contains_item
|
local list_contains_item = exchange_shop.list_contains_item
|
||||||
|
|
||||||
-- Check availability of the shop's items
|
-- Check availability of the shop's items
|
||||||
for i, item in pairs(owner_gives) do
|
for _, item in ipairs(owner_gives) do
|
||||||
if not list_contains_item(shop_inv, "stock", item) then
|
if not list_contains_item(shop_inv, "stock", item) then
|
||||||
return S("This shop is sold out.")
|
return S("This shop is sold out.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for space in the player's inventory
|
-- Check for space in the player's inventory
|
||||||
for i, item in pairs(owner_gives) do
|
for _, item in ipairs(owner_gives) do
|
||||||
if not player_inv:room_for_item("main", item) then
|
if not player_inv:room_for_item("main", item) then
|
||||||
return S("You do not have enough space in your inventory.")
|
return S("You do not have enough space in your inventory.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check availability of the player's items
|
-- Check availability of the player's items
|
||||||
for i, item in pairs(owner_wants) do
|
for _, item in ipairs(owner_wants) do
|
||||||
if not list_contains_item(player_inv, "main", item) then
|
if not list_contains_item(player_inv, "main", item) then
|
||||||
return S("You do not have the required items.")
|
return S("You do not have the required items.")
|
||||||
end
|
end
|
||||||
@ -138,7 +138,7 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
|
|
||||||
-- Conditions are ok: (try to) exchange now
|
-- Conditions are ok: (try to) exchange now
|
||||||
local fully_exchanged = true
|
local fully_exchanged = true
|
||||||
for i, item in pairs(owner_wants) do
|
for _, item in ipairs(owner_wants) do
|
||||||
local stack = list_remove_item(player_inv, "main", item)
|
local stack = list_remove_item(player_inv, "main", item)
|
||||||
if shop_inv:room_for_item("custm", stack) then
|
if shop_inv:room_for_item("custm", stack) then
|
||||||
shop_inv:add_item("custm", stack)
|
shop_inv:add_item("custm", stack)
|
||||||
@ -148,7 +148,7 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
fully_exchanged = false
|
fully_exchanged = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i, item in pairs(owner_gives) do
|
for _, item in ipairs(owner_gives) do
|
||||||
local stack = list_remove_item(shop_inv, "stock", item)
|
local stack = list_remove_item(shop_inv, "stock", item)
|
||||||
if player_inv:room_for_item("main", stack) then
|
if player_inv:room_for_item("main", stack) then
|
||||||
player_inv:add_item("main", stack)
|
player_inv:add_item("main", stack)
|
||||||
|
Before Width: | Height: | Size: 438 B |
Before Width: | Height: | Size: 738 B After Width: | Height: | Size: 726 B |
Before Width: | Height: | Size: 672 B After Width: | Height: | Size: 422 B |
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 493 B |