hkzorman / advanced_npc

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

Problem with paralyzed NPCs #38

Closed BrunoMine closed 6 years ago

BrunoMine commented 6 years ago

I'm just doing initial testing to see the changes. I place a bed and a npc next door, but it seems he does not want to sleep. It gets paralyzed only. After a few tries I just get this message in the debugger.

Debug

2018-04-17 11:55:36: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:55:37: [Server]: [advanced_npc] INFO: Initializing NPC at (16,10,-43)
2018-04-17 11:55:37: [Server]: [advanced_npc] INFO: Successfully initialized NPC with name "Kiko", sex: male, is child: nil, texture: {
    "mobs_igor5.png"
}
2018-04-17 11:55:37: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:55:37: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:55:37: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:55:37: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:55:38: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:55:38: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-17 11:55:38: [Server]: [advanced_npc] INFO: NPC "Kiko" is executing: nil
2018-04-17 11:55:38: [Server]: [advanced_npc] INFO: NPC "Kiko" is executing: nil
2018-04-17 11:55:38: [Server]: [advanced_npc] ERROR: Attempted to execute program with name nil.
Program doesn't exists.
2018-04-17 11:55:59: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:00: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:56:00: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:00: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:56:00: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:00: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:56:00: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:00: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:56:01: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:01: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:56:01: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:01: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 11:56:01: [Server]: Executing scheduler for NPC "Kiko"
2018-04-17 11:56:01: [Server]: [advanced_npc] INFO: Current process queue size: 1

register npc mobs redo

on_spawn = function(self)
        if self.initialized == nil then

            -- Initialize
            npc.initialize(self, self.object:getpos(), true)
            self.tamed = false

            -- Location
            local bed = minetest.find_node_near(self.object:getpos(), 6, {"beds:bed_bottom"})
            if bed then
                local v = minetest.facedir_to_dir(minetest.get_node(bed).param2)
                local acess = vector.subtract(bed, v)
                npc.locations.add_owned(self, "cama_1", "bed_primary", bed, acess)
            else
                self.object:remove()
                minetest.chat_send_all("bed not found")
            end

            minetest.chat_send_all("set schedule")

            npc.schedule.create(self, "generic", 0)

            npc.schedule.entry.set(self, "generic", 0, 22, nil, {
                [1] = {
                    program_name = "advanced_npc:walk_to_pos",
                    arguments = {
                        end_pos = {place_type="bed_primary", use_access_node=true},
                        walkable = {}
                    },
                    interrupt_options = {}
                },
                [2] = {
                    program_name = "advanced_npc:use_bed",
                    arguments = {
                        pos = "bed_primary",
                        action = npc.programs.const.node_ops.beds.LAY
                    },
                    interrupt_options = {
                        allow_rightclick = false
                    }
                },
                [3] = {
                    program_name = "advanced_npc:idle",
                    arguments = {
                        acknowledge_nearby_objs = false,
                        wander_chance = 0
                    },
                    interrupt_options = {
                        allow_rightclick = false
                    },
                    is_state_program = true
                }
            })
        end
    end,

    do_custom = function(self, dtime)

        -- Here is my "do_custom" code

        -- Process the NPC action and return freeze state
        return npc.step(self, dtime)
    end,

captura de tela de 2018-04-17 12-08-37

hkzorman commented 6 years ago

@BrunoMine In the schedule entries, order now is very important. I see your schedule entries array has elements 1, 1, 2. Try using 1, 2, 3 and try again.

Also, small hint: In the logs I see: 2018-04-17 11:55:38: [Server]: [advanced_npc] INFO: NPC "Kiko" is executing: nil Instead of nil, it should show the program name, this could be part of the issue.

Also, I have fixed a small bug around the place-finding code, which might help. Please update your branch to the latest.

BrunoMine commented 6 years ago

Correct the code (also edited in the initial post) and updated advanced_npc, but the problem continues.

