This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
item_pickup_tutorial [2018/03/07 19:53] – justin | item_pickup_tutorial [2018/03/07 20:47] – justin | ||
---|---|---|---|
Line 3: | Line 3: | ||
(WIP) | (WIP) | ||
- | This tutorial will explain how to set up map [[object|objects]] as [[item|items]] for the player to pick up, for example a key that the player can pick up by walking into/over it and then use to open a door or treasure chest. | + | This tutorial will explain how to set up map [[object|objects]] as [[item|items]] for the [[player_character|player]] to pick up, for example a key that the [[player_character|player]] can pick up by walking into/over it and then use to open a door or treasure chest. |
**Note:** This tutorial assumes that you already understand the basics of using the RPG in a Box editors, in particular the [[Map Editor]] and [[Voxel Editor]]. | **Note:** This tutorial assumes that you already understand the basics of using the RPG in a Box editors, in particular the [[Map Editor]] and [[Voxel Editor]]. | ||
=====Creating the Object Model===== | =====Creating the Object Model===== | ||
- | |||
Open the [[New Resource Dialog]] and create a new [[object]]. Once the [[Voxel Editor]] opens for the new [[object]] model, use the [[voxel]] tools to build a key as shown below (or whatever will best visually represent the [[item]]). | Open the [[New Resource Dialog]] and create a new [[object]]. Once the [[Voxel Editor]] opens for the new [[object]] model, use the [[voxel]] tools to build a key as shown below (or whatever will best visually represent the [[item]]). | ||
Line 17: | Line 16: | ||
{{: | {{: | ||
- | Before proceeding to the next section, you can optionally create a " | + | Before proceeding to the next section, you can optionally create a " |
- | Create | + | =====Defining the Item===== |
+ | In addition to the [[object]] model, you'll also need to define the corresponding [[item]] that the [[player_character|player]] will receive | ||
{{: | {{: | ||
- | Optional: create sound effect for picking | + | Remember the name you used for your item (including case) as it will be referenced in a [[quick script]] later on. Click the " |
+ | |||
+ | =====Creating a Sound Effect===== | ||
+ | Optionally, you can create | ||
{{: | {{: | ||
- | Place object into map in desired location | + | Once you are happy with the [[sound]], click the "Save Sound" button ({{: |
+ | |||
+ | =====Setting Up the Object in a Map===== | ||
+ | Open the [[map]] where you'd like to have the [[item]] pickup. Select the [[object]] model you created earlier from the resource container on the right, then place the [[object]] onto an open [[tile]] | ||
{{: | {{: | ||
- | Open properties dialog for object and assign an entity | + | Switch into " |
{{: | {{: | ||
- | Open properties | + | Double-click the [[tile]] underneath the [[object]] (or right-click on it and select " |
+ | |||
+ | Copy and paste the [[script]] source code below into the dialog as shown. You may need to make a few adjustments according to the names you chose earlier on, in particular the entity ID for the [[object]] (" | ||
<code lua> | <code lua> | ||
Line 45: | Line 53: | ||
{{: | {{: | ||
+ | |||
+ | To better understand what the [[script]] is doing, I've included explanations for each line. | ||
+ | |||
+ | <code lua> | ||
+ | set_entity_script(self, | ||
+ | </ | ||
+ | |||
+ | This line removes the [[script]] from the [[entity]] that activated it (" | ||
+ | |||
+ | <code lua> | ||
+ | remove_entity(entity[" | ||
+ | </ | ||
+ | |||
+ | This line removes the physical key [[object]] from the scene by referring to the unique [[entity]] ID we assigned to the key earlier on in the [[Map Editor]]. The ID inside the quotes should exactly match the ID that was assigned to the [[object]] earlier on from its [[Entity Properties]] dialog. | ||
+ | |||
+ | <code lua> | ||
+ | play_sound(" | ||
+ | </ | ||
+ | |||
+ | This line plays the [[sound|sound effect]] named " | ||
+ | |||
+ | <code lua> | ||
+ | give_item(" | ||
+ | </ | ||
+ | |||
+ | This line puts the [[item]] named "Gold Key" into the [[player_character|player' | ||
+ | |||
+ | =====Testing the Pickup In-Game===== | ||
Finished! Save map and export game, player will now "pick up" key when walking onto the tile. | Finished! Save map and export game, player will now "pick up" key when walking onto the tile. |