Jump to content

Event on sound stop


FatalTerror

Recommended Posts

Long time ago I made a patch for that. I wrote onClientSoundStop and onClientSoundPlay with arguments but it was never amended.

The only way I can think of is creating your own events, setting a timer at the same time as starting sounds, timer will trigger the sound event. Use getSoundLength to get sounds length and the interval for timer.

Link to comment
Long time ago I made a patch for that. I wrote onClientSoundStop and onClientSoundPlay with arguments but it was never amended.

The only way I can think of is creating your own events, setting a timer at the same time as starting sounds, timer will trigger the sound event. Use getSoundLength to get sounds length and the interval for timer.

This will work with sounds played from a file, not live streams, as the length is always 0 for live streams.

Link to comment

you can do getElementsByType("sound") and check when the number of sound elements changes, or use onClientElementDestroy

example code (the onClientSoundPlay is not working 100%, but you didn't really want it soo.. dont mind it)

  
addEventHandler("onClientElementDestroy", getRootElement(), 
function() 
    if(getElementType(source) == "sound")then 
        outputChatBox("Sound stopped: "..tostring(source)) 
    end 
end) 
  
--[[ 
local sounds = getElementsByType("sound") 
  
addEventHandler("onClientRender", getRootElement(), 
function() 
    local s = getElementsByType("sound") 
    if(#s > #sounds)then 
        triggerEvent("onClientSoundPlay", getLocalPlayer(), s[#s]) 
    end 
    if(#s < #sounds)then 
        for i = 1, #sounds do 
            local theSound = searchTable(s, sounds[i]) 
            if not theSound then 
                triggerEvent("onClientSoundStop", getLocalPlayer(), sounds[i]) 
                break 
            end 
        end 
    end 
    if(#s ~= #sounds)then 
        sounds = s 
    end 
end) 
  
addEvent("onClientSoundPlay", true) 
addEventHandler("onClientSoundPlay", getRootElement(), 
function(theSound) 
    outputChatBox("Sound started playing: "..tostring(theSound)) 
end) 
  
addEvent("onClientSoundStop", true) 
addEventHandler("onClientSoundStop", getRootElement(), 
function(theSound) 
    outputChatBox("Sound stopped playing: "..tostring(theSound)) 
end) 
  
function searchTable(tab, var) 
    for k, v in pairs(tab) do 
        if(v == var)then 
            return v 
        end 
    end 
    return false 
end 
--]] 

i commented out script in case you want to add onClientSoundPlay (you only need the onClientElementDestroy for what you asked)

Link to comment
you can do getElementsByType("sound") and check when the number of sound elements changes, or use onClientElementDestroy

example code (the onClientSoundPlay is not working 100%, but you didn't really want it soo.. dont mind it)

  
addEventHandler("onClientElementDestroy", getRootElement(), 
function() 
    if(getElementType(source) == "sound")then 
        outputChatBox("Sound stopped: "..tostring(source)) 
    end 
end) 
  
--[[ 
local sounds = getElementsByType("sound") 
  
addEventHandler("onClientRender", getRootElement(), 
function() 
    local s = getElementsByType("sound") 
    if(#s > #sounds)then 
        triggerEvent("onClientSoundPlay", getLocalPlayer(), s[#s]) 
    end 
    if(#s < #sounds)then 
        for i = 1, #sounds do 
            local theSound = searchTable(s, sounds[i]) 
            if not theSound then 
                triggerEvent("onClientSoundStop", getLocalPlayer(), sounds[i]) 
                break 
            end 
        end 
    end 
    if(#s ~= #sounds)then 
        sounds = s 
    end 
end) 
  
addEvent("onClientSoundPlay", true) 
addEventHandler("onClientSoundPlay", getRootElement(), 
function(theSound) 
    outputChatBox("Sound started playing: "..tostring(theSound)) 
end) 
  
addEvent("onClientSoundStop", true) 
addEventHandler("onClientSoundStop", getRootElement(), 
function(theSound) 
    outputChatBox("Sound stopped playing: "..tostring(theSound)) 
end) 
  
function searchTable(tab, var) 
    for k, v in pairs(tab) do 
        if(v == var)then 
            return v 
        end 
    end 
    return false 
end 
--]] 

i commented out script in case you want to add onClientSoundPlay (you only need the onClientElementDestroy for what you asked)

It work... big thanks :mrgreen:

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...