Multiple Item Requirements?

Cadam

I want an event to happen, but only if the player has multiple objects in their inventory. I can do it if they have one, but is there a way I can make it so it will only work if they have, say... two or three items?


XanMag

Well, there are multiple ways to do this (EDIT: see my next post first maybe?).

I would use an integer attribute because I know how to use them. There is probably a way to use the if (Got(object one)) with the AND code bit, but I don't know how to do it! WARNING: this might be the most difficult way, but it does work as I just tested it out. Also, if you are not familiar with using and changing attributes, they are INCREDIBLY handy.

Anyway...

  1. I created an "object" called carryinv and added an integer attribute to it with the name of carrying and set the integer to 0 (zero). I placed the "carryinv" object in a warehouse/storage room. I just needed an object to place my attributes on.
  2. I have three objects that I eloquently called 'one', 'two', and 'three'.
    3a. On the inventory tab of each object I chose the 'set variable' script and typed the following in the first box: carryinv.carrying
    3b. I left the drop down as expression and typed the following in the second box: carryinv.carrying + 1
  3. Don't forget to add a script to add the object to your inventory and a message indicating the object has been taken.
  4. I copy-pasted this same code for objects two and three and just changed the add to inventory to the appropriate object.
  5. I repeated this for the drop script except I changed the + to a - and moved the appropriate object to current room.
  6. I have an NPC in my last room and added a speak to verb on them. In the speak to verb box I choose an 'If' script. I chose If 'object attribute equals' and typed in the object box carryinv and in the attribute box carrying equals 3
  7. Then... printed message saying "Congrats, you are carrying all three". In the Else part of this script I printed a message saying "You need to be carrying all the objects."

Below is the entire code if you want to copy-paste it in a new game and look at it in the GUI. Or just ask questions if you need clarification. Good luck!

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="multiple conditions integer count test">
    <gameid>9657b4b7-fc77-4047-b97b-cdce39d3b6a0</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="one">
      <inherit name="editor_object" />
      <take type="script">
        carryinv.carrying = carryinv.carrying + 1
        AddToInventory (one)
        msg ("Taken.")
      </take>
      <drop type="script">
        carryinv.carrying = carryinv.carrying - 1
        MoveObjectHere (one)
        msg ("Dropped.")
      </drop>
    </object>
    <object name="two">
      <inherit name="editor_object" />
      <take type="script">
        carryinv.carrying = carryinv.carrying + 1
        AddToInventory (two)
        msg ("Taken.")
      </take>
      <drop type="script">
        carryinv.carrying = carryinv.carrying - 1
        MoveObjectHere (two)
        msg ("Dropped.")
      </drop>
    </object>
    <object name="three">
      <inherit name="editor_object" />
      <take type="script">
        carryinv.carrying = carryinv.carrying + 1
        AddToInventory (three)
        msg ("Taken.")
      </take>
      <drop type="script">
        carryinv.carrying = carryinv.carrying - 1
        MoveObjectHere (three)
        msg ("Dropped.")
      </drop>
    </object>
    <exit alias="south" to="room2">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="room2">
    <inherit name="editor_room" />
    <exit alias="north" to="room">
      <inherit name="northdirection" />
    </exit>
    <exit alias="south" to="room3">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="room3">
    <inherit name="editor_room" />
    <exit alias="north" to="room2">
      <inherit name="northdirection" />
    </exit>
    <object name="MRCounter">
      <inherit name="editor_object" />
      <alias>Mr. Counter</alias>
      <speak type="script">
        if (carryinv.carrying = 3) {
          msg ("Congratulations.  You are carrying all three objects needed to pass the test.")
        }
        else {
          msg ("You are not carrying all the items you need.  Find them all.")
        }
      </speak>
    </object>
  </object>
  <object name="warehouse">
    <inherit name="editor_room" />
    <object name="carryinv">
      <inherit name="editor_object" />
      <carrying type="int">0</carrying>
    </object>
  </object>
</asl>

XanMag

Just thought of this but haven't tested it...

Wherever you have the checkpoint for carrying all the objects, you could try this (the object names are still one, two, and three):

If script.

if (one.parent = player and two.parent = player and three.parent = player) {
msg ("You are carrying all three objects! Congrats!)

In the GUI, that would be If 'object attribute equals' object expression 'one.parent = player and two.parent = player and three.parent = player' equals attribute 'parent' = 'player'

In the Then part of this script, run whatever scripts you want to run for the player carrying all the object (this is where I printed the congrats message).

In the Else part of the script you would just run whatever scripts you want to let the player know they are not carrying everything they need.

Might be worth a shot because it is less coding.


hegemonkhan

for a small number of Objects and simplistically (not scalable nor re-usable):

if (Got (NAME_OF_OBJECT_1) and Got (NAME_OF_OBJECT_2) and Got (NAME_OF_OBJECT_3)) {
  // scripting
}

or (if you want to check for a lot of Objects):

// (this uses the same method as XanMag mentions/uses in his post: an Integer Attribute for counting/tallying the number of and out of the total desired/needed Objects to be in your inventory, using iteration, for if there's a lot of Objects)

// give/create/add an Objectlist Attribute to some Object, and add in the names of the Object that you're checking for, for example:

game.example_objectlist_attribute = split ("NAME_OF_OBJECT_1; NAME_OF_OBJECT_1; NAME_OF_OBJECT_2; NAME_OF_OBJECT_3; NAME_OF_OBJECT_4; NAME_OF_OBJECT_5", ";")

// scripting:

counting_integer_variable = 0
foreach (object_variable, game.example_objectlist_attribute) {
  if (Got (object_variable)) {
    counting_integer_variable = count_integer_variable + 1
  }
}
if (counting_integer_variable = ListCount (game.example_objectlist_attribute)) {
  // your scripting
}

though, how/when/where you implement it, is another matter...

ask if you need any help or have questions about anything


Cadam

Thank you :3


Log in to post a reply.

Support

Forums