Random Sounds on a level

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Random Sounds on a level

Post by Eleven Warrior »

Hi guys I used this Script in my mod it makes a random sounds in the level but I cannot get it work now. I got this from Mines Of Mulan. I do hope someone can get this to work Thxs :) There's some Kudos in it for you lol

1 Timer Called: soundtimer - seconds = 30
1 Counter Called: finalcounter - Value = 0

A plate is connected to timer and the timer is connected to the function: function horrorsounds() and the counter can be on any level or just one level. Here is the Code:

Code: Select all

function horrorsounds()

if finalcounter:getValue() == 0 then

xpos = 0
ypos = 0
local random = math.random(2)

	if random == 1 then
	xpos = party.x + 1 + math.random(4)
	else
	xpos = party.x - 1 - math.random(4)
	end
	
local random = math.random(2)

	if random == 1 then
	ypos = party.y + 1 + math.random(4)
	else
	ypos = party.y - 1 - math.random(4)
	end

local plev = party.level

local random = math.random(10)

	if random == 1 then
	playSoundAt("mine_horror01",plev,xpos,ypos)
	elseif random == 2 then
	playSoundAt("mine_horror02",plev,xpos,ypos)
	elseif random == 3 then
	playSoundAt("mine_horror03",plev,xpos,ypos)
	elseif random == 4 then
	playSoundAt("mine_horror04",plev,xpos,ypos)
	elseif random == 5 then
	playSoundAt("mine_horror05",plev,xpos,ypos)
	elseif random == 6 then
	playSoundAt("mine_horror06",plev,xpos,ypos)
	elseif random == 7 then
	playSoundAt("mine_horror07",plev,xpos,ypos)
	elseif random == 8 then
	playSoundAt("mine_horror08",plev,xpos,ypos)
	elseif random == 9 then
	playSoundAt("mine_horror09",plev,xpos,ypos)
	elseif random == 10 then
	playSoundAt("mine_horror10",plev,xpos,ypos)
	end
	
	local random = math.random(40) + 20
	soundtimer:setTimerInterval(random)

end

end
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Random Sounds on a level

Post by GoldenShadowGS »

I cleaned it up a bit:

Code: Select all

function horrorsounds()
	local xpos = 0
	local ypos = 0
	local random = 0
	local plev = party.level
	if finalcounter:getValue() == 0 then
		random = math.random(2)
		if random == 1 then
			xpos = party.x + 1 + math.random(4)
		else
			xpos = party.x - 1 - math.random(4)
		end
		random = math.random(2)
		if random == 1 then
			ypos = party.y + 1 + math.random(4)
		else
			ypos = party.y - 1 - math.random(4)
		end
		random = math.random(10)
		if random == 1 then
			playSoundAt("mine_horror01",plev,xpos,ypos)
		elseif random == 2 then
			playSoundAt("mine_horror02",plev,xpos,ypos)
		elseif random == 3 then
			playSoundAt("mine_horror03",plev,xpos,ypos)
		elseif random == 4 then
			playSoundAt("mine_horror04",plev,xpos,ypos)
		elseif random == 5 then
			playSoundAt("mine_horror05",plev,xpos,ypos)
		elseif random == 6 then
			playSoundAt("mine_horror06",plev,xpos,ypos)
		elseif random == 7 then
			playSoundAt("mine_horror07",plev,xpos,ypos)
		elseif random == 8 then
			playSoundAt("mine_horror08",plev,xpos,ypos)
		elseif random == 9 then
			playSoundAt("mine_horror09",plev,xpos,ypos)
		elseif random == 10 then
			playSoundAt("mine_horror10",plev,xpos,ypos)
		end
		random = math.random(40) + 20
		soundtimer:setTimerInterval(random)
	end
end
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Random Sounds on a level

Post by Eleven Warrior »

WOW Thxs Shadow awesome work man thxs :D
Post Reply