About limiting taken Objects [Solved]

I'm fairly new to Quest and coding in general, and probably getting ahead of myself with this...
I'm trying to make a sort of RPG, but I hit a wall trying to figure out how to limit the things the player can take before moving on.
Like, I want them to pick 2 things from a selection of items and once they do - force them to the next stage of the story with those items in their inventory.

Thanks for any help in advance!


there is probably a better way to do this but you could trigger a menu that asks which combination of objects they want to take.

object 1+2
1+3
2+3
and once the selection is made move the 2 object to the player inventory and then move the player to the next room

would look something like this

objchoice = split("hat and vest;vest and glove;hat and glove", ";")
ShowMenu ("What do you want to take?", objchoice, false) {
  switch (result) {
    case ("vest and glove") {
      msg ("you chose the vest and glove.")
      MoveObject (glove, player)
      MoveObject (vest, player)
      MoveObject (player, room2)
    }
    case ("hat and glove") {
      msg ("you chose the hat and glove.")
      MoveObject (hat, player)
      MoveObject (glove, player)
      MoveObject (player, room2)
    }
    case ("hat and vest") {
      msg ("you chose the hat and vest.")
      MoveObject (hat, player)
      MoveObject (vest, player)
      MoveObject (player, room2)
    }
  }
}

you can script that in the room1 description and put the 3 object in a object or hidden room. when the player make a choice he will receive the items and be moved to room 2 .

there is no chance of him taking anything since the object are not there with him in the room.


If it's objects in the first room, then I'd say put a custom "take" command in that room. It will run instead of the default take command as long as the player is in that room.

I'd copy the pattern from the built-in take command, to make sure it matches all the same cases. And then give it a script like this:

// A list of objects - in case there's objects in the room that can't be taken
limited_objects = Split("bell;book;candle;hat;tea")

// how many the player can take:
objects_to_take = 3

// take the object they've selected
DoTake (object, false)

// check if they've got too many objects
foreach (obj, limited_objects) {
  if (Contains (game.pov, GetObject (obj))) {
    objects_to_take = objects_to_take - 1
  }
}

if (objects_to_take < 0) {
  msg ("This shouldn't be possible, but you've taken too many objects. Please drop one.")
}
else if (objects_to_take = 0) {
  msg ("That's it!")
  MoveObject (game.pov, the next room)
}
else {
  msg ("You can take " + objects_to_take + " more objects.")
}

Update:

Alright, so

  • devilmaymoan's option works, but there's way too many combinations for the game screen. I'm having the player choose from several weapons and there's quite a number of them.
    I'll explore that code a little more and, if anything, I'll chop down the number of given weapons for comfort.

  • mrangel's looks to be exactly what I need, but when I try to configure it with my own objects and rooms the game shows ''Error compiling expression 'object': Unknown object or variable 'object' ''.

It might be that it's messing with my code to give the player a shortsword if they choose to err ''take/pick'' ransack the Swords pile. Once again, I'm a noob, still learning stuff.


Io
mrangel's looks to be exactly what I need, but when I try to configure it with my own objects and rooms the game shows ''Error compiling expression 'object': Unknown object or variable 'object' ''.

I don't think you're supposed to actually put 'object'. Put the name of the object in question.


Hmm… I'm not quite sure, but I would assume the pattern for that command is something like ^(get|take|pick up) (?<object>.+)$ if it's a regular expression? object should be defined.

It might be that it's messing with my code to give the player a shortsword if they choose to err ''take/pick'' ransack the Swords pile.

That's why I called DoTake to do the actual picking up; so that objects with custom take scripts still work fine.
If you've got any other commands which cause the player to gain items, you'd presumably want to change those too.


Here’s what I have done in the past (and I will clarify if needed (just ask)):

I create a integer counter that subtracts from 2. Then I subtract one from that counter if an item is picked up and add one to the counter if the item is dropped. Once two items are picked up the counter reaches zero and I put an if counter equal to zero script on the take command as well prohibiting the player from picking up of a third item.

This works well given that you either close the room, remove the items in question, close the shop... basically you would need to prevent the player from carrying things wherever they want, dropping them, and picking up more than a second item.

Sounds like it might be messy but it is the method that works for me. Let me know if you need to see examples or code.


Do you want to know how I've done it? I 've created an attribute, like player.items = 0 and everytime you take an object, add one to it player.items = player.items + 1.

Then you change the take object's command to a different script.

if (player.items > 9) {
  player.items = player.items + 1
  add to inventory (object)
}
else {
  msg ( "You are carrying too many items." )

You will need to change the drop command's code as well, to subtract one item from the attribute. player.items = player.items - 1

Edit: Needed to add ` things


I took another look over mrangel's suggestion. I thought I figured it out, but now the problems are:

  • When I Play the game and choose the Swords pile it says '' You can't choose it.''
  • Meanwhile for the other piles it drops an ''Error running script: Too many parameters passed to DoTake function - 10 passed, but only 2 expected'' ok nvm solved that somehow

Now I just have all the choices giving me the result that I can't choose them...

Edit: Apparently there was a Verb with ''"You can't choose " + object.article + "." Expression, which I don't remember creating. Alright, well, obviously I'm loosing my mind here.
Taking out the Verb it now prints that it doesn't understand my command in that room so I'm at a loss


What is the pattern for your custom take command?

If it's saying that it doesn't understand your command, possibly the pattern isn't matching the command you typed.

Can you show us the game? Might be easier to find the issue that way.


Oh wait! It works!
There WAS a mistake in the take command pattern I had set. The facepalm was mighty...
The correct pattern that now let's the whole thing work:
take #object#; get #object#; pick up #object#; Choose #object#

Thanks, mrangel!


Log in to post a reply.

Support

Forums