Disabling the use of anything in the inventory.

Good evening,

Long story short:


I want to be able to forbid the player from interacting with/looking at/using/etc anything in the inventory (but only the inventory).
Is this possible without having to script individually for every single item?



Slightly longer story:


I want to simulate the use of a backpack. When the player picks it up the inventory pane (called "backpack") shows up.
If the player drops the backpack the pane disappears. All this is working already.
But the thing is the player can still interact with all the stuff in the inventory which makes no sense if he/she drops the backpack in one room and then enters another.
In reality everything's still there of course, in the inventory, just not visible (because of the lack of pane. They're not invisible per say). But I want it to seem like it's not.
I guess would I would really need is some sort of, in pseudo MakeObjectsInvisible (EverythingInInventory)

Any thoughts on the matter?


UNTESTED

After dropping the backpack:

foreach (o, ScopeInventory()){
  o.visible = false
}

After picking it up:

foreach (o, ScopeInventory()){
  o.visible = true
}

WARNING!

I am 99% sure DROP ALL will drop invisible objects!


This doesn't sound very realistic to me, but I don't really know the context.

My line of thinking:

I pick up a stick.

I pick up a backpack.

I drop my backpack.

My stick is gone?


Now, if I actually PUT things in the backpack, that would make sense.

...or if it said, "you pick it up and put it in your backpack," each time I took something, that might not upset me during play. But, if this message was printing, that would mean the TAKE script had to be modified, so it would make more sense to actually move the object into the backpack. Then, when you drop the backpack, that stuff is in the backpack, not in inventory. Problem solved.


So, the way Quest already has containers set up makes more sense to me, but, again, I don't know the context.


Thanks K.V. I'll try it out!
If it works, which I'm sure it will, you just saved me a whole lot of unnecessary work!


(edit: small typo)

You could change the changedparent script on the defaultobject type so that picking up an object automatically puts it in the backpack. Then when you drop the backpack you won't be able to use them; but you will be able to open it and take one item with you.

Here's an example off the top of my head:

    <changedparent type="script">
      if (game.pov = this) {
        if (IsDefined("oldvalue")) {
          OnEnterRoom(oldvalue)
        }
        else {
          OnEnterRoom(null)
        }
        if (game.gridmap) {
          MergePOVCoordinates
        }
      }
      else if (this.parent = game.pov) {
        if (not this = backpack) {
          if (backpack.parent = this.parent) {
            this.parent = backpack
          }
          else if (ListCount(ScopeInventory()) > 2) {
            msg ("You need a backpack if you want to carry more than two items")
            this.parent = oldvalue
          }
        }
      }
      this.hasbeenmoved = true
    </changedparent>

Or a slightly sillier version:

    <changedparent type="script">
      if (game.pov = this) {
        if (IsDefined("oldvalue")) {
          OnEnterRoom(oldvalue)
        }
        else {
          OnEnterRoom(null)
        }
        if (game.gridmap) {
          MergePOVCoordinates
        }
      }
      else if (this.parent = game.pov) {
        if (not this = backpack) {
          if (backpack.parent = this.parent) {
            items_in_hands = FilterByNotAttribute(ListExclude(GetDirectChildren(game.pov), backpack), "visible", false)
            if (ListCount(items_in_hands) > 2) {
              if (backpack.parent = game.pov) {
                picked_item = PickOneObject (items_in_hands)
                msg ("Your hands are full, so you put "+GetDisplayName(picked_item)+" in "+GetDisplayName(backpack)+".")
                picked_item.parent = backpack
              }
              else {
                msg ("Your hands are full. You probably need "+GetDisplayName(backpack)+".")
              }
            }
          }
        }
      }
      this.hasbeenmoved = true
    </changedparent>

If the backpack is either open or transparent, you can use items inside it as if they were in your inventory; and then when you put it down, you can use them as if they were in the room.

The latter version gives the player a little more control. They can put as many items as they want in their backpack, and hold 2 in their hands; and automatically put one at random into the backpack if you type "get" when their hands are full.


That's pretty much exactly what I was going for. I see now (when reading your code) that I woldn't have figured it out myself.
Thanks a lot Mrangel!!


Log in to post a reply.

Support

Forums