Help needed - Random Monster Spawner Script require - Solved

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
jpaf84
Posts: 10
Joined: Sun Mar 03, 2013 1:13 am

Help needed - Random Monster Spawner Script require - Solved

Post by jpaf84 »

Hi, I've been messing with the editor and I'm on the process of building a new dungeon.
I've got some levels already done, but I'm not very good with scripting.
In one level I decided I should have a random spawner for monsters. The player steps into a pressure plate and "puff" two random monsters appear in the next two corridors.

I've been doing this the hard way. I've set up a room with several monsters and a few teleporters deactivated. What I'm doing is activating those teleporters for a brief moment letting some monsters "squeeze" into the corridors.

What I would like to do is use a script instead. I've been looking for scripts and found something that I thought it could help me, so I modified it a bit but I'm not getting the script to work. Any help would be appreciated.
I believe the original script that I tried to adapt was for counting the number of monsters from a list.

here is what I was thinking:

Code: Select all

-- RANDOM MONSTER 
function spawnR()
monsters = {"snail","herder","crowern","ogre"}
random_monster = math.random(1,#monsters)
spawn("random_monster", 16, 20, 11, 2)
end
The error I'm getting says: undefined object:random_monster
The problem seems to be on my 3rd line of code, I believe I need something completely different in there.

Can someone help?
Last edited by jpaf84 on Thu Apr 18, 2013 6:41 am, edited 2 times in total.
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Help needed - Random Monster Spawner Script required

Post by alois »

jpaf84 wrote:

Code: Select all

-- RANDOM MONSTER 
function spawnR()
monsters = {"snail","herder","crowern","ogre"}
random_monster = math.random(1,#monsters)
spawn("random_monster", 16, 20, 11, 2)
end
The error I'm getting says: undefined object:random_monster
The problem seems to be on my 3rd line of code, I believe I need something completely different in there.

Can someone help?
The problem with the script is that 'random_monster' is a number between 1 and 4; that line should be

Code: Select all

random_monster = monsters[math.random(1,#monsters)]
i.e., you have to 'select' an element of the table corresponding to the random number you pick.

Ah, and also the 'spawn' command should be

Code: Select all

spawn(random_monster, 16, 20, 11, 2)
i.e., without the quotation marks (or otherwise LoG looks for a monster whose name is "random_monster").

alois :)
jpaf84
Posts: 10
Joined: Sun Mar 03, 2013 1:13 am

Re: Help needed - Random Monster Spawner Script required

Post by jpaf84 »

Nice, thanks for the fast answer.
That worked well.
Now I just need to align the monster list with the level section to be more thematic, and replace the coordinates from my test chamber to the real corridors.

Code: Select all

-- RANDOM MONSTER SPAWNER
function spawnR()
monsters = {"snail","herder","crowern","ogre"}
random_monster = monsters[math.random(1,#monsters)]
spawn(random_monster, 16, 20, 11, 2)
end
Post Reply