2018-04-17 15:41:06: [Server]: [advanced_npc] INFO: Initializing NPC at (128,10,19)
2018-04-17 15:41:06: [Server]: [advanced_npc] INFO: Successfully initialized NPC with name "Joseph", sex: male, is child: nil, texture: {
    "mobs_igor3.png"
}
2018-04-17 15:41:07: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:07: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-17 15:41:07: [Server]: [advanced_npc] INFO: NPC "Joseph" is executing: nil
2018-04-17 15:41:07: [Server]: [advanced_npc] INFO: NPC "Joseph" is executing: nil
2018-04-17 15:41:07: [Server]: [advanced_npc] ERROR: Attempted to execute program with name nil.
Program doesn't exists.
2018-04-17 15:41:08: ACTION[Server]: 888 sets time to 22000
2018-04-17 15:41:08: [Server]: [advanced_npc] INFO: Time: 22
2018-04-17 15:41:08: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:08: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 15:41:09: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:09: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 15:41:10: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:10: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 15:41:11: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:11: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 15:41:12: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:12: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 15:41:13: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:13: [Server]: [advanced_npc] INFO: Current process queue size: 1
2018-04-17 15:41:14: [Server]: Executing scheduler for NPC "Joseph"
2018-04-17 15:41:14: [Server]: [advanced_npc] INFO: Current process queue size: 1
hkzorman commented 6 years ago

The main problem is that the program name is nil, for some reason. I will try to reproduce this issue in my local.

BrunoMine commented 6 years ago

try using mobs_npc (igor)

hkzorman commented 6 years ago

Found the issue and pushed a fix. Basically the scheduler didn't expect two things:

Thanks for this! Btw, there is the concept of state process which I have to define better, but basically it is a process that is run by default when no other process is running , and is run continously. The usecase is for example, being idle, wandering, etc.

You can see two state process implemented, advanced_npc:idle and advanced_npc:wander. These processes might give you an idea on how to implement wandering on certain nodes ( I know you do this for your mod)

BrunoMine commented 6 years ago

have you already pushed the fix for the development branch?

hkzorman commented 6 years ago

I had committed but not actually pushed... sorry. Pushed now!

BrunoMine commented 6 years ago

The problem still persists. Maybe I need to fix something in the code. Do you know what the problem is?


2018-04-18 10:04:09: [Server]: [advanced_npc] INFO: Initializing NPC at (120,10,22)
2018-04-18 10:04:09: [Server]: [advanced_npc] INFO: Successfully initialized NPC with name "Alexis", sex: male, is child: nil, texture: {
    "mobs_igor6.png"
}
2018-04-18 10:04:10: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:10: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:11: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:11: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:12: [Server]: [advanced_npc] INFO: Time: 23
2018-04-18 10:04:12: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:12: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:13: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:13: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:14: ACTION[Server]: 888 sets time to 22000
2018-04-18 10:04:14: [Server]: [advanced_npc] INFO: Time: 22
2018-04-18 10:04:14: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:14: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:15: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:15: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:17: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:17: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:18: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:18: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:19: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:19: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:20: [Server]: Executing scheduler for NPC "Alexis"
2018-04-18 10:04:20: [Server]: [advanced_npc] INFO: Current process queue size: 0
2018-04-18 10:04:21: [Server]: Executing scheduler for NPC "Alexis"```
hkzorman commented 6 years ago

Right, forgot tell you that you need to change the function for schedule entries: Instead of "npc.schedule.entry.set()" the correct function is: "npc.schedule.entry.put()". Arguments are fine, just change "set" for "put"

BrunoMine commented 6 years ago

Ok, now it worked, but why? I thought set was the most correct because i am setting a new schedule.

hkzorman commented 6 years ago

The method names follow (or at least try) data structure naming convention. Since schedules are a kind of map, it has:

In this case since entry for 22 doesn't exists, it can't update.