PACKAGE: Inventory Requirement Filter
Search for and install Inventory Requirement Filter
from the Community tab.
DESCRIPTION
Enables verifying a player has a partiular item in their inventory. It is also possible to specify how many that are required. By default, the items are consumed (removed from player inventory), but that can be turned off for re-usable items. If they have the item in their inventory a pass-event will be fired, and if they do not, a fail-event will be fired.
Note: This package requires the official Crayta package Inventory
.
Note: This package can be used in basic mode.
USAGE
Use of this script requires that you already have a script that can perform an action on. Below follows an example for how to do this, but you can use the script for many other things, such as only opening a chest if the user has a key.
- Install the official Crayta package
Inventory
, and set it up. If you use for example the Adventure game template it is already set up for you. - Install the
Inventory Requirement Filter
package. - Install the official Crayta package
Door
. - Drag a door Mesh into your environment.
- Edit the door Mesh, and add the
doorScript
to your door entity. - Add the
inventoryRequirementFilterScript
to your door entity. - In the
inventoryRequirementFilterScript
, setinventoryTemplateRequirement
to a particular item from your inventory. - In the
inventoryRequirementFilterScript
, setonFilteredEventPass
to invoke thedoorScript
of your door entity, and selectdoorScript
in theScript
field. And lastly, selectSetOpen
in theEvent
field. - Edit the
onInteract
field of the entity itself and setEntity
equal to your door,Script
equal to theinventoryRequirementFilterScript
, andEvent
toFilterEventForPlayer
.
This will enable your players to interact with your door. If they do not have the required item, nothing will happen, but if they do have it, the door will open.
SETTINGS
-
inventoryTemplateRequirement
: Which item to look for in the player inventory. -
count
: How many of the specified item to require. -
consumeItems
: Whether to remove the items from the player inventory on success. -
requireItemSelected
: Whether it is required for the item to be selected for the filter to pass. If the player has enough of the specified item, but do not have it currently selected, theonFilteredEventFailNotSelected
event will fire. If they do not have enough items overall, theonFilteredEventFail
will fire. And if they do have enough, theonFilteredEventPass
will fire. Only one of the events will be fired for each filter invocation. Selecting this option displays the newonFilteredEventFailNotSelected
event:
METHODS
-
FilterEventForPlayer(player)
: Checks whether the given player has the item in their inventory or not. FiresonFilteredEventPass
if they do, andonFilteredEventFail
if they do not. IfconsumeItems
is set, consumes the items on success.
EVENTS
-
onFilteredEventPass
: Fired after invokingFilterEventForPlayer(player)
, and the player had enough of the specified item in their inventory. -
onFilteredEventFail
: Fired after invokingFilterEventForPlayer(player)
, and the player did not have enough of the specified item in their inventory. -
onFilteredEventFailNotSelected
: Fired after invokingFilterEventForPlayer(player)
, and the player has enough of the specified item in their inventory, but the item is not currently selected. This event is only fired ifrequireItemSelected
is set to true.