Adding to Scope

I get the feeling this is so obvious I'm just trying to hard, I wand to add the inventory of a backpack a player is carrying to their scope.

The basic effect I want is a backpack that can be closed to hide all of its contents and clean up the inventory pane, however I want those items to also be reachable for various checks . For example if you have a shovel in your backpack you'll be able to dig a hole even if it's not in your hand at the moment


If you're using the desktop editor, look for the hidden function CanReachThrough and modify it.

The default code is:

  <function name="CanReachThrough" type="boolean" parameters="obj">
    return (GetBoolean(obj, "isopen") and not GetBoolean(obj, "hidechildren"))
  </function>

for this specific case, you could do something like:

  <function name="CanReachThrough" type="boolean" parameters="obj">
    return (obj = backpack or (GetBoolean(obj, "isopen") and not GetBoolean(obj, "hidechildren")))
  </function>

If you're using the online editor, you can't edit the core functions. So you'll have to use one of the extra features added in Quest 5.8. In your start script, you can put something like:

game.changecommandscope => {
  if (ListContains (items, backpack) and not GetBoolean (backpack, "isopen")) {
    foreach (obj, GetAllChildObjects (backpack)) {
      if (ContainsReachable (backpack, obj)) {
        list add (items, obj)
      }
    }
  }
}

This adds a script attribute which will be run after determining the list of objects in scope for a command. Its code basically breaks down to:

  • If the backpack is in the list of available items and is closed
    • Repeat for every object in the backpack
      • If the object is reachable within the backpack (visible and not inside another closed container in there)
        • Add that object to items

Hope that helps! I've not tested this, but I'm pretty confident it should work.


Oh that sounds good, and don't feel quite as foolish, did not think to look for the already present hidden functions, will work on it today

edit Well. that brought up a very odd issue, for some reason adding that code broke the hiding effect of closing the backpack, Tried to get around that by fiddling with scripts to make anything put into the pack become scenery but still appears in the inventory list


Ah… I didn't think about that. Yeah, you'd probably also need to change the logic in CanSeeThrough.

The second method, the one I suggested for the online editor, might have a different problem… The script attribute game.changecommandscope basically adds objects to scope after the usual scope stuff is done… although it wouldn't work with commands which check in their own script if an object is reachable.


Log in to post a reply.

Support

Forums