Page 1 of 3

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

Posted: Tue Mar 05, 2013 11:22 pm
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

Re: Moving NPC's

Posted: Tue Mar 05, 2013 11:36 pm
by Komag
That looks quite powerful and useful, I'm sure people would like use of it, especially long term :)

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

Posted: Tue Mar 05, 2013 11:55 pm
by Phitt
That's pretty cool and certainly very useful for a lot of purposes. Thanks (if you release it... :lol: )!

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

Posted: Wed Mar 06, 2013 12:02 am
by pulpum
impressive! 8-)

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

Posted: Wed Mar 06, 2013 9:58 am
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.

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

Posted: Wed Mar 06, 2013 4:04 pm
by Drakkan
I wish we had some human NPC´s...

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

Posted: Wed Mar 06, 2013 4:08 pm
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:

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

Posted: Wed Mar 06, 2013 10:15 pm
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

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

Posted: Wed Mar 06, 2013 10:49 pm
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. :(

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

Posted: Sat Mar 09, 2013 9:52 pm
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.