Put ALL/MULTIPLE - How can we set this up?

Hello.

It seems like we covered this a couple of years ago...

I came up with code, but it was no good. I remember that, and I can find that forum thread.

It seems like mrangel or Pixie posted some good code, though, but I can't find it.

Here's how I'd like it to work:

>PUT BLUE EGG AND RED EGG IN BASKET
Blue egg: Done.
Red egg: Done.


>INVENTORY
You are carrying a blue egg, a red egg and a green egg.

>PUT ALL BUT GREEN EGG IN BASKET
Blue egg: Done.
Red egg: Done.


>INVENTORY
You are carrying a blue egg, a red egg and a green egg.

>PUT EVERYTHING EXCEPT GREEN EGG IN BASKET
Blue egg: Done.
Red egg: Done.


>INVENTORY
You are carrying a blue egg, a red egg and a green egg.

>PUT ALL IN BASKET
Blue egg: Done.
Red egg: Done.
Green egg: Done.


>PUT BLUE EGG IN BASKET
Done.



I've tried a few things, but I'm obviously not tuned into the correct frequency to code such things today.

Currently working on this game in Quest 5.8.0, by the way.


What I've got going on right now:

  <command name="put">
    <pattern type="string"><![CDATA[^(put|insert|place|drop) (?<object1>.*) (on to|onto|in to|into|on|in) (?<object2>.*)$]]></pattern>
    <scope>object1=inventory|object2=container</scope>
    <synonyms type="stringlist">
      <value>put</value>
      <value>insert</value>
      <value>place</value>
      <value>drop</value>
    </synonyms>
    <allow_all />
    <script><![CDATA[
      put_something = false
      // msg (multiple)
      // msg (object1)
      // msg (object2)
      // msg ("<hr/>")
      if (multiple) {
        if (ListCount(object2) > 1) {
          msg ("object2 can't be multiple!")
        }
        else {
          object2 = ListItem(object2,0)
          object1 = ListExclude(object1, object2)
          foreach (obj, object1) {
            if (not GetBoolean(obj, "worn")) {
              Tell (CapFirst(GetDisplayAlias(obj))+": ")
              if (obj = object2) {
                msg ("You can't put something into itself.")
              }
              else {
                HandlePut (obj, object2)
                put_something = true
              }
            }
          }
        }
        if (not put_something) {
          msg ("You didn't put anything anywhere!")
        }
      }
      else {
        object1 = ListItem(object1,0)
        object2 = ListItem(object2,0)
        if (object1 = object2) {
          msg ("You can't put something into itself.")
        }
        else {
          HandlePut (object1, object2)
        }
      }
    ]]></script>
  </command>

  <function name="HandlePut" parameters="object1, object2">
    // put object1 in/on object 2
    canbedropped = true
    if (HasBoolean(object1, "drop")) {
      if (not object1.drop) {
        canbedropped = false
      }
    }
    if (object1.parent = object2) {
      msg (DynamicTemplate("AlreadyThere", object1))
    }
    else if (not ListContains(ScopeInventory(), object1)) {
      msg (DynamicTemplate("NotCarrying", object1))
    }
    else if (not canbedropped) {
      if (HasString(object1,"dropmsg")) {
        msg (object1.dropmsg)
      }
      else {
        msg (DynamicTemplate("ObjectCannotBeStored", object1))
      }
    }
    else if (not ListContains(ScopeReachable(), object1)) {
      msg (BlockingMessage(object1, ""))
    }
    else if (not ListContains(ScopeReachable(), object2)) {
      msg (BlockingMessage(object2, ""))
    }
    else if (not object2.container) {
      msg (Template("CannotDoThat"))
    }
    else if (not object2.isopen) {
      msg (DynamicTemplate("ObjectNotOpen", object2))
    }
    else if (ListContains(ListParents(object2), object1)) {
      msg (Template("CannotDoThat"))
    }
    else if (not TestDropGlobal(object1, "")) {
      // Do nothing, already handled
    }
    else {
      if (GetBoolean(object2, "hidechildren")) {
        object2.hidechildren = false
      }
      params = NewDictionary()
      dictionary add (params, "object", object1)
      dictionary add (params, "destination", object2)
      if (HasScript(object2, "addscript")) {
        do (object2, "addscript", params)
      }
      else if (HasScript(object1, "drop")) {
        do (object1, "drop", params)
      }
      else {
        object1.parent = object2
        msg (Template("Done"))
      }
    }
    // must be carrying object1
    // item cannot be dropped
    // object1 must not be inside a closed container
    // object2 must not be inside a closed container
    // object2 must be an open container or surface
    // object1 is inside object 2
  </function>

It seems to work, but I normally overlook at least one thing.


PS

The responses in the command's script are mostly just placeholders, until I make sure it's all working correctly.


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

Support

Forums