Containers Help

There are two things I’d like to learn how to achieve. I’d like to have an object tha can only hold one specific object, and I’d also like to make containers that can only contain certain types of objects.


There's a space on the containers tab for a script that runs when the player attempts to put an object in a container.

If you want to only allow a certain object to put in there, you'd make it something like:

if (object = red ball) {
  msg ("You put it in.")
  MoveObject (object, destination)
}
else {
  msg ("That object won't fit.")
}

(obviously, changing red ball to the name of the object that will go in there, and changing the messages as appropriate)

For multiple objects that can go in, there are two common methods.
First, giving the object an attribute. For example, a mailbox might have:

if (GetBoolean (object, "has_stamp")) {
  msg ("You post the " + GetDisplayAlias (object) + ".")
  MoveObject (object, destination)
}
else {
  msg ("You should put a stamp on the " + GetDisplayAlias (object) + " before you put it in the mailbox.")
}

You can use whatever attribute you want. Within the add script, object will be the object and destination will be the container.

The other method would be having a specific list of objects:

switch (object) {
  case (thimble, needle, spool, toy soldier, dice, dice2, dormouse) {
    msg ("You put it in.")
    MoveObject (object, destination)
  }
  default {
    msg ("It won't fit.")
  }
}

If some of the objects have their own drop script (for example, a magic ring that disintegrates when you take it off), your script would be a little more complex. For example:

if (HasInt (object, "size")  and GetInt (object, "size") < 15) {
  if (HasScript (object, "drop")) {
    do (object, "drop", QuickParams ("object", object, "destination", destination))
  }
  else {
    msg ("You put the " + GetDisplayAlias (object) + " in the box.")
    MoveObject (object, destination)
  }
}
else {
  msg ("It won't fit.")
}

(note that if you are using containers, any drop scripts should always use the variable destination to determine where the player is trying to put the object. A lot of people seem to miss that detail, and you end up with the situation where the player does "put ring in box" and the ring ends up on the floor)


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

Support

Forums