hkzorman / advanced_npc

Advanced NPC for Minetest, using mobs_redo API
Other
17 stars 5 forks source link

NPC lies down repeatedly. #28

Open BrunoMine opened 7 years ago

BrunoMine commented 7 years ago

The npc lies down repeatedly while the hour 22 does not pass.

npc.add_schedule_entry(self, "generic", day, 7, nil, {
    -- Get out of bed
    [1] = {
        task = npc.actions.cmd.USE_BED, args = {
            pos = npc.places.PLACE_TYPE.BED.PRIMARY,
            action = npc.actions.const.beds.GET_UP
        }
    },
    -- Allow mobs_redo wandering
    [2] = {
        action = npc.actions.cmd.FREEZE, args = {freeze = false}
    }
})

npc.add_schedule_entry(self, "generic", day, 22, nil, {
    -- Use bed
    [2] = {
        task = npc.actions.cmd.USE_BED, args = {
            pos = "bed_primary",
            action = npc.actions.const.beds.LAY
        }
    },
    -- Stay put on bed
    [3] = {
        action = npc.actions.cmd.FREEZE, args = {freeze = true}
    }
})
hkzorman commented 7 years ago

I need to investigate this. Few things that come to mind though:

Let me know if any of this fixes your problem.

BrunoMine commented 7 years ago

Your investigation led me to the solution. I'm running npc.add_schedule_entry on on_spawn callback (of mobs_redo). Apparently this callback runs whenever npc is loaded (if I close and open the world, for example). Thanks for the quick response.

BrunoMine commented 6 years ago

The problem happened again, but now there no a loop. Can you reproduce this problem? My code

if sunos.advanced_npc then
    npc.occupations.register_occupation("sunos_npc_caseiro", {
        dialogues = {},
        textures = {},
        building_types = {},
        surrounding_building_types = {},
        walkable_nodes = farming_plants,
        initial_inventory = {},
        schedules_entries = {

            [6] = {
                -- Get out of bed
                [1] = {
                task = npc.actions.cmd.USE_BED, args = {
                    pos = "bed_primary",
                    action = npc.actions.const.beds.GET_UP
                }
                },
                -- Walk to home inside
                [2] = {
                task = npc.actions.cmd.WALK_TO_POS, args = {
                    end_pos = npc.places.PLACE_TYPE.OTHER.HOME_INSIDE,
                    walkable = {}
                },
                chance = 75
                },
                -- Allow mobs_redo wandering
                [3] = {action = npc.actions.cmd.FREEZE, args = {freeze = false}}
            },

            [22] = {
                [1] = {
                task = npc.actions.cmd.WALK_TO_POS, args = {
                    end_pos = "bed_primary",
                    walkable = {}
                }
                },
                -- Use bed
                [2] = {
                task = npc.actions.cmd.USE_BED, args = {
                    pos = "bed_primary",
                    action = npc.actions.const.beds.LAY
                }
                },
                -- Stay put on bed
                [3] = {action = npc.actions.cmd.FREEZE, args = {freeze = true} }
            }
        }
    })
end
[...]
-- NPC callback
on_spawn = function(self)
    if sunos.advanced_npc and self.initialized == nil then
        npc.initialize(self, self.object:getpos(), true)
        self.tamed = false

        -- Configurar lugares (espera para que alores sejam atualizados)
        minetest.after(1, set_npc_places, self)
        -- Configura agenda de tarefas
        npc.occupations.initialize_occupation_values(self, "sunos_npc_caseiro")
    end
end,
[...]
hkzorman commented 6 years ago

I will try to reproduce this issue. Do you mind pointing me to the whole file where this is happening?

BrunoMine commented 6 years ago

Code: The code in the post was used in tests based, currently the project is much modified. The structure is divided. NPC register Schedules Tests: Sunos mod I have already finished implementing advanced_npc in my other project, download the dependencies, open in a world of flat mapgen and look in open and grassy places, wait for an npc to appear at village and then set the schedule for dusk (/time 0).

hkzorman commented 6 years ago

Thanks, I have looked at your code and will be working on this soon.