How to let monsters drop things?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

How to let monsters drop things?

Post by Akatana »

Hello can someone tell me how to let monsters drop things like keys or armor?
BuGi
Posts: 4
Joined: Wed Sep 12, 2012 8:09 pm

Re: How to let monsters drop things?

Post 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,
}
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

Re: How to let monsters drop things?

Post by Akatana »

Thanks works :D
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

Re: How to let monsters drop things?

Post by Akatana »

Ok doesent work...
if i kill the keySnail the game crashes

E: My mistake I was on the wrong level :P
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: How to let monsters drop things?

Post 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.
Steven Seagal of gaming industry
User avatar
resonansER
Posts: 92
Joined: Fri Mar 02, 2012 2:02 pm
Location: Kiev, Ukraine
Contact:

Re: How to let monsters drop things?

Post by resonansER »

I don't understand HOW connect this script with monster. :( Please, show the sample.
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: How to let monsters drop things?

Post 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/
Steven Seagal of gaming industry
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: How to let monsters drop things?

Post 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.
User avatar
resonansER
Posts: 92
Joined: Fri Mar 02, 2012 2:02 pm
Location: Kiev, Ukraine
Contact:

Re: How to let monsters drop things?

Post 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!!! ;)
Moonsprite
Posts: 6
Joined: Wed Sep 12, 2012 7:13 pm

Re: How to let monsters drop things?

Post 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 )
Post Reply