Hunted by a NPC in the game

Hello - I have a sequence I’m working out which involves the player being hunted by an NPC, I’d like to be able to let the player hide behind something in the room, but am having difficulty getting the game to recognize the player as “hidden”. Not sure what I’m doing wrong, but here’s a bit of the code and gameplay results…

[code]Section - HIDING

An object is either hideable or nothideable. An object is usually nothideable.

A person is either hidden or vulnerable. A person is usually vulnerable.

Hiding is an action applying to one visible thing.

Understand “hide behind [something]” as hiding.

The Forest is a room. The description of player is “You’re [if the player is hidden]hidden[otherwise]vulnerable[end if].”

A tree is in the Forest. The tree is hideable.

There is a stump in the Forest.

Carry out hiding:
if the noun is a tree:
say “You are now hiding behind a tree.” instead;
now the player is hidden;
otherwise:
say “You can’t hide behind the [noun].” instead.[/code]

Forest
You can see a tree and a stump here.

hide behind tree
You are now hiding behind a tree.

x self
You’re vulnerable.

hide
What do you want to hide behind?

stump
You can’t hide behind the stump.

hide
What do you want to hide behind?

forest
You can’t see any such thing.

hide behind tree
You are now hiding behind a tree.

x self
You’re vulnerable.

Any suggestions how I might fix this, and make the game recognize the player as either “hidden” or “vulnerable”? Thanks for any help or tips…

Hm, I think I just fixed this by removing the first “instead” in the ‘carry out hiding’ action–but the next problem is to work out a way to make the NPC wait two turns if the player is visible, before attempting to kill them, thus giving you a chance to flee…I might get hung up on that, so I’ll keep this thread open for any help in the short term.

Okay, with the help of another script I’ve found here I’ve begun to get the hunting sequence working, except for one thing…I’m not sure how to change the player back from “hidden” to “vulnerable” once they are no longer in the room that has a tree they can hide behind. Once I hide, wherever I go, the game thinks I’m still ‘hidden’. I thought the way I wrote it that the game would only consider me ‘hidden’ if I was in a certain room with a certain object that provides cover.

I’m wondering if I have to script an additional command like “stand up” or a “yes/no” prompt asking the player if they want to come out of their hiding place before any other action can be performed, and then set their status back to “vulnerable” again? If anyone has any suggestions as to the easiest way to unhide the player I would be really appreciative. Thanks!

[code]Trolls Path is a region. Denied is a region.

Section - HIDING

A person is either hidden or vulnerable. A person is usually vulnerable.

Hiding is an action applying to one visible thing.

Understand “hide behind [something]” as hiding.

The description of player is “You’re [if the player is hidden]hidden[else if the player is vulnerable]vulnerable[end if].”

Carry out hiding:
if the noun is a gnarled tree and the location is Forest:
say “You are now hiding behind a tree.”;
now the player is hidden;
otherwise:
say “You can’t hide behind the [noun]” instead.

Section - SAMPLE TEST GAME

Forest is a room in Trolls Path. A gnarled tree is in the Forest. A stump is in the Forest. Clearing is a room in Trolls Path. It is north of Forest. Meadow is a room in Trolls Path. It is east of Forest. Cliff is a room in Denied. It is south of Forest. Hilltop is a room in Denied. It is west of Forest.

Troll is a man in Forest.

Every turn (this is the hungry troll rule):
If the location of Troll is the location of the player:
say “[one of]The Troll looks around, trying to find where the delicious scent of food is coming from.[or]The Troll turns over a nearby rock, hoping to find something - or someone - to eat.[or]The Troll lashes outvangrily, narrowly missing your head.[then at random]”;
hunt the player;
Otherwise:
hunt the player.

To hunt the player:
let origin be the location of Troll;
let nextspace be a random room which is adjacent to origin;
while nextspace is not in Trolls Path:
let nextspace be a random room which is adjacent to origin;
let way be the best route from the origin to nextspace;
if Troll is visible:
say “With a grunt, the Troll moves [way], trying to find someone to eat.”;
try Troll going way;
if Troll is visible and the player is not hidden:
say “The Troll howls in rage as he spots you! You have died”;
end the story.
[/code]

Try this:

Carry out going: now the player is vulnerable.

