Page 1 of 2

How to let monsters drop things?

Posted: Thu Sep 13, 2012 5:30 pm
by Akatana
Hello can someone tell me how to let monsters drop things like keys or armor?

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 5:40 pm
by BuGi
Did this by cloning the monster I wanted to use and using the onDie hook to spawn an item on its location.
For example:

Code: Select all

cloneObject{
	name = "keySnail",
	baseObject = "snail",
	
	onDie = function(self)
		spawn("iron_key", 2, self.x, self.y, 1, "ironKey1")
	end,
}

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 5:55 pm
by Akatana
Thanks works :D

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 6:01 pm
by Akatana
Ok doesent work...
if i kill the keySnail the game crashes

E: My mistake I was on the wrong level :P

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 6:27 pm
by antti
BuGi wrote:Did this by cloning the monster I wanted to use and using the onDie hook to spawn an item on its location.
For example:

Code: Select all

cloneObject{
	name = "keySnail",
	baseObject = "snail",
	
	onDie = function(self)
		spawn("iron_key", 2, self.x, self.y, 1, "ironKey1")
	end,
}
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.

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 6:40 pm
by resonansER
I don't understand HOW connect this script with monster. :( Please, show the sample.

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 7:13 pm
by antti
resonansER wrote:I don't understand HOW connect this script with monster. :( Please, show the sample.
The cloneObject in this case is put into monsters.lua under your custom dungeon's mod_assets\scripts folder using a text editor. See these documents for the basics on creating custom assets and using script hooks, such as onDie:
http://www.grimrock.net/modding/creating-custom-assets/
http://www.grimrock.net/modding/scripting-hooks/

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 7:21 pm
by petri
There seems to be an oversight in the scripting interface. There is actually a much simpler way to make monsters carry items but it seems to have been left out from the scripting interface. Should be fixed with the next update.

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 7:49 pm
by resonansER
petri wrote:There seems to be an oversight in the scripting interface. There is actually a much simpler way to make monsters carry items but it seems to have been left out from the scripting interface. Should be fixed with the next update.
I'll be appreciate it you for this!!! ;)

Re: How to let monsters drop things?

Posted: Thu Sep 13, 2012 7:57 pm
by Moonsprite
resonansER wrote:I don't understand HOW connect this script with monster. :( Please, show the sample.
It took me awhile to figure this out as well (I'm new to this scripting stuff too).

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 :D )