mirror of
https://github.com/SmallJoker/exchange_shop.git
synced 2025-07-04 17:20:29 +02:00
Minor changes
This commit is contained in:
@ -20,7 +20,7 @@ function exchange_shop.list_contains_item(inv, listname, stack)
|
||||
local list = inv:get_list(listname)
|
||||
local name = stack:get_name()
|
||||
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
|
||||
list_stack:get_wear() <= wear 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 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
|
||||
list_stack:get_wear() <= wear then
|
||||
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")
|
||||
|
||||
-- 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()
|
||||
for i2, item2 in pairs(owner_wants) do
|
||||
for i2, item2 in ipairs(owner_wants) do
|
||||
if name1 == "" then
|
||||
break
|
||||
end
|
||||
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")) .. " " ..
|
||||
S("Please contact the shop owner.")
|
||||
return S("The field '@1' can not contain multiple times the same items.",
|
||||
S("You need")) .. " " .. S("Please contact the shop owner.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 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()
|
||||
for i2, item2 in pairs(owner_gives) do
|
||||
for i2, item2 in ipairs(owner_gives) do
|
||||
if name1 == "" then
|
||||
break
|
||||
end
|
||||
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")) .. " " ..
|
||||
S("Please contact the shop owner.")
|
||||
return S("The field '@1' can not contain multiple times the same items.",
|
||||
S("You give")) .. " " .. S("Please contact the shop owner.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 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
|
||||
return S("The stock in this shop is full.") .. " " ..
|
||||
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
|
||||
|
||||
-- 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
|
||||
return S("This shop is sold out.")
|
||||
end
|
||||
end
|
||||
|
||||
-- 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
|
||||
return S("You do not have enough space in your inventory.")
|
||||
end
|
||||
end
|
||||
|
||||
-- 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
|
||||
return S("You do not have the required items.")
|
||||
end
|
||||
@ -138,7 +138,7 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
||||
|
||||
-- Conditions are ok: (try to) exchange now
|
||||
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)
|
||||
if shop_inv:room_for_item("custm", stack) then
|
||||
shop_inv:add_item("custm", stack)
|
||||
@ -148,7 +148,7 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
||||
fully_exchanged = false
|
||||
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)
|
||||
if player_inv:room_for_item("main", stack) then
|
||||
player_inv:add_item("main", stack)
|
||||
|
Reference in New Issue
Block a user