This ought to fire only when the player successfully goes to another room (so if you get blocked by a locked door or are trying to go a way where there’s no exit, it won’t fire), and since it doesn’t contain “instead” or “stop the action” or “rule succeeds” it won’t stop the rest of the behavior of the going action from happening. (As you discovered, when you put “instead” at the end of a line it ends the entire action immediately, so none of the subsequent rules discovering that action will fire.)

Thanks Matt, and another thing…

To hunt the player: let origin be the location of Troll; let nextspace be a random room which is adjacent to origin; while nextspace is not in Trolls Path: let nextspace be a random room which is adjacent to origin; let way be the best route from the origin to nextspace; if Troll is visible: say "With a grunt, the Troll moves [way], trying to find someone to eat."; try Troll going way; if Troll is visible and the player is not hidden: say "The Troll howls in rage as he spots you!"; after waiting two turns, say "***You are killed.***"; end the story.

Does anyone know a way I could insert an “after two turns from now” into this, so that the game will give the player a chance to escape or do something before they are killed?

As it is now, the player is killed as soon as they run into the Troll, but ideally, I’d like to figure out a way to give the player a chance to respond/evade, before they are killed. I know the above code is wrong, but I was hoping somebody would understand a different way of putting it and tell me if there was some way this could be worked into the code…

You might try using a scene. Something like “Troll-attacking is a scene. Troll-attacking begins when blah blah blah.” Then, when the scene has been running for two turns, kill the character.

I would suggest a timed event (e.g. “the troll attacks in two turns from now”), but I don’t know if you can cancel one once it has been scheduled.

For anyone who may be interested in testing and adapting this scenario to their own project, I tacked on ‘Armed’ by David Ratliff, and made it so the player can hide from the NPC hunting you (for example if there’s something in the room like a tree to conceal you), and the NPC will alternate back and forth between ‘docile’ (if he can’t see you, meaning he’ll just roam around) or ‘hostile’ (meaning he will attack on sight if you’re visible to him). It’s probably not the most elegant way to do this, but seems to work okay so far, and maybe somebody will wish to come along and add something new or refine it.

[code]“Hide and Seek”

Include Armed by David Ratliff.

Trolls Path is a region. Denied is a region.

Section - ARMED

Use no scoring.

A crossbow is a bow. The maximum damage of the crossbow is 25.

A centaur is a kind of person. The max health of a centaur is usually 40. A centaur is usually docile.

Section - HIDING

A thing can be hideable. A thing is usually not hideable.

A person is either hidden or vulnerable. A person is usually vulnerable.

Hiding is an action applying to one visible thing.

Understand “hide behind [something]” as hiding.

The description of player is “You’re [if the player is hidden]hidden[else if the player is vulnerable]vulnerable[end if].”

Carry out hiding:
if the noun is a hideable thing:
say “You are now hiding behind the [noun].”;
now the player is hidden;
otherwise:
say “You can’t hide behind the [noun].” instead.

Carry out going:
say “(first creeping out of your hiding place…)”;
now the player is vulnerable.

Section - SAMPLE TEST GAME

Forest is a room in Trolls Path. A gnarled tree is in the Forest. The gnarled tree is hideable. A stump is in the Forest. Clearing is a room in Trolls Path. It is north of Forest. Meadow is a room in Trolls Path. It is east of Forest. A large boulder is in the Meadow. The large boulder is hideable. Cliff is a room in Denied. It is south of Forest. Hilltop is a room in Denied. It is west of Forest.

Troll is a centaur in the Forest. The max health of Troll is 70. Troll is docile. Troll carries the crossbow.

Every turn (this is the hungry troll rule):
If the location of Troll is the location of the player:
say “[one of]The Troll looks around, trying to find where the delicious scent of food is coming from.[or]The Troll turns over a nearby rock, hoping to find something - or someone - to eat.[or]The Troll lumbers clumsily about, sniffing the air.[then at random]”;
hunt the player;
Otherwise:
hunt the player.

Every turn:
if Troll is visible and the player is hidden:
now the Troll is docile.

To hunt the player:
let origin be the location of Troll;
let nextspace be a random room which is adjacent to origin;
while nextspace is not in Trolls Path:
let nextspace be a random room which is adjacent to origin;
let way be the best route from the origin to nextspace;
if Troll is visible:
say “With a grunt, the Troll moves [way], trying to find someone to eat.”;
try Troll going way;
if Troll is visible and the player is not hidden:
say “The Troll howls in rage as he spots you!”;
now the Troll is hostile.[/code]