Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update player.lua #1251

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions mods/ctf/ctf_modebase/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ ctf_settings.register("auto_trash_stone_swords", {
default = "false"
})

ctf_settings.register("auto_trash_stone_tools", {
type = "bool",
label = "Auto-trash stone tools when you pick up a better one",
description = "Only triggers when picking up tools from the ground",
default = "false"
})

local simplify_for_saved_stuff = function(iname)
if not iname or iname == "" then return iname end

Expand Down Expand Up @@ -212,10 +219,16 @@ minetest.register_on_item_pickup(function(itemstack, picker)
local cprio = func(compare)

if cprio and cprio < priority then
local item, type = simplify_for_saved_stuff(compare:get_name())
inv:set_stack("main", i, itemstack)

if compare:get_name() == "ctf_melee:sword_stone" and
ctf_settings.get(picker, "auto_trash_stone_swords") == "true" then
if item == "sword" and type == "stone" and
ctf_settings.get(picker, "auto_trash_stone_swords") == "true" then
return ItemStack("")
end

if item ~= "sword" and type == "stone" and
ctf_settings.get(picker, "auto_trash_stone_tools") == "true" then
return ItemStack("")
else
local result = inv:add_item("main", compare):get_count()
Expand All @@ -224,14 +237,12 @@ minetest.register_on_item_pickup(function(itemstack, picker)
return ItemStack("")
else
compare:set_count(result)

return compare
end
end
end
end
end

break -- We already found a place for it, don't check for one held by a different item type
end
end
Expand Down
Loading