AddToInventory

From Who's Angel?
Jump to: navigation, search

This is a piece of code I created in response to a query on the Quest forum, but for some unknown reason the forum's adult-content filter wouldn't allow me to post it. So here it is!

 <function name="AddToInventory" parameters="object" type="string">
   message = null
   foreach (bag, FilterByType (ScopeInventory (), "inventorybag")) {
     message = ""
     if (object.parent = bag) {
       return ("It is already in your "+GetDisplayName (bag)+".")
     }
     if (HasInt (bag, "maxvolume")) {
       if (GetVolume(object, true) + GetVolume(bag, false) > bag.maxvolume) {
         if (HasString(bag, "containerfullmessage")) {
           message = bag.containerfullmessage
         }
         else {
           message = DynamicTemplate("ContainerFull", bag)
         }
       }
     }
 
     if (HasInt (bag, "maxobjects")) {
       if (ListCount (GetDirectChildren (bag)) >= bag.maxobjects and bag.maxobjects > 0) {
        if (HasString(bag, "containermaxobjects")) {
           message = bag.containermaxobjects
         }
         else {
           message = DynamicTemplate("MaxObjectsInContainer", bag)
         }
       }
     }
     if (message = "") {
       object.parent = bag
       return ("You put " + object.article + " in your " + GetDisplayName(bag) + ".")
     }
   }
   if (message = null) {
     // This is what will happen if the player isn't carrying a bag/satchel.
     // Depending on your game setup, this might never happen;
     // or you might allow the player to carry 2 objects in their hands.
     object.parent = game.pov
     return ("You pick it up.")
   }
   else {
     return (message)
   }
 </function>