Inventory Display with stacked object

Ok. I have an item "Healing Potions". When the player gets one I just increase the quantity of the object. I want the object to display in inventory like "Healing Potions (x2)". I've tried several ways and coming up for broke. How would I accomplish this? I tried using the listalias but that does nothing. Here is what I have so far.

  <object name="potionstack">
    <inherit name="editor_object" />
    <look><![CDATA[{img:Healing_Potion_card.png}<br/><br/>The liquid burns your throat like bitter fire but quickly heals open wounds and broken bones. When you drink this potion, you recover half of your maximum stamina.]]></look>
    <attr name="feature_usegive" type="boolean">false</attr>
    <take />
    <quantity type="int">1</quantity>
    <alias type="string"></alias>
    <listalias type="script">
      potionstack.listalias = "Healing Potion (x" + potionstack.quantity + ")"
    </listalias>
    <ontake type="script"><![CDATA[
      if (potionstack.quantity < 3) {
        potionstack.quantity = potionstack.quantity + 1
      }
      else {
        msg ("You cannot carry more than three healing potions")
      }
      potionstack.listalias = "Healing Potion (x" + potionstack.quantity + ")"
    ]]></ontake>
    <drink type="script">
      if (player.staminacurrent = player.staminamax) {
        msg ("Your stamina is at maximum. You decide not to waste the potion.")
      }
      else {
        msg ("You recover half of your maximum stamina and toss the bottle away.")
        potionstack.quantity = potionstack.quantity - 1
        if (potionstack.quantity = 0) {
          RemoveObject (potionstack)
        }
        player.staminacurrent = player.staminacurrent + (player.staminamax / 2)
        potionstack.listalias = "Healing Potion (x" + potionstack.quantity + ")"
      }
    </drink>
    <use type="script">
    </use>
    <drop type="boolean">false</drop>
    <inventoryverbs type="stringlist">
      <value>Look at</value>
      <value>Drink</value>
    </inventoryverbs>
  </object>

This looks a little weird.

You have an item called potionstack which has an initial quantity attribute set tyo 1. When you pick it up, it increases this to 2, and sets its listalias to "Healing potion (x2)".

Normally if you have a stacking system, you would have some way to have multiple of the same object. There are two different ways to do this:

  1. You have a potionstackobject that the player starts off with (but its quantity might start at 0). Other potion objects can be found, and they have a take script which removes them from the game and increases the quantity of the potionstack instead.

  2. All potions are the same (without a separate stack object). When you pick up the first one it is taken normally, but if you pick up a second potion it removes itself from the game and increases the quantity on the first one instead.

I'm not sure which one of these you're working with. If you have a separate potion object that the player can pick up, it might be worth showing us the script for that object. That's more likely where your problem lies.

If you're cloning your potionstack, the script you have won't work because you're changing potionstack.listalias (the list alias of the original) rather than this.listalias (the listalias of the one that the player is currently interacting with). So you'd need to guarantee that the one in the player's inventory is the original one.


This is the only object. It has an initial starting stack of 1 because when I give it to the player it is a single item. Then later, as I give him more, it increases the quantity. The object and the code work in game, my issue is that in my inventory I can only show it as "Healing Potion". I'm trying to have it show the quantity of the stack in the inventory window.


when I give it to the player it is a single item.

If the player picks it up, they will have 2, because it adds 1 when it is picked up.

If you give it to the player without them using the 'take' command, your ontake script is never run, so the listalias is never set.


I use a Text Processor directive in my stackables' aliases and listaliases, e.g.: olive oil ({olive_oil_player.qty}). This object's name is olive_oil_player and it has a qty integer attribute. So when it is displayed, it reads: olive oil (5), if the qty is 5. Whenever the qty value changes, the alias and listalias seem to update automatically.

I also have 2 objectstacks for EACH real stackable object in my game, e.g.: olive_oil_player is a single objectstack that is moved into the player's inventory when the qty is more than zero, and olive_oil_clone is a single objectstack that is cloned and placed in the room when "discovered" or dropped. Actually, I also have a 3rd objectstack olive_oil_merch that is only interacted with whenever the player buys that object from a merchant.

When my stackables are taken or dropped, I run my own take or drop functions to handle everything. Admittedly, they are a bit complicated.


Log in to post a reply.

Support

Forums