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

Making team doors automatically close after opening. #1151

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mods/ctf/ctf_teams/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = ctf_teams
depends = ctf_core, lib_chatcmdbuilder, doors, default, hud_events
depends = ctf_core, lib_chatcmdbuilder, doors, default, hud_events, ctf_settings
26 changes: 26 additions & 0 deletions mods/ctf/ctf_teams/team_door.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
ctf_settings.register("auto_close_doors", {
type = "bool",
label = "Auto close doors.",
description = "Only triggers when you open your own team's doors.",
default = "false",
})

doors.register("ctf_teams:door_steel", {
tiles = {{name = "doors_door_steel.png", backface_culling = true}},
description = "Team Door",
Expand Down Expand Up @@ -27,6 +34,8 @@ minetest.override_item("ctf_teams:door_steel", {
local item = minetest.registered_craftitems["ctf_teams:door_steel_" .. pteam]
local result = item.on_place(newitemstack, placer, pointed_thing)

minetest.get_meta(pointed_thing.above):set_string("ctf_teams.old_door", minetest.get_node(pointed_thing.above).name)

if result then
itemstack:set_count(result:get_count())
end
Expand All @@ -49,6 +58,7 @@ minetest.handle_node_drops = function(pos, drops, digger)
return old_handle(pos, drops, digger)
end

local jobs = {}
for team, def in pairs(ctf_teams.team) do
local doorname = "ctf_teams:door_steel_%s"
local modifier = "^[colorize:%s:190)^(ctf_teams_door_steel.png^[mask:ctf_teams_door_steel_mask.png^[colorize:%s:42)"
Expand All @@ -63,6 +73,22 @@ for team, def in pairs(ctf_teams.team) do
sound_close = "doors_steel_door_close",
gain_open = 0.2,
gain_close = 0.2,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local door = doors.get(pos)
local jobname = minetest.pos_to_string(pos, 1)
if jobs[jobname] then
jobs[jobname]:cancel()
end

door:toggle(clicker)
if ctf_settings.get(clicker, "auto_close_doors") == "true" and
minetest.get_meta(pos):get_string("ctf_teams.old_door") == node.name then
jobs[jobname] = minetest.after(1.5, function()
door:toggle(clicker)
end)
end
return itemstack
end
})
end

Expand Down