How to let monsters drop things?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
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 »

Moonsprite wrote:
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 )
I UNDERSTAND!!! THANK YOU SO MUCH! COOL!!! I create first snail who dropped key! THANK YOU!!! :shock: ;) :D :D

And thank you for this, antti!:
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.
Cool!
Last edited by resonansER on Thu Sep 13, 2012 9:35 pm, edited 1 time in total.
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 »

Please note:

The engine can support items carried by individual monsters without needing to clone the base monster type. There's just an oversight that this functionality is not exposed in the scripting interface / inspector. So it's not recommended that you clone the monster type but unfortunately that seems to be the only way with beta-1.2.6. Next update should fix this.

Also check out "lootDrop" property in monster definitions. It's a bit easier to use than onDie.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: How to let monsters drop things?

Post by Grimwold »

any help on how to format lootDrop: I cloned a skeleton warrior to change the loot drops and none of them dropped anything.

This is the code I put in monsters.lua

Code: Select all

cloneObject{
        name = "skeleton_warrior",
        baseObject = "skeleton_warrior",
        lootDrop = { 65, “legionary_spear”, 55, “legionary_shield”, 45, "legionary_helmet" }
}
Edit: I've also had the editor completely crash twice now, when attacking a modified skeleton warrior (possibly at the point of death??)
Last edited by Grimwold on Sun Sep 16, 2012 1:58 am, edited 1 time in total.
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

Re: How to let monsters drop things?

Post by Akatana »

65 + 55 + 45 = 165

I think 100% is the highest maybe they don't drop because its over 100% (9000!)
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: How to let monsters drop things?

Post by Grimwold »

Akatana wrote:65 + 55 + 45 = 165

I think 100% is the highest maybe they don't drop because its over 100% (9000!)
I didn't think it was additive.. how else could skeleton warriors drop both shield and spear every time otherwise?
User avatar
Billick
Posts: 201
Joined: Thu Apr 19, 2012 9:28 pm

Re: How to let monsters drop things?

Post by Billick »

I think you need a comma after your lootDrop definition.
Halls of Barrian - current version 1.0.3 - Steam Nexus
Me Grimrock no bozo!
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: How to let monsters drop things?

Post by Grimwold »

after a little experimentation, the following worked to some degree:

Code: Select all

lootDrop = {50, "legionary_spear", 25, "legionary_shield", 25, "legionary_helmet"}
however I hardly ever got a helmet
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Re: How to let monsters drop things?

Post by SpacialKatana »

Okay, the following is crashing my game/editor when I kill the monster, but I don't get why. I have an item called orb_of_power cloned from a golden orb. The monster has 1 health and increment for testing purposes....

cloneObject{
name = "uggardian_orb2",
baseObject = "uggardian",
health = 1,
healthIncrement = 1,
sight = 6,

onDie = function(self)
spawn("orb_of_power", self.level, self.x, self.y, self.facing, "orb2")
uggdoor1:open()
end
}
User avatar
Akatana
Posts: 42
Joined: Tue Apr 10, 2012 11:07 pm

Re: How to let monsters drop things?

Post by Akatana »

Code: Select all

cloneObject{
name = "uggardian_orb2",
baseObject = "uggardian",
health = 1,
healthIncrement = 1,
sight = 6,

onDie = function(self)
spawn("orb_of_power", self.level, self.x, self.y, self.facing)
uggdoor1:open()
end
}
try this :)
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Re: How to let monsters drop things?

Post by SpacialKatana »

Fixed.

The code was fine, I'd forgotten to delete the object (ID orb2) from another level, the ID clash was crashing the game :)
Post Reply