From cffd307cfe34710c77e73a871f22db48941e7814 Mon Sep 17 00:00:00 2001 From: zorman2000 Date: Thu, 29 Dec 2016 17:26:09 -0500 Subject: [PATCH] Actions: Added action to open/close doors, fence gates and anything that uses the default doors mod. --- actions/actions.lua | 33 +++++++++++++++++++++++++++++++++ npc.lua | 9 +++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/actions/actions.lua b/actions/actions.lua index 08dd1b4..8555f7c 100644 --- a/actions/actions.lua +++ b/actions/actions.lua @@ -13,6 +13,18 @@ npc.actions = {} +-- Describes actions with doors or openable nodes +npc.actions.door_action = { + OPEN = 1, + CLOSE = 2 +} + +-- Describe the state of doors or openable nodes +npc.actions.door_state = { + OPEN = 1, + CLOSED = 2 +} + function npc.actions.rotate(args) local self = args.self local dir = args.dir @@ -153,6 +165,25 @@ function npc.actions.take_item_from_external_inventory(args) return false end +-- This function is used to open or close doors from +-- that use the default doors mod +function npc.actions.use_door(args) + local self = args.self + local pos = args.pos + local action = args.action + local node = minetest.get_node(pos) + local state = npc.actions.door_state.CLOSED + local a_i1, a_i2 = string.find(node.name, "_a") + if a_i1 == nil then + state = npc.actions.door_state.OPEN + end + --minetest.log("Node: "..dump(node)..". State: "..dump(state)..", Action: "..dump(action)) + local clicker = self.object + if action ~= state then + minetest.registered_nodes[node.name].on_rightclick(pos, node, clicker, nil, nil) + end +end + --------------------------------------------------------------------------------------- -- Tasks functionality @@ -276,6 +307,8 @@ function npc.actions.get_direction(v1, v2) end end +-- This function is used to determine if a node is walkable +-- or openable, in which case is good to use when finding a path local function is_good_node(node) -- Is openable is to support doors, fence gates and other -- doors from other mods. Currently, default doors and gates diff --git a/npc.lua b/npc.lua index 9b0c924..45753da 100755 --- a/npc.lua +++ b/npc.lua @@ -346,10 +346,11 @@ local function npc_spawn(self, pos) ent.places_map = {} -- Temporary initialization of actions for testing - local nodes = npc.places.find_new_nearby(ent, {"default:furnace"}, 20) - npc.add_action(ent, npc.actions.stand, {self = ent}) - npc.add_action(ent, npc.actions.stand, {self = ent}) - npc.actions.walk_to_pos(ent, nodes[1]) + local nodes = npc.places.find_new_nearby(ent, {"doors:door_wood_a", "doors:door_wood_b"}, 2) + npc.add_action(ent, npc.actions.use_door, {self = ent, pos = nodes[1], action = npc.actions.door_action.OPEN}) + --npc.add_action(ent, npc.actions.stand, {self = ent}) + --npc.add_action(ent, npc.actions.stand, {self = ent} + --npc.actions.walk_to_pos(ent, nodes[1]) -- npc.add_action(ent, npc.action.stand, {self = ent}) -- npc.add_action(ent, npc.action.stand, {self = ent}) -- npc.add_action(ent, npc.action.walk_step, {self = ent, dir = npc.direction.east})