how to "action" when monster dies.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: how to "action" when monster dies.

Post by Blichew »

I found out how I did onDie function on my squishy version of skeleton warrior with 10 HP:

I require the player to kill 4 of them before the door opens.
I made a counter KillCount_1 with a value of 4
I made a script KillCount_lua with a function that plays a sound after each kill and opens the door when it reaches 0 (Of course this part can be done by only linking the counter to the door)

Code: Select all

cloneObject{
	name = "squishy_skeleton_warr",
	baseObject = "skeleton_warrior",
	health = 10,
	
	onDie = function(self)
		local kc = KillCount_1
		local kcl = KillCount_lua
		kc:decrement()
		kcl:checkNumber()
	end
}
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Re: how to "action" when monster dies.

Post by SpacialKatana »

Have you tested this by using the 'k' method to kill monsters? I had no luck before doing this, but was using 'k' to quick kill. The counter never fired it's triggers for me.
User avatar
HaunterV
Posts: 676
Joined: Mon Apr 16, 2012 9:54 pm
Location: Barrie, Ontario, Canada

Re: how to "action" when monster dies.

Post by HaunterV »

this is still beyond me... i'll try to understand it again in a few more months.

For now...I'll just use practical nuts & bolts methods.
Grimrock Community 'FrankenDungeon 2012. Submit your entry now!: http://tinyurl.com/cnupr7h
SUBMIT YOUR ASSETS! Community Asset Pack (C.A.P.): http://tinyurl.com/bqvykrp
Behold! The HeroQuest Revival!: http://tinyurl.com/cu52ksc
davehca
Posts: 21
Joined: Sat Sep 15, 2012 6:09 pm

Re: how to "action" when monster dies.

Post by davehca »

I was able to get a monster's death to open a door using the following:

Code: Select all

cloneObject {
	name = "snail2",
	baseObject = "snail",

	onDie = function(self) 
 		dungeon_door_iron_1:open()
	end,
}
If it returns "false" then when the monster "dies" it doesn't really, but the door still opens. What's funny is if I set to toggle() and return false, after the initial "death" the door will toggle with each whack made against the creature.
User avatar
Kuningas
Posts: 268
Joined: Wed Apr 11, 2012 10:29 pm
Location: Northern Finland

Re: how to "action" when monster dies.

Post by Kuningas »

I am battling with this problem as well, and I suppose many will be doing likewise in the future, so I humbly suggest adding this topic to the modding superthread.

I am trying to do a room with 3 slimes, so that when you kill them, the last one you kill always has a green gem item. I've simplified by isolating one of the slimes for testing purposes (the one to be killed last), and I've managed to build a functioning counter that will run a lua script entity on the map when you kill a slime. The script is then supposed to check if the counter equals 2 (in other words, 2 of the three slimes killed), and if it is so, it will place the green_gem item on the remaining slime. The thing is, the last part doesn't work, apparently. I don't know the reason. My codes are as follows.

The onDie function with the slime:

Code: Select all

	onDie = function(self)
		local s = slimekillcounter
		local sl = givegemscript
		s:increment()
		sl:givegem()
	end,
"slimekillcounter" is the counter on the map
"givegemscript" is the script entity.
This part seems to work correctly, but I am not entirely sure.

This is the script entity (simplified for testing, the final product would be threefold)

Code: Select all

function givegem()
	if slimekillcounter == 2 then
		if not findEntity("sewer_slime_1") and not findEntity("sewer_slime_2") then
		sewer_slime_3:addItem("green_gem") else
		nothing()
		end
	end
end
I killed the slimes using conventional means and I have verified the counter works as intended. The problem is probably in the latter part.
BASILEUS
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: how to "action" when monster dies.

Post by Komag »

I've never tried "if not" stuff. Maybe put in some print messages to test where it's breaking down. Try one right after the test to find the two slimes.
Finished Dungeons - complete mods to play
User avatar
Kuningas
Posts: 268
Joined: Wed Apr 11, 2012 10:29 pm
Location: Northern Finland

Re: how to "action" when monster dies.

Post by Kuningas »

Weird -- as a matter of fact it seems it is the addItem function that isn't working -- I can't add anything to the slimes even through console. It always gives the same error: "(Item expected, got ???)".

This is... perplexing. All the other lines work fine alone.

EDIT: Wait, you don't suppose it wants the UI name? Gotta check... EDIT2: aaand no...
BASILEUS
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: how to "action" when monster dies.

Post by Komag »

you could try nesting in a spawn command in place of "green_gem", sometimes it works with those but not with direct items
Finished Dungeons - complete mods to play
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: how to "action" when monster dies.

Post by petri »

addItem() expects an Item and "green_gem" is not an Item, it's a string. An Item is an object returned by e.g. spawn("green_gem"). Hope this helps!
User avatar
Trollmann
Posts: 24
Joined: Sun Apr 15, 2012 6:31 pm

Re: how to "action" when monster dies.

Post by Trollmann »

hello there everybody, I've been doing my dungeon for several days now, and I've come to point where I need to add snail farm, but I don't know where to start.
I've tried some scripting and at this point I can get 3 snails spawned at random intervals, but I don't know how to make them do a decrement as they die.
I'm still kinda noob with LUA, so even the basics can be hard :P

Some help would be appreciated.
Post Reply