Making NPCs follow
Exellinor
29 Mar 2022, 21:31Hello, I'm new to Quest and I'm trying to make a game in which you have a pet dog that follows you but I can't figure out how to make it follow. Please help. Thank you!
mrangel
29 Mar 2022, 22:24The easiest way is probably to use the roomenter
script ("Script when entering a room:" on the game's "Scripts" tab)
That's run every time the player moves to a new room, so you can use it to check if the dog is currently following the player, and if so move it to the new room.
Something like:
if (some condition to test if the dog is following you) {
dog.parent = game.pov.parent
msg (CapFirst ("{object:dog} follows you into the room."))
}
You could use a flag to make the dog follow you or not, or some other condition.
Exellinor
29 Mar 2022, 22:49OK,I'll try that. Thank you very much!
Exellinor
30 Mar 2022, 00:02I know this is off topic, but I have another question. If you're trying to make a quiver full of arrows, how do you make so that it so that it just says "12 arrows" instead of "arrow" 12 times? Also, how do you make that you need an arrow to shoot a bow? Thank You! ☺☺
mrangel
30 Mar 2022, 00:23I know this is off topic, but I have another question. If you're trying to make a quiver full of arrows, how do you make so that it so that it just says "12 arrows" instead of "arrow" 12 times? Also, how do you make that you need an arrow to shoot a bow? Thank You! ☺☺
For something like that, I would make an object for the quiver and give it an arrows
attribute that's a number. Put it in the inventory to start with, but you can make it hidden.
If you give the quiver a script attribute called changedarrows
, it will be run whenever the number of arrows changes. So you could give it a script like:
if (this.arrows > 0) {
this.visible = true
this.alias = ToStriing (this.arrows) + " arrows"
}
else {
this.visible = false
}
Then for any arrows, you would give them a "take" script (to run when the player takes it) that does:
quiver.arrows = quiver.arrows + 1
this.visible = false
And for shooting a bow, I assume the bow will have a shoot verb; or that there's some command for shooting. You would make it do something like:
if (quiver.arrows = 0) {
msg ("You don't have any arrows!")
}
else {
quiver.arrows = quiver.arrows - 1
// the rest of the code to shoot something goes here
}
Can you follow how that works, checking a numeric attribute to see how many arrows the object represents?
There are more complex versions that can also handle piles of arrows out there in the world; this one only does the "3 arrows" thing in the inventory. But if you can understand it, you can probably work out how to do it.
People have found many different ways to do that kind of thing. Searching the forum for "stacking system" will find a few different approaches, but I think the one I just mentioned is probably the simplest.
(I did have a pretty fancy one that allows the player to type things like "drop six arrows" to split up their supply; but in most cases I think that won't be necessary)