NPC (Custom Brain, or No Brain)

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
The_Morlock
Posts: 17
Joined: Sun Jun 02, 2024 6:15 am

NPC (Custom Brain, or No Brain)

Post by The_Morlock »

Hey everyone,

I've been researching and working on creating an NPC in my mod. I've attended the LoG2 Discord and they (mostly minmay (Thank you, BTW!)) have been gracious enough to give me some pointers to use the monster brain instead of just monster commands (I assume because LoG2 was designed with using monster brains only and not just commands with no brain? I've noticed that there are fewer non-brain monster commands like seek() and goTo(). Note that this monster is there only to perform a set sequence of events, nothing more. It is not going to interact with the party or other monsters.), but I've been running into hurdles I can't seem to figure out. With each set of brain commands, the monster will wander around and go where the party is and I can't seem to stop this behavior. If I use no brain, the sequence of events is rather... mechanical. 1 second for each square move, etc. It just isn't as smooth. I've used both a timer object as well as delayedCall() which works better than the timer object as I can more easily set second limits until the next command.

I've been looking into this via the following forum post:
https://mail.grimrock.net/forum/viewtop ... ion#p93615

It informs that the wait() command sometimes is not followed when using the monster brain...
Note that calling wait() doesn’t appear to override the predefined brain behavior.
unlike if adding it to a predefined brain, where this will accomplish nothing
Forgive me if you've seen this before, I am just needing more clarification since if I simply add the commands in order, they are not followed and seemingly, they are all run at the same time instead of waiting for one command to complete before going to the next command.

Basically, I need an NPC that does a specific set of instructions, like the following (waiting until each one completes before continuing to the next):

Code: Select all

monster spawns at x5,y16,z1 facing 3(west)
monster moveForward() twice (or two spaces/cells) (could be seek x3,y16,z0 if using brain since it seems that non-brain commands only move one space at a time)
monster at x3,y16,z0
monster waits for x seconds for dialogue to play
monster turnLeft()
monster moveForward()
monster at x3,y17,z0
monster turnRight()
monster moveForward()
monster at x2,y17,z0
monster turnLeft()
monster moveForward()
monster at x2,y18,z0
monster waits for lever at x2,y18,z0
monster waits for x seconds for dialogue to play
monster seeks to x4,y24,z0
monster waits for lever at x3,y24,z0 and then moves downstairs
If I can add to the LUA defineObject onThink (self) instruction set to perform a command and then just wait for the next command, that would be ideal as this won't be the only NPC in the mod.

I appreciate anyone who gives assistance.

Much appreciated,
TheMorlock
My Project(s): Grimstone Keep, a reimagining of the 1995 Interplay game, Stonekeep.
Discord: https://discord.gg/AfZVYHc8JX
Patreon: https://patreon.com/GrimstoneKeep
Post Reply