I UNDERSTAND!!! THANK YOU SO MUCH! COOL!!! I create first snail who dropped key! THANK YOU!!!Moonsprite wrote:It took me awhile to figure this out as well (I'm new to this scripting stuff too).resonansER wrote:I don't understand HOW connect this script with monster. Please, show the sample.
The principle behind this is that you are making a new monster that has an attribute that on its death, it will drop a key.
So:
- first I'd suggest you close the editor (I'd guess all assets are loaded when you first start and/or open your project) If the editor is running it won't see the new monster.
- in your 'scripts' folder on your harddisk within your project folder, open the file 'monsters.lua'.
- Add the script mentioned above
- save and exit file.
- start your editor and open your current project (thats where the edited monsters.lua file resides within)
- you should now find you have a new asset (called 'KeySnail' if you named it as the above script).
- now whenever you use this asset/monster, it will drop a key or its death (so only use this monster once, or if you have a hundred locked doors, use this monster another 99 times )
And thank you for this, antti!:
Cool!antti wrote: I'd slightly tweak the spawning like so:
spawn("iron_key", self.level, self.x, self.y, self.facing)
None of those tweaks might not be absolutely necessary in this case but they will make the script a little more robust and flexible. Using self.level instead of 2 means that the script will work no matter what floor the creature is on. self.facing is just a "nice touch" so that the item is spawned according to the monster's orientation. And finally, I left out the ID, which is an optional parameter. This means that there will be no trouble with clashing IDs if you would want to, for some reason, use multiple snails like these.