This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
item_pickup_tutorial [2018/03/07 19:59] – justin | item_pickup_tutorial [2018/03/07 20:58] (current) – justin | ||
---|---|---|---|
Line 1: | Line 1: | ||
======Item Pickups====== | ======Item Pickups====== | ||
- | + | 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. | |
- | (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. | + | |
**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 13: | ||
{{: | {{: | ||
- | Before proceeding to the next section, you can optionally create a " | + | Before proceeding to the next section, you can optionally create a " |
=====Defining the Item===== | =====Defining the Item===== | ||
- | Create | + | In addition to the [[object]] model, you'll also need to define the corresponding [[item]] that the [[player_character|player]] will receive |
{{: | {{: | ||
+ | |||
+ | 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===== | =====Creating a Sound Effect===== | ||
- | Optional: | + | Optionally, you can create |
{{: | {{: | ||
- | ======Setting Up the Object in a Map===== | + | Once you are happy with the [[sound]], click the "Save Sound" button ({{: |
- | Place object into map in desired location | + | =====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 50: | Line 51: | ||
{{: | {{: | ||
- | =====Testing | + | 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]] 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' | ||
+ | |||
+ | Click the " | ||
- | Finished! Save map and export | + | =====Testing the Pickup In-Game===== |
+ | [[exporting_your_game|Export the game]] to try out your new [[item]] pickup. The [[player_character|player]] should | ||
{{: | {{: | ||