Twin custom sounds for standard LoG lever
By Germanny 01/2014



- Copy the *.wav soundfiles to "mod_assets/samples/env/"
- Add these definitions to "sounds.lua":

--snip--------------------------------------------------------

	defineSound{
        name = "lever",
        filename = "mod_assets/samples/env/lever_nil.wav",
        loop = false,
        volume = 1,
        minDistance = 1,
        maxDistance = 8,
    }

    defineSound{
        name = "dm_lever_on",
        filename = "mod_assets/samples/env/dm_lever_on.wav",
        loop = false,
        volume = 1,
        minDistance = 1,
        maxDistance = 10,
    }

	defineSound{
        name = "dm_lever_off",
        filename = "mod_assets/samples/env/dm_lever_off.wav",
        loop = false,
        volume = 1,
        minDistance = 1,
        maxDistance = 10,
    }

------------------------------------------------------snap--

- Set some levers in the Dungeon
- Place this script into a new ScriptEntity into your dungeon:
  (Name of the script entity: ' leverSndSet ')

--snip--------------------------------------------------------

-- Set connectors to all levers in dungeon (thx to Isaac!)
for l = 1, getMaxLevels() do
      for e in allEntities(l) do
         if  e.class == "Lever" then
            e:addConnector('any', 'leverSndSet', 'playLvSnd')
         end
         end
end

-- The function to play custom sounds
function playLvSnd(dmDungLev)

-- declare and set variables
lvState = dmDungLev:getLeverState()
lvLevl = dmDungLev.level
lvNam = dmDungLev.name
lvFac = dmDungLev.facing
lvPosX = dmDungLev.x
lvPosY = dmDungLev.y

-- Display lever states on screen - for debugging, remove this
hudPrint(lvState..", "..lvNam..", "..lvPosX..", "..lvPosY..", "..lvFac)

-- OK, this was a fault with my soundsystem.. ignore this xD - Correct the position for playSoundAt()
-- if lvFac == 0 then lvPosY = lvPosY-1      -- if lever Facing North
-- elseif lvFac == 1 then lvPosX = lvPosX+1  -- if lever Facing West
-- elseif lvFac == 2 then lvPosY = lvPosY+1  -- if lever Facing South
-- else lvPosX = lvPosX-1                    -- if lever Facing East
-- end

-- play sounds for each state
if lvState == 'activated' and lvNam == 'lever' then
	playSoundAt("dm_lever_on", lvLevl, lvPosX, lvPosY)

elseif lvState == 'deactivated' and lvNam == 'lever' then
	playSoundAt("dm_lever_off", lvLevl, lvPosX, lvPosY)

-- BEGIN paste (new lever definition name and sound name here)



-- END paste

end
end

------------------------------------------------------snap--


**
If you want to add a new custom lever, replace placeholder names
with yours and paste into ScriptEntity 'leverSndSet':

--snip--------------------------------------------------------

elseif lvNam == 'MyNewLeverName' and lvState == 'activated' then
	playSoundAt("MyNewLeverActivSound", lvLevl, lvPosX, lvPosY)

elseif lvNam == 'MyNewLeverName' and lvState == 'deactivated' then
	playSoundAt("MyNewLeverDeactivSound", lvLevl, lvPosX, lvPosY)

------------------------------------------------------snap--

