• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

random songs in the same position, rc-sound

Ricardo Berg

New Member
Joined
Mar 16, 2015
Messages
43
Reaction score
2
Hello everybody, is as follows, using the otclient and want to put sounds in the citys my server, and I was wondering how I could put 2 kinds of sounds (Music) at the same coordinates, type, ta person in a "CP" of a poketibia, and ta playing a "just Music" ai one out of cp and come again, will play other types of music, and if the person in and out again this cp, will play another song, and so ^ ^ I will leave on my script "Rc-sound", which is on my desk, and I'll leave a video demonstrating how I want lol, and yes, another issue that created a guy said something, and this can help ^^
Only add various sounds on the table in the same area, then it makes a math.random for when the guy will play a random song.
I do not know what that means "Math.random" and does not know how to do it lol.

Code:
SOUNDS_CONFIG = {
    soundChannel = SoundChannels.Music,
    checkInterval = 500,
    folder = 'music/',
    noSound = 'No sound file for this area.',
}

SOUNDS = {
-- PVP
    {fromPos = {x=936, y=1025, z=13}, toPos = {x=952, y=1043, z=13}, priority = 1, sound="Balada.ogg"},
} ----------

-- Sound
local rcSoundChannel
local showPosEvent
local playingSound

-- Design
soundWindow = nil
soundButton = nil

function toggle()
if soundButton:isOn() then
soundWindow:close()
soundButton:setOn(false)
else
soundWindow:open()
soundButton:setOn(true)
end
end

function onMiniWindowClose()
soundButton:setOn(false)
end

function init()
    for i = 1, #SOUNDS do
        SOUNDS[i].sound = SOUNDS_CONFIG.folder .. SOUNDS[i].sound
    end
   
    connect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
   
    rcSoundChannel = g_sounds.getChannel(SOUNDS_CONFIG.soundChannel)
    -- rcSoundChannel:setGain(value/COUNDS_CONFIG.volume)

    soundButton = modules.client_topmenu.addRightGameToggleButton('soundButton', tr('Sound Info') .. '', '/images/audio', toggle)
    soundButton:setOn(true)
   
    soundWindow = g_ui.loadUI('rcsound', modules.game_interface.getRightPanel())
    soundWindow:disableResize()
    soundWindow:setup()
   
    if(g_game.isOnline()) then
        onGameStart()
    end
end

function terminate()
    disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
    onGameEnd()
    soundWindow:destroy()
    soundButton:destroy()
end

function onGameStart()
    stopSound()
    toggleSoundEvent = addEvent(toggleSound, SOUNDS_CONFIG.checkInterval)
end

function onGameEnd()
    stopSound()
    removeEvent(toggleSoundEvent)
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

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[i].fromPos, SOUNDS[i].toPos)) then
            if(toPlay) then
                toPlay.priority = toPlay.priority or 0
                if((toPlay.sound~=SOUNDS[i].sound) and (SOUNDS[i].priority>toPlay.priority)) then
                    toPlay = SOUNDS[i]
                end
            else
                toPlay = SOUNDS[i]
            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

function playSound(sound)
    rcSoundChannel:enqueue(sound, 0)
    setLabel(clearName(sound))
end

