Page 2 of 2

Re: Scripts help

Posted: Mon Dec 31, 2012 1:46 am
by Drakkan
xbdj wrote:Got it:

cloneObject{
name = "snail_drop",
baseObject = "snail",
onDie = function(self)
spawn("rock", self.level, self.x, self.y, self.facing)
end,
}


Add this to your monster.lua file (and edit text as necessary ofcourse)
and then simply spawn a "snail_drop" instead of a snail...or whatever monster it is you need to drop it
I tried this:
cloneObject{
name = "skeleton_Iron_Key",
baseObject = "skeleton_patrol",
onDie = function(self)
spawn("iron_key", self.level, self.x, self.y, self.facing)
end,
}

working fine with single monster like skeleton_warrior etc....
not working for skeleton_patrol :/
made some tests and items are not spawning for single group of monsters :/ Any ideas ?

Re: Scripts help

Posted: Mon Dec 31, 2012 2:07 am
by xbdj
Hmmm...weird...I just tried it and - as you say - it doesnt work with patrols!

Sorry...Im all out of ideas now

Re: Scripts help

Posted: Mon Dec 31, 2012 3:12 am
by Hariolor
Drakkan wrote:Hello everybody,

2. It is possible to script somehow that object "spawner" (creature) will drop some item after killing ?
EDIT: solved for single monster. However still not working for group of single monsters (like skeleton_patrol)

thats all for now, thanks
see this thread

viewtopic.php?f=14&t=3194&hilit=additem&start=20

patrols are made up of groups of single monsters - AFAIK nobody has yet come up with a method to use an addItem() with a patrol successfully.

Re: Scripts help

Posted: Mon Dec 31, 2012 4:15 am
by Diarmuid
Hi, I managed to do it!

While working on my EXSP framework, I spent two days doing tests to detect monster groups properly. So here's for you a function that returns a table of all individual monsters in a monster group:

Code: Select all

function getMonsterGroup(level, x, y)
	local monstersTable = {}
	for i in entitiesAt(level,x,y) do
		if i.class == "Monster" then
			table.insert(monstersTable, i)
		end	
	end
	return monstersTable
end
So I used this code to add a brass key to the first skeleton in a patrol which was at 1, 6, 4:

Code: Select all

	local monsters = getMonsterGroup(1,6,4)
	monsters[1]:addItem(spawn("brass_key"))
Enjoy! 8-)

Re: Scripts help

Posted: Mon Dec 31, 2012 5:19 am
by Komag
you could maybe set up an onDie hook to search and see if they are the last to die, and if so, spawn the key