S2ENGINE HD  1.4.6
Official manual about S2Engine HD editor and programming
Items

Items are the components of player inventory. They have two representations: ItemObjects and itemTAGs

ItemObject and ItemTAG

ItemTAG is the item representation before player takes it. It is what you must add into the scene for letting player take it. ItemTAG has a reference to the ItemObject prefab that must be set into the ItemObject parameter.
When the player takes the item ( i.e. it sends the ACTION message to the aimed itemTAG), itemTAG replies to player with a message TAKE specifing the ItemObject prefab filename, the item description (item caption) and the unlimited use flag.

ItemObject executes what the item is built for. For example health itemObject sends an "IncreraseHealth" message to the playerCharacter, and then destroy itself.
It is spawned just when user selects the item icon into the inventory and presses the use button. ItemObject must not be inserted into the scene, it is stored as prefab and referenced by the related itemTAG.

Below is an example of an itemTAG prefab related to the light battery

itemTAG.jpg

Below is the corresponding itemObject for the light battery.

itemObject.jpg
Note
It hasn't a model because it has to only send a RechargeBattery message to the player.

Adding a new Item

For adding a new Item you need:

  • an itemTAG object. You can create it following the Creation procedure (see Creating objects). When creating it you can set its parameters, the most important are:
    1. model: it is the model representing the item in the scene
    2. itemObject: the reference to the itemObject prefab
    3. DestroyWhenTaken: True if you want the itemObject must disappear when player takes it
    4. itemCaption: the description of the item, either when player aims it and when player select it into the inventory
    5. UseWhenTaken: True if you want player to use the item just when taking it (no need to put it into the inventory)
    6. UnlimitedUse: True if you want item count to be infinite (i.e. item can be used as many times as you want from the inventory)
  • an itemObject prefab. You can create it following the Prefab Creation from scratch (see Create Prefabs From Scratch). After creating it you must set its parameters, the most important are:
    1. model: also itemObject could have a model (but usually it is not required)
    2. fsm: the GameMachine FSM itemObject must execute when instanced
    3. icon: the icon that represents the item into the inventory
    4. iconLit: the icon when the item is selected into the inventory
    5. maxCount: the maximum number of items of this type inventory can contain
    6. locked: True if you want the item be unusable until player receives the UNLOCK_ITEM message (see Player Receiving Messages).
    7. TagPrefab: it is the prefab of the related itemTAG, it is needed if you want player can drop items from inventory (see Drop items/weapons).

Creating Item Logic

Usually item logic is made using GameMachine (see GameMachine). Usually the itemObject do some work just when created and then it destroy itself.
The following is an example related to the battery Item in the demo project:

batteryFSM.jpg

As you can see it is a very simple FSM, composed by a single state:

  1. At start The battery item sends RechargeBattery message to the player
  2. Then it destroy itself by setting the died flag