Jade Posted February 26, 2014 Author Share Posted February 26, 2014 problem /start script - Mute: No /mute Player - Mute:Yes /unmute Player - Mute:Yes /restart script - Mute:Yes Link to comment
myonlake Posted February 26, 2014 Share Posted February 26, 2014 Did you use the code Solidsnake or Citizen posted above? It won't work alone, if you're using the admin panel, so that's why you need to use those codes in combination with my code. Link to comment
Jade Posted February 26, 2014 Author Share Posted February 26, 2014 -- 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 Citizen Posted February 26, 2014 Moderators Share Posted February 26, 2014 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
Castillo Posted February 26, 2014 Share Posted February 26, 2014 Won't that cause a stack overflow? what's the point of making that whole function when you can simply use the events onPlayerMute and onPlayerUnmute to set the element data? Link to comment
Jade Posted February 26, 2014 Author Share Posted February 26, 2014 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
Castillo Posted February 26, 2014 Share Posted February 26, 2014 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
Jade Posted February 26, 2014 Author Share Posted February 26, 2014 I only use this code /start script - Mute: no /mute player - Mute: Yes /unmute player - Mute: Yes ==> fault here Link to comment
Castillo Posted February 26, 2014 Share Posted February 26, 2014 addEventHandler ( "onPlayerUnmute", root, function ( ) setElementData ( source, resName ..":muted", false ) outputChatBox ( "UNMUTED!" ) end ) Use that see if it outputs "UNMUTED!" when you unmute the player. Link to comment
Jade Posted February 27, 2014 Author Share Posted February 27, 2014 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? Link to comment
Castillo Posted February 27, 2014 Share Posted February 27, 2014 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
Jade Posted February 27, 2014 Author Share Posted February 27, 2014 this works,thank you very much Solidsnake14,myonlake,Citizen,IIYAMA Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 I know why, it's because the admin panel triggers it's own "onPlayerMute" event. Oh nice catch ! Link to comment
Castillo Posted February 27, 2014 Share Posted February 27, 2014 Jade said: this works,thank you very much Solidsnake14,myonlake,Citizen,IIYAMA You're welcome. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now