Jump to content

Mute Problem


Jade

Recommended Posts

-- myonlake Code -- 
  
local _setPlayerMuted = setPlayerMuted 
function setPlayerMuted( player, state ) 
    if ( isElement( player ) ) and ( getElementType( player ) == "player" ) and ( type( state ) == "boolean" ) then 
        if ( _setPlayerMuted( player, state ) ) then 
            if ( state ) then 
                setElementData( player, getResourceName( resource ) .. ":muted", true, true ) 
            else 
                if ( getElementData( player, getResourceName( resource ) .. ":muted" ) ) then 
                    removeElementData( player, getResourceName( resource ) .. ":muted" ) 
                end 
            end 
            return true 
        end 
    end 
    return false 
end 
  
-- Solidsnake14 Code -- 
  
local resName = getResourceName ( getThisResource ( ) ) 
  
addEventHandler ( "onPlayerMute", root, 
    function ( ) 
        setElementData ( source, resName ..":muted", true ) 
    end 
) 
  
addEventHandler ( "onPlayerUnmute", root, 
    function ( ) 
        setElementData ( source, resName ..":muted", false ) 
    end 
) 
 

I've added

Link to comment
  • Moderators

To make everything clear, here is one of the code you should end with:

Server:

local _setPlayerMuted = setPlayerMuted 
function setPlayerMuted( player, state ) 
    if ( isElement( player ) ) and ( getElementType( player ) == "player" ) and ( type( state ) == "boolean" ) then 
        if ( _setPlayerMuted( player, state ) ) then 
            if ( state ) then 
                setElementData( player, getResourceName( resource ) .. ":muted", true, true ) 
            else 
                if ( getElementData( player, getResourceName( resource ) .. ":muted" ) ) then 
                    removeElementData( player, getResourceName( resource ) .. ":muted" ) 
                end 
            end 
            return true 
        end 
    end 
    return false 
end 
  
addEventHandler("onPlayerMute", root, function() 
    setPlayerMuted(source, true) 
end) 
  
addEventHandler("onPlayerUnmute", root, function() 
    setPlayerMuted(source, false) 
end) 

Client:

local screen_width, screen_height = guiGetScreenSize( ) 
addEventHandler( "onClientRender", root, 
    function( ) 
        local is_muted = getElementData( localPlayer, getResourceName( resource ) .. ":muted" ) 
        local mute_text = "Mute: " .. ( is_muted and "Yes" or "No" ) 
        local mute_width, mute_height = dxGetTextWidth( mute_text, 2.0, "default" ), dxGetFontHeight( 2.0, "default" ) 
        dxDrawText( mute_text, screen_width - mute_width - 24, ( screen_height - mute_height ) / 2 + 1, screen_width, screen_height, tocolor( 0, 0, 0, 150 ), 2.0, "default", "left", "top", true, false, post_gui, false, false ) 
        dxDrawText( mute_text, screen_width - mute_width - 25, ( screen_height - mute_height ) / 2, screen_width, screen_height, tocolor( 255, is_muted and 0 or 255, is_muted and 0 or 255, 230 ), 2.0, "default", "left", "top", true, false, post_gui, false, false ) 
    end 
) 

There is no reason it shouldn't work (restart the right resource, not admin one)

Link to comment
To make everything clear, here is one of the code you should end with:

Server:

local _setPlayerMuted = setPlayerMuted 
function setPlayerMuted( player, state ) 
    if ( isElement( player ) ) and ( getElementType( player ) == "player" ) and ( type( state ) == "boolean" ) then 
        if ( _setPlayerMuted( player, state ) ) then 
            if ( state ) then 
                setElementData( player, getResourceName( resource ) .. ":muted", true, true ) 
            else 
                if ( getElementData( player, getResourceName( resource ) .. ":muted" ) ) then 
                    removeElementData( player, getResourceName( resource ) .. ":muted" ) 
                end 
            end 
            return true 
        end 
    end 
    return false 
end 
  
addEventHandler("onPlayerMute", root, function() 
    setPlayerMuted(source, true) 
end) 
  
addEventHandler("onPlayerUnmute", root, function() 
    setPlayerMuted(source, false) 
end) 

Client:

local screen_width, screen_height = guiGetScreenSize( ) 
addEventHandler( "onClientRender", root, 
    function( ) 
        local is_muted = getElementData( localPlayer, getResourceName( resource ) .. ":muted" ) 
        local mute_text = "Mute: " .. ( is_muted and "Yes" or "No" ) 
        local mute_width, mute_height = dxGetTextWidth( mute_text, 2.0, "default" ), dxGetFontHeight( 2.0, "default" ) 
        dxDrawText( mute_text, screen_width - mute_width - 24, ( screen_height - mute_height ) / 2 + 1, screen_width, screen_height, tocolor( 0, 0, 0, 150 ), 2.0, "default", "left", "top", true, false, post_gui, false, false ) 
        dxDrawText( mute_text, screen_width - mute_width - 25, ( screen_height - mute_height ) / 2, screen_width, screen_height, tocolor( 255, is_muted and 0 or 255, is_muted and 0 or 255, 230 ), 2.0, "default", "left", "top", true, false, post_gui, false, false ) 
    end 
) 

There is no reason it shouldn't work (restart the right resource, not admin one)

i bug full mute not work unmute

ERROR: S.lua:4: C stack overflow

Link to comment
local resName = getResourceName ( getThisResource ( ) ) 
  
addEventHandler ( "onPlayerMute", root, 
    function ( ) 
        setElementData ( source, resName ..":muted", true ) 
    end 
) 
  
addEventHandler ( "onPlayerUnmute", root, 
    function ( ) 
        setElementData ( source, resName ..":muted", false ) 
    end 
) 

Use that code ALONE.

Link to comment
addEventHandler ( "onPlayerUnmute", root, 
    function ( ) 
        outputChatBox ( "UNMUTED PLAYER!" ) 
    end 
) 
  
addEventHandler ( "onPlayerMute", root, 
    function ( ) 
        outputChatBox ( "MUTED! PLAYER" ) 
    end 
) 

/mute Player

Chat:

MUTED! PLAYER

MUTED! PLAYER

/unmute Player

Chat:

UNMUTED PLAYER!

MUTED! PLAYER

Why twice and unmute incorrect?

w10GWN.png

Link to comment

I know why, it's because the admin panel triggers it's own "onPlayerMute" event.

addEventHandler ( "onPlayerMute", root, 
    function ( state ) 
        if ( state == true or state == false ) then 
            setElementData ( source, getResourceName ( getThisResource ( ) ) ..":muted", state ) 
        end 
    end 
) 

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...