creating an NPC follower

steve the gaming guy
Is it possible to make an NPC that can follow throughout a game from room to room? And getting more complicated, maybe at certain times during the game, the NPC decides to leave for whatever reason and return later. AND there are certain parts of the game that the NPC decides it doesn't want to go with you at all.
I'm thinking about making a version of King's Quest V and those who are familiar with it remember the owl that follows you for most of the game...

Al, do you think this would be better accomplished using the typelib library where NPC's are labeled as 'actors' as opposed to objects? I'm sure there is a lot more to it than that though.

Thanks,
steve 8)

007bond
I think that would be a good ability to add to the next version of TypeLib. It would be pointless making it part of the standard Quest.

In answer to your question, I wouldn't use the TypeLib's actor thing for this. What this does require is some very hard programming. There would probably be 2 ways to do this: using the global after turn script, or making all room exits complex scripts. Either way is very hard, and I'm not sure how to do it exactly.

Anonymous

Is it possible to make an NPC that can follow throughout a game from room to room?



Yes it is possible and it isn't even that hard to do.

Somewhere I have a demo I wrote in which a pet cat follows the player around until it is fed.. then mooches off until it gets hungry at which point it follows the player again... This was I'm pretty sure posted to the forums way back - might even have been the old forums actually.

Does this sound like what you are looking for?

Al (MaDbRiT)

I think Im Dead
Wow I wrote a reply to this last night but apparently didn't post it.

It, like anying, can vary in difficulty. If you want something like Al suggested, it really probably wouldn't be anything more than a post script and a few if statements. If you want something where the npc has some serious AI of it's own and will go out and so some quest's of it's own and such, it can be a vary daunting process.

Anonymous
Here's a very simple 'following NPC'. In this case the cat will follow the player if he speaks to it.

I've chosen to implement it by adding an action in the cat object that is called by the game's afterturn script. This makes it quite easy to make the conditional tests to decide whether the cat should move (and be reported as moving) in the cat object rather than clutter up the afterturn script which you might want for something else.

If you want to stop the cat following, just set the 'cat_following' flag to off in code - easy as that. :-)


' "NPC Follower Demo"
' Created with QDK Pro 3.52

!include <Typelib.qlb>

define game <NPC Follower Demo>
asl-version <350>
gametype singleplayer
start <kitchen>
game author <Your Name>
game version <1.0>
game copyright <© 2004 ...>
game info <Extra Info>
afterturn doaction <fluffy;following>
end define

define synonyms
end define

define room <kitchen>
look <a normal kitchen>
north <hall>

define object <fluffy>
type <TLTobject>
type <TLTactor>
properties <displaytype=cat; not takeable>
action <following> {
if flag <cat_following> and ( $locationof(fluffy)$ <> #quest.currentroom# ) then {
move <fluffy;#quest.currentroom#>
msg <Fluffy has followed you and is miaowing for attention.>
}
}
action <speak> {
flag on <cat_following>
msg <Fluffy miaows back at you... Cats are not great conversationalists>
}
end define

end define

define room <hall>
look <a normal hall>
north <lounge>
south <kitchen>
end define

define room <lounge>
look <a normal lounge>
south <hall>
end define

define text <intro>
Enter intro text here
end define

define text <win>
Enter win text here
end define

define text <lose>
Enter lose text here
end define



Al (MaDbRiT)

steve the gaming guy
That cat idea sounds pretty good. Thanks a lot.

For a quick idea of what's going to happen (and for those who haven't played King's Quest V), you are King Graham accompanied by an owl named Cedric. He is mostly there as a hint companion. If you talk to him, he suggests what might be a good thing to do.
There are certain parts of the game such as, where you walk into town, Cedric says "I think I'll stay out here, I had a nasty run-in with a dog last time." You go into town for an undetermined amount of time and when you return, Cedric is waiting for you.
Certain things happen to Cedric during that game that are beyond your control. He gets "kidnapped" a couple times and eventually returns to your side during the course of the story.
Towards the end of the game, he leaves you "to get help" and returns when you reach a certain part of the end.
It sounds complicated but I think if I keep your cat scenario in mind, I should be on the right track.

Thanks again,
steve

007bond
That shouldn't be to hard to do. Good luck with your game.

billchelonis
Though you can do it as an afterturn event or turn event in each room, I did something like this as a "timer" agent. This way you do not have to repeat code in every room.

Have a timer just check a made up "isFollowingPlayer" flag for the NPC, and then if the flag is true just move the NPC to quest.currentroom and maybe add in a random string from a table to display how the NPC arrives (i.e. "Chancey stumbles in the room behind you." or "The butler follows you in.", etc.)

I also had flags attached to rooms where I did not want an NPC to follow you. For example, Chicken Chancey (a made up NPC) won't follow you into the haunted mansion and if you go there after having issued him a "follow me" command, he'll run away to a non-mansion room and stop following you. In this case I mixed a "nearClockTower" flag with this so that if you're anywhere near the mansion's clock tower the NPC would chicken out and stop following.

Anyhow, the timed agent is kind of nice and allows for the NPC to follow you at a different (real time) interval than a turn based script. In other words, if the follower was kind of a slow poke he might not follow you right away but eventually get there some 20 or 30 seconds later in real time, in which case you might see the following message appear "...Chancey stumbles in the room out of breath." Or "Chancey enters the room complaining,"Hold up a sec... you go too fast, Stan. You go too fast..."