function clearName(soundName)
    local explode = string.explode(soundName, "/")
    soundName = explode[#explode]
    explode = string.explode(soundName, ".ogg")
    soundName = ''
    for i = 1, #explode-1 do
        soundName = soundName .. explode[i]
    end
    return soundName
end

function stopSound()
    setLabel(SOUNDS_CONFIG.noSound)
    rcSoundChannel:stop()
    playingSound = nil
end

function setLabel(str)
    soundWindow:recursiveGetChildById('currentSound'):getChildById('value'):setText(str)
end

 
Last edited:
Hello everybody, is as follows, using the otclient and want to put sounds in the citys my server, and I was wondering how I could put 2 kinds of sounds (Music) at the same coordinates, type, ta person in a "CP" of a poketibia, and ta playing a "just Music" ai one out of cp and come again, will play other types of music, and if the person in and out again this cp, will play another song, and so ^ ^ I will leave on my script "Rc-sound", which is on my desk, and I'll leave a video demonstrating how I want lol, and yes, another issue that created a guy said something, and this can help ^^
Only add various sounds on the table in the same area, then it makes a math.random for when the guy will play a random song.
I do not know what that means "Math.random" and does not know how to do it lol.

SOUNDS_CONFIG = {
soundChannel = SoundChannels.Music,
checkInterval = 500,
folder = 'music/',
noSound = 'No sound file for this area.',
}

SOUNDS = {
-- PVP
{fromPos = {x=936, y=1025, z=13}, toPos = {x=952, y=1043, z=13}, priority = 1, sound="Balada.ogg"},
} ----------

-- Sound
local rcSoundChannel
local showPosEvent
local playingSound

-- Design
soundWindow = nil
soundButton = nil

function toggle()
if soundButton:isOn() then
soundWindow:close()
soundButton:setOn(false)
else
soundWindow:eek:pen()
soundButton:setOn(true)
end
end

function onMiniWindowClose()
soundButton:setOn(false)
end

function init()
for i = 1, #SOUNDS do
SOUNDS.sound = SOUNDS_CONFIG.folder .. SOUNDS.sound
end

connect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })

rcSoundChannel = g_sounds.getChannel(SOUNDS_CONFIG.soundChannel)
-- rcSoundChannel:setGain(value/COUNDS_CONFIG.volume)

soundButton = modules.client_topmenu.addRightGameToggleButton('soundButton', tr('Sound Info') .. '', '/images/audio', toggle)
soundButton:setOn(true)

soundWindow = g_ui.loadUI('rcsound', modules.game_interface.getRightPanel())
soundWindow:disableResize()
soundWindow:setup()

if(g_game.isOnline()) then
onGameStart()
end
end

function terminate()
disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
onGameEnd()
soundWindow:destroy()
soundButton:destroy()
end

function onGameStart()
stopSound()
toggleSoundEvent = addEvent(toggleSound, SOUNDS_CONFIG.checkInterval)
end

function onGameEnd()
stopSound()
removeEvent(toggleSoundEvent)
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

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

function playSound(sound)
rcSoundChannel:enqueue(sound, 0)
setLabel(clearName(sound))
end

function clearName(soundName)
local explode = string.explode(soundName, "/")
soundName = explode[#explode]
explode = string.explode(soundName, ".ogg")
soundName = ''
for i = 1, #explode-1 do
soundName = soundName .. explode
end
return soundName
end

function stopSound()
setLabel(SOUNDS_CONFIG.noSound)
rcSoundChannel:stop()
playingSound = nil
end

function setLabel(str)
soundWindow:recursiveGetChildById('currentSound'):getChildById('value'):setText(str)
end

Please use code tags instead. a part in your script changed it from : open, to :O
 
Code:
SOUNDS_CONFIG = {
soundChannel = SoundChannels.Music,
checkInterval = 500,
folder = 'music/',
noSound = 'No sound file for this area.',
}

SOUNDS = {
-- PVP
{fromPos = {x=936, y=1025, z=13}, toPos = {x=952, y=1043, z=13}, priority = 1, sound="Balada.ogg"},
} ----------

-- Sound
local rcSoundChannel
local showPosEvent
local playingSound

-- Design
soundWindow = nil
soundButton = nil

function toggle()
if soundButton:isOn() then
soundWindow:close()
soundButton:setOn(false)
else
soundWindow:open()
soundButton:setOn(true)
end
end

function onMiniWindowClose()
soundButton:setOn(false)
end

function init()
for i = 1, #SOUNDS do
SOUNDS.sound = SOUNDS_CONFIG.folder .. SOUNDS.sound
end

connect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })

rcSoundChannel = g_sounds.getChannel(SOUNDS_CONFIG.soundChannel)
-- rcSoundChannel:setGain(value/COUNDS_CONFIG.volume)

