In a detection turnscript, checking if the last command entered was to use certain objects.

Hi,

I'm working on a stealth system in Quest 5.8, mostly as a fun exercise to get to grips with the scripting. I have built a system off CombatLib, that removes its basic stealth and instead now uses a system that gives a chance of detection by any 'attack on sight' monster based on a formula that includes the attributes of the room, player's agility, and a monster's perception score.

The detection script runs on every player turn, except if the last command was from a whitelist of allowed commands (for example, looking does not risk detection). This was achieved with a switch testing game.pov.currentcommandpattern.

However, as part of the system, certain inventory objects can be used to help the player improve their stealth. For example, using a moss vial will eliminate the room factor "loud floor". I want doing this to not risk detection, since the player won't know they need to until they have already entered a room that has enemies in it. I obviously don't want every "useon" to be whitelisted though, since I imagine many possible "useon"s should carry risk.

Is there a way to check if the last command was a use 'moss vial/other object' (or even "object that has x attribute") in Quest?


I think you want player.currentcommand.
Forgive the pseudo-coding.

If player.currentcommand = use moss vial
Then
…

I'm sure other users/writers may have a different approach.

There is also an unresolvedcommand detailed below which is amusing.
http://textadventures.co.uk/forum/samples/topic/hrhvcwvfa0_tjk2fky5thw/hitchhikers-guide-gag-in-quest


3 ways to do this:

  1. If you're just talking about useon, you could modify that command so that it saves the used object in an attribute somewhere before doing its normal behaviour.

  2. Or, if the number of "safe" objects is small, have the 'use' scripts for those objects set a flag which your turnscript checks (and then clears).

  3. Look at game.pov.currentcommandresolvedelements - it will be a dictionary containing all the parameters for the current command. In the case of useon, it will have 2 keys, object1 and object2.


Thanks for the replies, went with option 2 from mrangel.

One other thing I was thinking of allowing was leaving via the same exit you entered, but I have no idea how I'd tell which that is.


One other thing I was thinking of allowing was leaving via the same exit you entered, but I have no idea how I'd tell which that is.

Simplest way would probably be to modify the changedparent script attribute of the player. That script's run whenever they move from one location to another. Within that script, you can use this.parent for the room they're going to, and oldvalue for the room they've come from.
So you could, for example, add something like:

if (this.parent = this.previousroom) {
  // We're going back to the previous room, so set the flag
  // to let your turnscript know this is a stealthy action
}
else {
  this.previousroom = oldvalue
}

Maybe in your turnscript, if they actually do something in the room they've entered (like, they do a non-stealthy action), it implies they've moved away from the door so you'd set game.pov.previousroom = null as well.


Log in to post a reply.

Support

Forums