[Source] Easy to use NPC script (interaction, walking)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
mahric
Posts: 192
Joined: Sun Nov 04, 2012 3:05 pm

[Source] Easy to use NPC script (interaction, walking)

Post by mahric »

I made a library that allows you to define NPCs, make them walk a pre-defined route and interact with them with very little scripting.

At this moment the following monsters work:
- Ogres
- Skeleton warriors
- Scavengers
- Goromorg

You can:
- Create/remove an npc
- Make him walk a predefined path
- Make him (in)vulnerable with a single statement
- Define functions that are called when you click the NPC or give him an item

I released the source in a ready-to-play demo. Download it here. To use it in your own dungeon, consult the README.TXT in the "mod_assets/md_npc" folder.

Click here for a movie demonstrating the script.

List of available functions. (See source for parameters and more comment)
SpoilerShow

Code: Select all

mdNPC.addNPC()            - Spawn an NPC
mdNPC.registerNPC()       - Register a monster as an NPC
mdNPC.removeNPC()         - Despawn the monster and remove it from the NPC list
mdNPC.setRounte()         - Defines a route for the NPC to walk
mdNPC.appendRoute()       - Appends the defined route to the current route of the NPC
mdNPC.setInvulnerable()   - Defines if the NPC is invulnerable to damage
mdNPC.isWalking           - Indicates if the NPC is currently walking (walking characters don't respond to click events)
mdNPC.setOnClick()        - Set which function to call when the player clicks on the NPC
mdNPC.setOnGive()         - Set which function to call if the player gives and item to the NPC
mdNPC.setTag()            - Set the value of the tag. Use a tag for your own purpose. In the demo I use it to track progress in the 'plot' and response from the monster
mdNPC.getTag()            - Get the value of the tag
Last edited by mahric on Tue Mar 12, 2013 9:10 pm, edited 10 times in total.
Did you visit the Wine Merchant's Basement? And heard about the Awakening of Taarnab?
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Moving NPC's

Post by Komag »

That looks quite powerful and useful, I'm sure people would like use of it, especially long term :)
Finished Dungeons - complete mods to play
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: Moving NPC's v0.1 (incl source)

Post by Phitt »

That's pretty cool and certainly very useful for a lot of purposes. Thanks (if you release it... :lol: )!
User avatar
pulpum
Posts: 155
Joined: Wed Apr 18, 2012 1:23 am
Location: bordeaux, france

Re: Moving NPC's v0.1 (incl source)

Post by pulpum »

impressive! 8-)
ad&d / ff / d&d
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Moving NPC's v0.1 (incl source)

Post by Grimfan »

Very Impressive! This will be amazingly useful when it comes out. :D

Of course, I secretly wish AH gives modders the tools to do this (and many other things) without writing extra code.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Moving NPC's v0.1 (incl source)

Post by Drakkan »

I wish we had some human NPC´s...
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Moving NPC's v0.1 (incl source)

Post by Dr.Disaster »

Drakkan wrote:I wish we had some human NPC´s...
Well one could try skeletons. Looking at them tells how long they've been waiting for customers :twisted:
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: Moving NPC's v0.1 (incl source)

Post by SpiderFighter »

mahric wrote:Would the community be interested in a further developed version? Or should I release it as-is?
Great work, as usual, and very generous of you to share it with the community.
Considering my little (50 second) animation of a Skelly Warrior capturing an ogre and preparing to whup on him took a lot of precise timing, hidden plates and blockers, a hidden tele, and custom defined NPCs, I'd say go for it!

(Related map of area in video:)
SpoilerShow
Image
Your way sounds so much easier! :D
User avatar
mahric
Posts: 192
Joined: Sun Nov 04, 2012 3:05 pm

Re: Moving NPC's v0.1 (incl source)

Post by mahric »

I just uploaded a new demo including source that supports more than yesterdays version:

- Installation instructions (look at readme file in "mod_assets/md_npc" folder
- You can despawn and NPC if you want
- Supported monsters are now: Ogre, Skeleton warrior, Goromorg and scavenger

It still crashes if you walk over a pit though, I'll have to look into that later. :(
Did you visit the Wine Merchant's Basement? And heard about the Awakening of Taarnab?
User avatar
mahric
Posts: 192
Joined: Sun Nov 04, 2012 3:05 pm

Re: Moving NPC's v0.3 (incl source)

Post by mahric »

Another new version is being uploaded.

v1.03
- NPC's are now invulnerable by default, but it can be changed with the setInvulnerable() function
- The script no longer crashes if an npcs falls into a pit

The way it is now should be enough for basic usage. It would be enough for me if I had it in the awakening of taarnab.
Did you visit the Wine Merchant's Basement? And heard about the Awakening of Taarnab?
Post Reply