Ir para conteúdo

Featured Replies

Postado

testa ae :

require('advsound')


require('ex')

SOUNDS_CONFIG = {
folder = 'mods/Advanced Sound/audio/',
loop=false,
start_paused=false,
checkInterval = 500,
}



local UPDATESOUND_OPCODE = 85
local PAUSESOUND_OPCODE = 81

SOUNDS = {--area sounds
{fromPos = {x = 157, y = 42, z = 7}, toPos = {x = 168, y = 56, z = 7},priority = 1, sound = "startup.ogg"},
}
local toggleSoundEvent
local e
local playingSound
local audio = nil
local window = nil
local volume = 100
local str
function init()
connect(g_game, { onGameEnd = terminate })
window = modules.client_options.audioPanel
str = string.explode(window:getChildById('musicSoundVolumeLabel'):getText(), ":")
volume = tonumber(str[2])
ProtocolGame.registerExtendedOpcode(UPDATESOUND_OPCODE, getSound)
ProtocolGame.registerExtendedOpcode(PAUSESOUND_OPCODE, pauseSound)
e = cycleEvent(iniciar, SOUNDS_CONFIG.checkInterval)
end
function iniciar()
if (g_game.isOnline()) then
removeEvent(e)
toggleSoundEvent = addEvent(startAsound, SOUNDS_CONFIG.checkInterval)
end
end

local m
function toggleSound()
local player = g_game.getLocalPlayer()
if not player then return end

local pos = player:getPosition()
local toPlay = nil

for i = 1, #SOUNDS do
if(isInPos(pos, SOUNDS.fromPos, SOUNDS.toPos)) then
if(toPlay) then
toPlay.priority = toPlay.priority or 0
if((toPlay.sound~=SOUNDS.sound) and (SOUNDS.priority>toPlay.priority)) then
toPlay = SOUNDS
end
else
toPlay = SOUNDS
end
end
end

playingSound = playingSound or {sound='', priority=0}

if(toPlay~=nil and playingSound.sound~=toPlay.sound) then
g_logger.info("RC Sounds: New sound area detected:")
g_logger.info(" Position: {x=" .. pos.x .. ", y=" .. pos.y .. ", z=" .. pos.z .. "}")
g_logger.info(" Music: " .. toPlay.sound)
stopSound()
playSound(toPlay.sound)
playingSound = toPlay
elseif(toPlay==nil) and (playingSound.sound~='') then
g_logger.info("RC Sounds: New sound area detected:")
g_logger.info(" Left music area.")
stopSound()
end

toggleSoundEvent = scheduleEvent(toggleSound, SOUNDS_CONFIG.checkInterval)
end

local music
function getSound(protocol, opcode, buffer)
local cof = string.explode(buffer, "|")
local conff = {
["true"] = true,
["false"] = false,
}
music = advsound.playMusic(SOUNDS_CONFIG.folder..cof[1], conff[cof[2]], SOUNDS_CONFIG.start_paused)
str = string.explode(window:getChildById('musicSoundVolumeLabel'):getText(), ":")
volume = tonumber(str[2])
advsound.setVolume(music, volume/100)
end


function pauseSound(protocol, opcode, buffer)
if opcode == 81 then
advsound.pauseAll()
end
end

function terminate()
disconnect(g_game, { onGameEnd = terminate })
e = cycleEvent(iniciar, SOUNDS_CONFIG.checkInterval)
audio = nil
advsound.pauseAll()
end

function isInPos(pos, fromPos, toPos)
return
pos.x>=fromPos.x and
pos.y>=fromPos.y and
pos.z>=fromPos.z and
pos.x<=toPos.x and
pos.y<=toPos.y and
pos.z<=toPos.z
end


 

 

  • Respostas 8
  • Visualizações 957
  • Created
  • Última resposta

Top Posters In This Topic

  • 7 months later...
  • 2 weeks later...

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo