NPC following player (revisit)
XanMag
22 Mar 2018, 01:43So... as I most typically do, I decided to do this MY way instead of what was probably suggested somewhere on this forum in a much simpler fashion.
After an event, I have an NPC follow a player wherever that player goes. Easy.
When the player enters a specific room where a specific object is, the NPC returns to his original room. Easy.
Problem:
You are in Room5.
You can see a dragon and a rock.
You can go northeast or northwest.
> get rock
You pick it up.
> Throw rock at dragon
You throw the rock at the dragon.
*Plunk*
You hit him square in the nose.
The dragon has followed you into the room looking as pissed as ever.
I do not want that last message to print until the player has moved rooms. Is there a way to fix what I've done? Below is my code.
dragon.parent = player.parent
msg ("The dragon has followed you into the room looking as pissed as ever.")
if (ListContains(ScopeReachable(), kitten)) {
msg ("<br/>But... he then takes one look at the kitten, sighs, and smiles. His anger at you seems to have subsided. He turns and stomps from the room.")
DisableTurnScript (DragonPissed)
SetObjectFlagOff (dragon, "pissed")
MoveObject (dragon, Room5)
}
I know why it is happening, but is there an easy way to fix it? Thanks in advance.
XanMag
22 Mar 2018, 01:47Oh, also...
Problem #2...
In my actual game (that's right, I am NOT copying the dragon and ice scenario in Zork), certain rooms have a quality that forces the NPC to retreat back to the original room. I think that I have to use inherited type attributes for each room that the NPC will retreat from, right? So, in my example above, instead of (ListContains(ScopeReachable(), kitten)), what would I put in its place? Let's pretend instead of a kitten object it is an inherited type attribute called 'fear'.
I realize I could do a bunch of Else Ifs and check for each object in those certain rooms, but that seems like a mess.
Thanks again!
mrangel
22 Mar 2018, 02:31So you've got a turnscript that moves the dragon into your room and displays a message?
i'd just have the turnscript move the dragon around. And then create a script attribute dragon.changedparent
- this will automatically run whenever the dragon actually moves. So you could put the message in there (though you'd probably want to wrap it in an if
block, to ensure that the dragon is actually pissed. just to make sure that the message doesn't print again when the dragon moves back to room 5.
mrangel
22 Mar 2018, 02:33Problem #2:
if (DoesInherit(dragon.parent, "fear")) {

DarkLizerd
22 Mar 2018, 02:34Maybe...
Add to each object, that could "stop a follower", an attribute... (like)
kitten.dragon // this would stop a dragon from following you, but not anything else...
cat. dragon // this will also stop a dragon
cat.thief // this cat could also stop a thief...
dog.cat // if for some reason the cat is following you, this dog would run it off...
(Then you know better than I how to check for attributes to see if any object in the room has a ".dragon" attribute, which will run the dragon off...)
Problem #1:
on room enter...
if DragonPissed=true, then print
msg ("The dragon has followed you into the room looking as pissed as ever.")
XanMag
22 Mar 2018, 02:54Got it!! Worked perfectly. Got both problems solved! Thanks folks!
Now back to X3! =)