hkzorman/advanced_npc

NPC lies down repeatedly.

Opened this issue · 6 comments

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}
	}
})

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

  • How are you calling this? Is it possible that npc.add_schedule_entry(self, "generic", day, 22, nil, {...}) is being called on a loop?
  • The day should be 0, there is no support yet for other days (as there's no calendar implemented)
  • In the actions array for hour 22, the array seems to start at index 2. Please change it to be 1 and 2.

Let me know if any of this fixes your problem.

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.

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,
[...]

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

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).

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