Fix team-chest shift-click

This commit is contained in:
shivajiva101 2018-12-30 23:08:55 +00:00 committed by rubenwardy
parent 904c47dea2
commit 8b41008bc1

View file

@ -43,6 +43,7 @@ for _, chest_color in pairs(colors) do
local inv = meta:get_inventory()
inv:set_size("main", 5*4)
inv:set_size("pro", 3*4)
inv:set_size("helper", 1*1)
end,
on_rightclick = function(pos, node, player)
if chest_color ~= ctf.player(player:get_player_name()).team then
@ -90,15 +91,16 @@ for _, chest_color in pairs(colors) do
"list[" .. chestinv .. ";pro;5,0.3;3,4;]"
if is_pro then
formspec = formspec .. "listring[current_name;pro]" ..
formspec = formspec .. "listring[" .. chestinv ..";pro]" ..
"listring[" .. chestinv .. ";helper]" ..
"label[5,-0.2;" .. minetest.formspec_escape("Pro players only (1k+ score, 1.5+ KD)") .. "]"
else
formspec = formspec .. "listring[current_name;pro]" ..
formspec = formspec ..
"label[5,-0.2;" .. minetest.formspec_escape("You need 1k+ score and 1.5+ KD") .. "]"
end
formspec = formspec ..
"listring[current_name;main]" ..
"listring[" .. chestinv ..";main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
@ -118,12 +120,30 @@ for _, chest_color in pairs(colors) do
end
if (from_list ~= "pro" and to_list ~= "pro") or get_is_player_pro(pstat) then
return count
if to_list == "helper" then
-- handle move & overflow
local chestinv = minetest.get_inventory({type = "node", pos = pos})
local playerinv = player:get_inventory()
local stack = chestinv:get_stack(from_list, from_index)
local leftover = playerinv:add_item("main", stack)
local n_stack = stack
n_stack:set_count(stack:get_count() - leftover:get_count())
chestinv:remove_item("helper", stack)
chestinv:remove_item("pro", n_stack)
return 0
elseif from_list == "helper" then
return 0
else
return count
end
else
return 0
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "helper" then
return 0
end
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0
@ -141,12 +161,27 @@ for _, chest_color in pairs(colors) do
end
if listname ~= "pro" or get_is_player_pro(pstat) then
return stack:get_count()
local chestinv = minetest.get_inventory({type = "node", pos = pos})
if chestinv:room_for_item("pro", stack) then
return stack:get_count()
else
-- handle overflow
local playerinv = player:get_inventory()
local leftovers = chestinv:add_item("pro", stack)
local leftover = chestinv:add_item("main", leftovers)
local n_stack = stack
n_stack:set_count(stack:get_count() - leftover:get_count())
playerinv:remove_item("main", n_stack)
return 0
end
else
return 0
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "helper" then
return 0
end
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0