soundButton = modules.client_topmenu.addRightGameToggleButton('soundButton', tr('Sound Info') .. '', '/images/audio', toggle)
soundButton:setOn(true)

soundWindow = g_ui.loadUI('rcsound', modules.game_interface.getRightPanel())
soundWindow:disableResize()
soundWindow:setup()

if(g_game.isOnline()) then
onGameStart()
end
end

function terminate()
disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
onGameEnd()
soundWindow:destroy()
soundButton:destroy()
end

function onGameStart()
stopSound()
toggleSoundEvent = addEvent(toggleSound, SOUNDS_CONFIG.checkInterval)
end

function onGameEnd()
stopSound()
removeEvent(toggleSoundEvent)
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

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

function playSound(sound)
rcSoundChannel:enqueue(sound, 0)
setLabel(clearName(sound))
end

function clearName(soundName)
local explode = string.explode(soundName, "/")
soundName = explode[#explode]
explode = string.explode(soundName, ".ogg")
soundName = ''
for i = 1, #explode-1 do
soundName = soundName .. explode
end
return soundName
end

function stopSound()
setLabel(SOUNDS_CONFIG.noSound)
rcSoundChannel:stop()
playingSound = nil
end

function setLabel(str)
soundWindow:recursiveGetChildById('currentSound'):getChildById('value'):setText(str)
end


Looooks much better now.
 
Code:
SOUNDS_CONFIG = {
soundChannel = SoundChannels.Music,
checkInterval = 500,
folder = 'music/',
noSound = 'No sound file for this area.',
}

SOUNDS = {
-- PVP
{fromPos = {x=936, y=1025, z=13}, toPos = {x=952, y=1043, z=13}, priority = 1, sound="Balada.ogg"},
} ----------

-- Sound
local rcSoundChannel
local showPosEvent
local playingSound

-- Design
soundWindow = nil
soundButton = nil

function toggle()
if soundButton:isOn() then
soundWindow:close()
soundButton:setOn(false)
else
soundWindow:open()
soundButton:setOn(true)
end
end

function onMiniWindowClose()
soundButton:setOn(false)
end

function init()
for i = 1, #SOUNDS do
SOUNDS.sound = SOUNDS_CONFIG.folder .. SOUNDS.sound
end

connect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })

rcSoundChannel = g_sounds.getChannel(SOUNDS_CONFIG.soundChannel)
-- rcSoundChannel:setGain(value/COUNDS_CONFIG.volume)

soundButton = modules.client_topmenu.addRightGameToggleButton('soundButton', tr('Sound Info') .. '', '/images/audio', toggle)
soundButton:setOn(true)

soundWindow = g_ui.loadUI('rcsound', modules.game_interface.getRightPanel())
soundWindow:disableResize()
soundWindow:setup()

if(g_game.isOnline()) then
onGameStart()
end
end

function terminate()
disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = onGameEnd })
onGameEnd()
soundWindow:destroy()
soundButton:destroy()
end

function onGameStart()
stopSound()
toggleSoundEvent = addEvent(toggleSound, SOUNDS_CONFIG.checkInterval)
end

function onGameEnd()
stopSound()
removeEvent(toggleSoundEvent)
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

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

function playSound(sound)
rcSoundChannel:enqueue(sound, 0)
setLabel(clearName(sound))
end

function clearName(soundName)
local explode = string.explode(soundName, "/")
soundName = explode[#explode]
explode = string.explode(soundName, ".ogg")
soundName = ''
for i = 1, #explode-1 do
soundName = soundName .. explode
end
return soundName
end

function stopSound()
setLabel(SOUNDS_CONFIG.noSound)
rcSoundChannel:stop()
playingSound = nil
end

function setLabel(str)
soundWindow:recursiveGetChildById('currentSound'):getChildById('value'):setText(str)
end


Looooks much better now.




this script ta with math.random for random sounds?
 
Back
Top