Solarus quests
1.6
Quest maker's reference
|
An equipment item represents something that the player can obtain (one or more times, in various forms and with several variants) and possibly keep. The Lua item type described in this page provides various functions to
A Lua item object represents a kind of treasure, and not a particular instance of treasures. Individual treasures may then be represented as pickable treasures, chests, shop treasures, and may be brandished by the hero. For example, multiple treasures of the kind "rupee"
may exist at the same time during the game, but only one Lua item object manages them.
The script file items/XXXX.lua
defines the item named XXXX
. The corresponding Lua item object is passed as parameter of that script. Use the Lua notation "..."
to get this parameter and store it into a regular variable.
Here is a basic example of script for the rupee
item, an item whose only role is to increase the money of the player when he obtains a rupee.
-- First, we put the parameter into a variable called "rupee". -- (In Lua, the notation "..." refers to the parameter(s) of the script.) local rupee = ... -- Event called when the hero obtains a rupee treasure. function rupee:on_obtaining() self:get_game():add_money(1) -- Increase the money of 1 unit. end
XXXX
must also exist in the sprite entities/items
: it is used by the engine whenever it needs to draw your item on the map (for example, when a pickable treasure of this kind is created on the map).Returns the name of this item.
Returns the game where this item belongs.
Returns the current map.
Returns the name of the integer savegame value that stores the possession state of this item.
nil
if this item is not saved.Sets the name of the integer savegame value that stores the possession state of this item.
You should call this function at initialization time if you want your item to be saved.
savegame_variable
(string): The savegame variable that should stored the possessed variant of this item, or nil
to make this item unsaved.Returns the name of the integer savegame value that stores the amount associated to this item.
nil
if this item has no associated amount.Sets the name of the integer savegame value that stores the amount of this item.
You should call this function at initialization time if you want your item to store an amount (in addition to its possessed variant). This is typically used for items like the bow and the counter of bombs.
nil
to make this item have no associated amount.Returns whether the player is allowed to obtain this item.
If not, any treasure representing this item is automatically replaced by an empty treasure.
true
if this item is obtainable.Sets whether the player is allowed to obtain this item.
If not, any treasure representing this item is automatically replaced by an empty treasure. There is no risk that the player can obtain it or even see it during the game. You can use this feature to hide some items while the player has not the necessary equipment. For example, you can make arrows unobtainable until the player has the bow. You can also make magic jars unobtainable until the player has a magic bar.
true
if this item is obtainable (no value means true
).Returns whether this item can be assigned to an item slot.
When the item is assigned to a slot, the player can use it by pressing the game command of that slot. Some items are meant to be used by pressing a command (like the bow), other are not supposed to (like a key or a rupee). When the player uses your item, the event item:on_using() is triggered.
true
if this item is assignable.Sets whether this item should be assignable to an item slot.
When the item is assigned to a slot, the player can use it by pressing the game command of this slot. Some items are meant to be used by pressing a command (like the bow), other are not supposed to (like a key or a rupee). When the player uses your item, the event item:on_using() is triggered.
By default, an item is not assignable. Call this function at initialization time if you want your item to be assignable.
assignable
(boolean, optional): true
if this item is assignable (no value means true
).Returns whether pickable treasures of this kind disappears after a few seconds when they are dropped by an enemy or a destructible entity.
true
if pickable treasures of this kind can disappear.Sets whether pickable treasures of this kind should disappear after a few seconds when they are dropped by an enemy or a destructible entity.
By default, an item cannot disappear. Call this function at initialization time if you want your item to be ephemeral.
can_disappear
(boolean, optional): true
to make such pickable treasures disappear after a few seconds (no value means true
).Returns whether the hero brandishes treasures of this kind when he picks them on the ground.
true
if the hero brandish such treasures.Sets whether the hero should brandish treasures of this kind when he picks them on the ground.
Treasures coming from a chest are always brandished, even the most basic ones like simple rupees. However, when treasures are picked on the ground (like rupees dropped by an enemy), you may want the hero not to brandish them.
By default, this property is true
. Call this function if you don't want your item to be brandished when it is picked on the ground.
brandish_when_picked
(boolean, optional): true
if the hero should brandish such treasures (no value means true
).Returns the name of the animation representing the shadow of this item in the sprite "entities/shadow"
.
"entities/shadow"
. nil
means no shadow displayed.Sets the name of the animation that should represent the shadow of this item in the sprite "entities/shadow"
.
When the engine needs to show a treasure representing your item, it sometimes also wants to display a shadow (in addition of the treasure's main sprite). For example, pickable treasures dropped by enemies normally have a shadow.
The default shadow animation is "big"
. You should call this function at initialization time if your item sprite is larger or smaller than usual.
shadow_animation
(string): Name of the shadow animation in the sprite "entities/shadow"
to set for this item. nil
means that no shadow will be displayed.entities/item
) and the shadow's sprite (entities/shadow
). Both sprites and their appropriate animations must exist so that treasures can be displayed correctly.Returns the sound played when the hero picks a treasure of this kind.
nil
means no sound).Sets the sound to play when the hero picks a treasure of this kind.
The default sound is "picked_item"
.
sound_when_picked
(string): Name of the sound to play (as in sol.audio.play_sound()) when the hero picks a treasure of this kind (nil
means no sound).true
).Returns the sound played when the hero brandishes a treasure of this kind.
nil
means no sound).Sets the sound to play when the hero brandishes a treasure of this kind.
The hero can brandish treasures in various situations: when opening a chest, when buying a shop treasure, when picking up a pickable treasure (unless you called item:set_brandish_when_picked(false)), and also when you call hero:start_treasure() directly.
The default sound is "treasure"
.
sound_when_brandished
(string): Name of the sound to play (as in sol.audio.play_sound()) when the hero brandishes a treasure of this kind (nil
means no sound).Returns whether the player owns at least the specified variant of this item (only for a saved item).
variant
(number, optional): The variant to check (default 1
).true
if the player has at least this variant.item:get_variant() >= variant
.Returns the possession state of this item (only for a saved item).
0
: not possessed, 1
: first variant, 2
: second variant, etc.).item:get_game():get_value(item:get_savegame_variable())
.Sets the possession state of this item (only for a saved item).
variant
(number): The new possession state to set (0
: not possessed, 1
: first variant, 2
: second variant, etc.)item:get_game():set_value(item:get_savegame_variable(), variant)
.Returns whether this item has an associated amount, or whether the player has at least the specified value.
amount
(number, optional): The amount to check. If this parameter is not set, this function only tests whether an amount value exists for the item.true
if the player has at least that amount. Otherwise, returns true
if the item has an amount value.item:get_amount() >= amount
. Otherwise, this method is equivalent to item:get_amount_savegame_variable() ~= nil
.Returns the amount associated to this item (only for an item with an amount value).
item:get_game():get_value(item:get_amount_savegame_variable())
.Sets the amount associated to this item (only for an item with an amount value). A negative amount will be replaced by 0
. An amount greater than item:get_max_amount() will be replaced by that maximum value.
amount
(number): The amount to set.Increases the amount associated to this item (only for an item with an amount value), without exceeding the maximum amount.
amount
(number): The amount to add.Decreases the amount associated to this item (only for an item with an amount value), without going below 0
.
amount
(number): The amount to remove.Returns the maximum amount associated to this item (only for an item with an amount value).
Sets the maximum amount associated to this item (only for an item with an amount value). This maximum value is used in item:set_amount() and item:add_amount() to make a limit. The default value is 1000
.
max_amount
(number): The maximum amount to set.Returns whether the item is currently being used by the hero.
Notifies the engine that using this item is finished and that the hero can get back to a normal state.
When the player uses this item (by pressing an item game command), your item script takes full control of the hero (event item:on_using() is called) and you have to program the item's behavior. When it is finished, call this function to restore normal control to the player.
This method should only be called when the hero is using this item.
Events are callback methods automatically called by the engine if you define them. In the case of a game, they are only called on the game currently running, if any.
Called when your item script is being created, that is, when the game object is being created.
In this event, you should initialize your item.
Called when your item starts, that is, once all items are created.
At this time, all items scripts are loaded and their on_created() events have been called.
You can use this event to make initializations that depend on other items. Such initializations could not be done earlier from item:on_created(), because all items did not exist at that time.
Called when the game stops running.
Called at each cycle of the main loop while the game is running.
Called when the map is being suspended or resumed. Only possible when the game is running.
The map is suspended by the engine in a few cases, like when the game is paused or when the camera is being moved by a script. When this happens, all map entities stop moving and most sprites stop their animation. Your item may need to be notified.
suspended
(boolean): true
if the map is being suspended, false
if it is being resumed.Called when the player has just entered a map. Only possible when the game is running.
The new map is already started at this point.
map
(map): The new active map.Called when a pickable treasure of your item's kind is created on the map. Only possible when the game is running.
If you need to do something special when a pickable treasure of this kind appears on the map, like setting a particular movement, you can use this event.
pickable
(pickable treasure): The pickable treasure just created.Called when the hero is obtaining a treasure of this kind of item. Only possible when the game is running.
variant
(number): The variant of item (because some items may have several variants). 1
is the first variant, 2
is the second variant, etc.savegame_variable
(string): Name of the boolean saved value that stores the state of the treasure being obtained. nil
means that the treasure is not saved.Like item:on_obtaining(), but called right after the treasure is obtained. Only possible when the game is running.
In the case of a brandished treasure, this event is called once the treasure's dialog is finished. Otherwise, it is called immediately after item:on_obtaining().
variant
(number): The variant of item (because some items may have several variants). 1
is the first variant, 2
is the second variant, etc.savegame_variable
(string): Name of the boolean saved value that stores the state of the treasure just obtained. nil
means that the treasure is not saved.Called when the possessed variant of this item has just changed. Only for saved items.
This event is triggered whenever the variant changes: it can be when the hero obtains a treasure of this item's kind, or when you call item:set_variant() explicitly.
variant
(number): The new variant possessed (possibly 0
).Called when the possessed amount of this item has just changed. Only for items with an associated amount.
This event is triggered when you call item:set_amount(), item:add_amount(), item:remove_amount(),
amount
(number): The new amount possessed (possibly 0
).Called when the player is using this item. Only possible when the game is running, and only for assignable items.
The player is using your item (by pressing an item game command). You now have full control of the hero. From this event, you have to program the item's behavior. For example, your item can remove some magic points and perform an special attack that kills all enemies nearby. When you have finished, call item:set_finished() to restore normal control to the player.
true
, then item:on_using() is not called (the interaction is considered done).Called when the player has just performed a built-in ability. Only possible when the game is running.
Built-in abilities indicate whether the hero can perform some built-in actions like attacking, swimming or running. See game:get_ability() for more details.
ability_name
(string): Name of the ability that was used.Called when the hero interacts (the player pressed the action command) in front of an NPC whose property is to notify your item. Only possible when the game is running.
npc
(NPC): A non-playing character.Called when the hero uses any item (the player pressed an item command) with an NPC whose property is to notify your item. Only possible when the game is running.
npc
(NPC): A non-playing character.item_used
(item): The item currently used by the player. This is not necessarily your item. The reason why your item gets notified is because the NPC is related to your item. But the player may be using another item.true
if an interaction happened. If you return false
or nothing, then item_used:on_using() will be called (just like if there was no NPC in front of the hero).Called when an NPC whose property is to notify your item touches fire. Only possible when the game is running.
npc
(npc): A non-playing character that touches fire and has the property to notify your item.