Sphere/Treasure Chest
From Spheriki
Treasure chest are useful things to have in a RPG.
They can hold gold and weapons and anything else you want to put in it.
To begin this tutorial you must first have a spriteset showing a chest in both open and closed form. Put the closed one in "north" direction and the open one in "south" direction.
Then open up your main script file and insert this line of code:
var chest_is_open = false;
This will tell the game that the chest has not yet been open and therefore still contains your items.
Then go into the map you want to have the treasure chest on and choose the location, right-click and choose Insert Entity > Person.
In the name dialogue-box type in a name for your chest. Then type the filename of your spriteset in the filename-box (remember to add ".rss" to the end, e.g. chest.rss)
Then choose "On Activate (Talk)" from the drop-down box. Then paste this into the text box below:
if(chest_is_open == false) { // the chest is open SetPersonDirection("chest", "south"); chest_is_open = true; } else { // the chest is closed }
Let me just run through exacly what the chest will do. First it will find if the chest has been opened before. If it isn't open, it will change the chest sprite's direction to look as if it is open. It will then set the flag to show that it has been open to true, so you cannot receive the same loot again.
Nothing for now will happen if the chest is already flagged as open. If you want to make the chest say what you got from opening it, you will need to set these messages up yourself. Also you will have to have an inventory system if you want your new items to actually appear in your inventory.
If you have any problems email me at helios_gv@hotmail.com or watch out for me in #sphere
JCDenton

