Make objects that player can acquire from NPCs?

Hi there,
In my game, I have an NPC who has a piece of gum that the player needs to get in order to finish the game, but I can't figure out how to let the player ask for the gum. I tried using the Ask/Tell tab by running a script that puts the gum in the player's inventory when they ask the NPC for gum, but the game responds with "I don't understand your command" when I type "ask Carlie for gum."
Any help finding a (probably very simple and obvious) solution would be appreciated. Thanks!


Here is what I would do...

1a. Create the gum and have stored in an empty room (no exits or entrances). It's used just for storage.
or
1b. Have the gum in the room but have it ticked as not visible. If you choose this option, there is no need for an empty room, just make sure you also run the script 'make object visible gum' to step 5.
I used 1a in my example coded below.

  1. Create a 'command expression' in the room where Carlie is. This also assumes Carlie does not move rooms.
  2. In the command input box, type something like this: ask carlie for gum; ask carlie for the gum; get gum from carlie; ask carlie gum; ask for gum; ask for gum from carlie; ask for carlies gum; ask for carlie's gum
  • you can also add any other logical combination you feel will cover the players attempt to ask 'carlie for gum'
  1. For the scripts for the command, I added an If script and used 'If object player has flag gummed' then print message "I already gave you gum"
  2. In the else for this script, I ran a script 'add to inventory object gum'. This will move the gum from the empty room to the player inventory. I also printed a message indicating the gum has been transferred.
  3. The last thing you should add is a set flag on player object named game. Do this in the else box, too.

If you have questions, let us know!

```

That worked! And now I know how to make command expressions. Thanks for your help!


Cool. There is some really helpful things you can use REGULAR EXPRESSIONS for as well. If interested check this out.

http://docs.textadventures.co.uk/quest/complex_commands.html


Have you tried MoveObject ?

I just store objects in other objects. An example, I use stores, and then I store objects in those stores.


the 'ask/Ask' Script/Function is a bit mis-leading, as it's actually just for doing a 'yes/no' type of question, an example:

ask ("Are you guilty of murder?") {
  // quest automatically (hidden from you) does this: result = true // (if you selected 'yes'), or: result = false // (if you selected 'no')
  if (result) {
    msg ("You confess to the crime")
  } else {
    msg ("You state your innocence of the crime")
  }
}

// -------------------------

ask ("Are you a male?") {
  if (result) {
    player.sex = "male"
  } else {
    player.sex = "female"
  }
}

// ---------------------

ask ("Are you a female?") {
  if (result) {
    player.sex = "female"
  } else {
    player.sex = "male"
  }
}


K.V.

To build on XanMag's solution (it really doesn't need it, but I like to frustrate XanMag):

You can also make the NPC a surface (container).

You'd need to tweak a few things, like changing "on which there is" to "who is carrying", but it makes it more realistic when you can look at the NPC and see what he, she, or it is carrying.

From there, you'd probably need to set up take scripts on the objects carried by NPCs which may or may not allow you to just take the things carried by NPCs, but would most definitely change "You pick it up." to "You take it." when the object is carried by someone (or some thing).

You'd also need to create a script when trying to add something to the NPC. I just use msg("You can't put that on "+this.article+".")


I also made a global ask_it_for_something command, which depends on the NPC having a Boolean attribute named giver which is set to true. (I didn't add all the various patterns XM mentioned, but only because I am lazy.)


Example (updated 1/15/18 7:21pm CST):

<!--Saved by Quest 5.7.6572.22852-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="example_game">
    <gameid>c097997e-5053-4b48-b78a-398d5e970a9b</gameid>
    <version>0.0.2</version>
    <firstpublished>2018</firstpublished>
    <feature_asktell />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="Ralph">
      <inherit name="editor_object" />
      <inherit name="namedmale" />
      <inherit name="surface" />
      <feature_container />
      <listchildren />
      <listchildrenprefix>CapFirst(this.article)+" is carrying</listchildrenprefix>
      <giver />
      <addscript type="script">
        msg ("You can't put that on "+this.article+".")
      </addscript>
      <ask type="scriptdictionary">
        <item key="widget">
          if (thingy.parent = Ralph) {
            msg ("\"It's all yours,\" says Ralph, handing it to you.")
            AddToInventory (thingy)
          }
          else {
            msg ("\"I gave it to you already,\" says Ralph.")
          }
        </item>
      </ask>
      <tellto type="scriptdictionary" />
      <contentsprefix>who is carrying</contentsprefix>
      <object name="widget">
        <inherit name="editor_object" />
        <take type="script">
          if (this.parent = Ralph) {
            msg ("You take "+this.article+" from Ralph.")
          }
          else {
            msg ("You pick it up.")
          }
          AddToInventory (this)
        </take>
      </object>
    </object>
  </object>
  <command name="ask_it_for_something_cmd">
    <pattern>ask #object1# for #object2#;#object1#, give me #object2#</pattern>
    <script>
      if (not HasAttribute(object1, "giver")) {
        msg (CapFirst(GetDisplayName(object1)) + " can't do that.")
      }
      else if (object1.giver) {
        if (HasAttribute(object1,"gave_"+object2.name)) {
          msg (CapFirst(GetDisplayName(object1)) + " has already given " + object2.article + " to you.")
        }
        else if (object2.parent = object1) {
          msg (CapFirst(GetDisplayName(object1)) + " hands over " + GetDisplayName(object2) + ".")
          set (object1, "gave_"+object2.name, true)
          AddToInventory (object2)
        }
        else {
          msg (CapFirst(GetDisplayName(object1)) + " is not carrying " + GetDisplayName(object2) + ".")
        }
      }
      else {
        msg (CapFirst(GetDisplayName(object1)) + " can't do that.")
      }
    </script>
  </command>
</asl>

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

Support

Forums