Script:inventory playeradd: Difference between revisions

From Arx Libertatis Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 31: Line 31:


{{Notice|In version before {{Changelog|1.3}} the icon file at the default path must also exist or the item will not be created, even for gold coins, movable items or items that change the icon in the {{Event|load}} event.}}
{{Notice|In version before {{Changelog|1.3}} the icon file at the default path must also exist or the item will not be created, even for gold coins, movable items or items that change the icon in the {{Event|load}} event.}}
[[Category:Script commands creating entities]]


== Entity ID ==
== Entity ID ==


The ID of the created entity can be retrieved via the <code>^last_spawned</code> [[Script:Variables#System variables|system variable]]. It will be made up of the filename component of the script path (the entity class) followed by <code>_</code> and a previously unused four-digit instance number - meaning one that does not have an instance directory in the game resources under the script path and does not have an existing entity in the current area or save file.
The ID of the created entity can be retrieved via the <code>^last_spawned</code> [[Script:Variables#System variables|system variable]]. It will be made up of the filename component of the script path (the entity class) followed by <code>_</code> and a previously unused four-digit instance number - meaning one that does not have an instance directory in the game resources under the script path and does not have an existing entity in the current area or save file.
[[Category:Script commands creating entities]]

Revision as of 10:54, 19 June 2022

The inventory playeradd script command is used to create a single new item and place it into the player inventory. New items will be assigned an unused instance number which means that it is not possible to create items with instance scripts using this command (or any other script command). This command only creates item entities - to create entities of other types use spawn or replaceme.

The created item will be sent the load, init and initend events (in that order).

The item will be combined into existing stacks in the player inventory if possible which may result in the created item being destroyed again. If the item does not fit into the player inventory or cannot be put into inventories then it is dropped in front of the player instead. Equipment items are first identified before being placed in the inventory which, if successful, results in the identify event being sent to the entity.

This command is equivalent to inventory playeraddmulti <script> 1 except that this command does not (re)set the maximum count to 9999 and count to 1 after the load, init and initend events have executed.

To add an existing item instead of creating a new one use inventory playeraddfromscene.

To add an item to the inventory of a non-player entity use inventory addfromscene, inventory add or inventory addmulti instead.

⚠️
This command has no effect while re-loading an area that was already visited before, e.g. in the reload event.

Usage

inventory playeradd <script>

Context: Ignored

Parameters:

ParameterTypeDescription
script path Script path (without file extension) of the entity to add, relative to graph/obj3d/interactive/items

Script path

The entity class script is loaded from graph/obj3d/interactive/items/<script>.asl.

If the filename component of the script path starts with gold_coin gold coin then the item will be treated as a gold coin which is added to the player's purse instead of the inventory.

If the script path contains the string movable then the item will not be possible to add to inventories and is dropped in front of the player instead.

The initial mesh of the item will be graph/obj3d/interactive/items/<script>.teo with the cooked mesh loaded from game/graph/obj3d/interactive/items/<script>.ftl. Either the raw mesh, cooked mesh or entity class script file must exist or the item will not be created.

The initial icon of the item will be graph/obj3d/interactive/items<script>[icon] if it exists or graph/interface/misc/default[icon] otherwise. The icon size determines how many slots the item takes up in inventories except for movable items (which have no icon) and gold coins (where the icon depends on the price).

ℹ️  In version before Arx Libertatis 1.3 the icon file at the default path must also exist or the item will not be created, even for gold coins, movable items or items that change the icon in the load event.

Entity ID

The ID of the created entity can be retrieved via the ^last_spawned system variable. It will be made up of the filename component of the script path (the entity class) followed by _ and a previously unused four-digit instance number - meaning one that does not have an instance directory in the game resources under the script path and does not have an existing entity in the current area or save file.