steve the gaming guy
Hmm, after a few weeks, I'm actually going through some of these codes and trying them out. This particular one, I can't get the cat to do anything. I can walk out and he doesn't follow. I can pick him up and carry him out but that kills the point of what I was testing.

What command makes him do something?

steve the gaming guy :roll:

Anonymous
Steve wrote

I can't get the cat to do anything. I can walk out and he doesn't follow. I can pick him up and carry him out but that kills the point of what I was testing.

What command makes him do something?



To demonstrate how to start (or stop) a following NPC I set this code so that the cat does nothing until you speak to it -THEN it will follow you about.

The idea was that if you attract its attention it follows you - cats are like that. :-)

In the original sample (not the one here) the cat stopped following you after you fed it - another 'typical cat' trait as anyone who owns one will confirm.

Al (MaDbRiT)

Anonymous
ohhh ok

thanks!

Anonymous
Severely off topic!

I wrote

another 'typical cat' trait as anyone who owns one will confirm.



As Ali my tester pointed out, cats don't actually subscribe to the concept of 'being owned' by humans, but they are smart enough to what makes for an easy life ;-)

Al (MaDbRiT)

007bond
very true. Cats really are amazing animals

Elexxorine
ok that very nice but that follower codes looks good. but i cant use asl have you got i qdk script version?

Anonymous

i cant use asl have you got i qdk script version?



You can cut n paste the example given above into notepad, then save as as (say) "cat.asl" - after which you will be able to open the file with QDK and see how it was done.

Al (MaDbRiT)

007bond
ASL files are text files that QDK parses. If you right-click on an ASL file and go Open With, and select Notepad, you can see all the ASL. From here you can make changes. It ain't rocket science, but it would probably help if you are a coder in a language like VB

GameBoy
007bond wrote:It ain't rocket science, but it would probably help if you are a coder in a language like VB


lmao, no it wouldn't....

007bond
yes it would, it would help you understand the way code is set out.

paul_one
It would help if you had a 'healthy' knowledge of PC's and knew HTML or some other script-like language...

-Bleh

steve the gaming guy
Yo MaDbRit,

I'm finally tackling this thing whole-heartedly now and I started working on the "following character" a different way because the game didn't seem that large. I was putting a script in every exit moving the character behind you. I've now attempted to use your cat-following script instead to see if I can get it to work. Short story: I cannot get it to work!!! Below is the code for the game (after hacking out unimportant sections). Cedric, my character, refuses to follow. At least the displaytype works!:

' "King's Quest V - text adventure"
' Created with QDK 3.52 - UNREGISTERED VERSION

!include <Typelib.qlb>

define game <King's Quest V - text adventure>
asl-version <350>
gametype singleplayer
start <Crispin's house -out front>
game author <Steve Lingle>
game info <Created with QDK 3.52 - UNREGISTERED EVALUATION VERSION.>
startscript do <start>
end define

define synonyms
take = get
end define

define room <Crispin's house -out front>
look <To the south you can almost make out a small town.>
indescription <You are at>
south <Town Path>
script msg <After a lengthy discussion with the great wizard, Crispinopher (Crispin for short), you set off on your quest to find your family. Accompanying you is Cedric, the wise-cracking owl, who will guide you occasionally. You were given only two items, a worn out magic wand and a bite of magical white snake (that you've already eaten) which helps you to understand the language of nature and animals. >

end define

define room <Town Path>
alias <town path>
look <A single stream of sunlight parts the branches and barely illuminates the dirt path before you. You come upon a dirt road intersection that goes in different directions. To the west, is another path that winds into the forest. To the south, you can definitely make out the activity of the town. To the east, a path leads up into the mountains but a rattlesnake seems to be blocking your path.>
indescription <You are on the>
north <Crispin's house -out front>

script {
flag on <snake>
if flag <snake> then {
say <|clLook out for that snake, Graham!|cb>
msg <says Cedric as he lands on a nearby tree branch.>
}
}

define object <rattlesnake>
alt <snake>
look <A rattlesnake eyes you as you walk by.>
take msg <That could be dangerous, Graham!>
speak <"Move, snake!" You yell out. The snake seems unintimidated by your meager attempts at frightening it.>
examine <This snake seems to be set on holding its ground. If there were only some way to frighten it off the path.>
prefix <a>
displaytype <reptile>
article <it>
end define

end define

define room <inven room>

define object <Cedric>
alt <owl; bird>
type <TLTobject>
type <TLTactor>
properties <displaytype=owl; not takeable>
action <following> {
if flag <cedric_following> and ( $locationof(Cedric)$ <> #quest.currentroom# ) then {
move <Cedric; #quest.currentroom#>
}
}
action <speak> {
do <cedric>
}
end define

end define

define procedure <cedric>
if ( #quest.currentroom# = Crispin's house -out front ) then say <|clGraham, why don't you try the town to the south? I'd hate to get lost in the forest to the west.|cb>
if ( #quest.currentroom# = Town Path ) then say <|clThere must be |isome|xi way to scare that snake away. For now, we could still move on towards the town further south.|cb>

end define

define procedure <start>
move <Cedric; Crispin's house -out front>
flag on <cedric_following>
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define


Please Help!!!

steve the gaming guy :o

Anonymous
Hi Steve

You've forgotten to set up the 'afterturn' script in game properties - it is this which calls the 'following' action in your character :-)

Al (MaDbRiT)

steve the gaming guy
Sweet!!! Thanks a lot! It works now!!!

steve the gaming guy :P

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums