ThePix / quest

Tutorials and Libraries for quest 5
14 stars 11 forks source link

Trouble with NPC Patrolling #7

Open Himesjb opened 5 years ago

Himesjb commented 5 years ago

I want an NPC ("The Woman") to patrol the area around her cave, about 6 rooms for the route. I copy and pasted in the code from the Quest Documentation pages, and I can make it work but only so that she goes from room to room as long as I don't have any repeated rooms at all in the route. If I repeat any rooms in the list, she just goes back and forth between 2 rooms (the first repeated and the one before it, I think). All I can do then is have a linear route where none of the rooms repeat, which is okay, but it would be more realistic if she could retrace part of her path instead of going in a straight line and then start back magically at the beginning room. Here is the code for her route, as I copied and then modified:

this.route = NewObjectList() list add (this.route, Deep Woods) list add (this.route, Hogs Crossing) list add (this.route, Village) list add (this.route, Old Mule Track) list add (this.route, CrossRoads) list add (this.route, Witch Cave) this.takeaturn => { oldroom = this.parent index = IndexOf(this.route, this.parent) newindex = (index + 1) % ListCount(this.route) this.parent = ObjectListItem(this.route, newindex) if (not oldroom = this.parent) { PrintIfHere (oldroom, "The Woman leaves suddenly.") PrintIfHere (this.parent, "From out of nowhere, the Woman appears.") } }


Is it a problem that my room names have 2 words? I think I remember reading in the Quest tutorials that two-word rooms can cause trouble, but now I can't find where it said that, and I'm not sure I got that right. Also, I came across the NpcLib.aslx while searching for answers, and I downloaded it, but now I can't figure out how to 'initialise' it into my game (how to invoke it as a library, call its functions, or however you say that). I guess that set of codes would really do a lot of what I want, because I also had trouble getting my NPC to pause (if I repeat rooms in the list, she gets hung up there). So having conversations with the player would help with pausing...

ThePix commented 5 years ago

Two word names are fine.

What page did you get the code from? I will update it to allow for that.

There are instructions for NpcLib here: https://github.com/ThePix/quest/wiki/Library:-Independent-NPCs

Once the library is added it is just a case of going to NPC objecvt and setting it to be an NPC on the NPC tab, then telling it what to do.

Himesjb commented 5 years ago

It was the page called "Making NPCs Patrol": http://docs.textadventures.co.uk/quest/patrolling_npcs.html

Thanks so much!

Himesjb commented 5 years ago

NpcLib is working great, but now I am wondering if I can make an NPC follow the player except for when he enters certain room(s). I can't find a way to use an "If" script (or any Npc script) with the "Actions" listed for the NPCs, as they seem to have their own system that doesn't show up on the "scripts" list. I want the NPC to follow but then stop and wait if the player enters certain areas. Is there a way to use npc Actions with "if" scripts? I read the documentation, but I don't see tips on that.