Jade Posted February 25, 2014 Share Posted February 25, 2014 How can show on the screen? İn the right part 'Mute= Yes' or 'Mute= No' Link to comment
myonlake Posted February 25, 2014 Share Posted February 25, 2014 The following functions should do the trick. -- Server-side setPlayerMuted -- To set the player muted in the first place setElementData -- When player is set muted, then set the element data, which is accessible client-side -- Client-side getElementData -- Get the muted state of the player guiGetScreenSize -- To get the client's screen resolution and position the text accordingly dxDrawText -- To draw the muted state received above And use onClientRender to render the text on the screen. Link to comment
Jade Posted February 25, 2014 Author Share Posted February 25, 2014 Server-side: function mutePlayer(player,command,victimName) if victimName then local victim = getPlayerFromName(victimName) if victim then if ( not isPlayerMuted(victim) ) then setPlayerMuted(victim, true) outputChatBox("You have been muted.",victim) end else outputChatBox("Could not find player with name: "..tostring(victimName),player) end else outputChatBox("Usage: /mute ",player) end end addCommandHandler("mute",mutePlayer) Client-side: function DXtext () local sWidth,sHeight = guiGetScreenSize() dxDrawText("Mute: No",sWidth*0.900, sHeight*0.452, sWidth*0.715, sHeight*0.997,tocolor(255,255,255,175),0.8,"bankgothic","left","top",false,false,false) end addEventHandler ( "onClientRender", getRootElement(), DXtext ) A little help? Link to comment
Moderators IIYAMA Posted February 25, 2014 Moderators Share Posted February 25, 2014 Not tested. Server triggerClientEvent(victim,"changeMuteEffect",victim,true) -- Yes triggerClientEvent(victim,"changeMuteEffect",victim,false) -- No Client -- other variables -- local myState = "No" --------------------- -- DX settings -- local sWidth,sHeight = guiGetScreenSize() local gray = tocolor(255,255,255,175) ----------------- local DXtext = function () dxDrawText("Mute: " .. myState, sWidth*0.900, sHeight*0.452, sWidth*0.715, sHeight*0.997,gray,0.8,"bankgothic","left","top",false,false,false) end addEventHandler ( "onClientRender", root, DXtext ) addEvent("changeMuteEffect",true) addEventHandler("changeMuteEffect",root, function (state) myState = state and "Yes" or "No" end) Link to comment
Jade Posted February 25, 2014 Author Share Posted February 25, 2014 didn't work debugscript: Warning:S.lua:1: Bad argument @ 'triggerClientEvent' [Expected string at argument 1,got nill] Warning:S.lua:3: Bad argument @ 'triggerClientEvent' [Expected string at argument 1,got nill] Link to comment
WhoAmI Posted February 25, 2014 Share Posted February 25, 2014 function mutePlayer(player,command,victimName) if victimName then local victim = getPlayerFromName(victimName) if victim then if ( not isPlayerMuted(victim) ) then setPlayerMuted(victim, true) outputChatBox("You have been muted.",victim) setElementData(victim, "muted", true) end else outputChatBox("Could not find player with name: "..tostring(victimName),player) end else outputChatBox("Usage: /mute ",player) end end addCommandHandler("mute",mutePlayer) Client function DXtext () local muted = getElementData(localPlayer, "muted") or false local value if (muted) then value = "Yes" else value = "No" end local sWidth,sHeight = guiGetScreenSize() dxDrawText("Mute: "..value,sWidth*0.900, sHeight*0.452, sWidth*0.715, sHeight*0.997,tocolor(255,255,255,175),0.8,"bankgothic","left","top",false,false,false) end addEventHandler ( "onClientRender", getRootElement(), DXtext ) Link to comment
Moderators IIYAMA Posted February 25, 2014 Moderators Share Posted February 25, 2014 didn't workdebugscript: Warning:S.lua:1: Bad argument @ 'triggerClientEvent' [Expected string at argument 1,got nill] Warning:S.lua:3: Bad argument @ 'triggerClientEvent' [Expected string at argument 1,got nill] You didn't defined victim. Must be a player. (or string when you send it to all) @WhoAmI If I am make working code, why the hell are you going to rewrite it? Link to comment
Jade Posted February 25, 2014 Author Share Posted February 25, 2014 How does it work?I'm tested Link to comment
Moderators IIYAMA Posted February 25, 2014 Moderators Share Posted February 25, 2014 server. function mutePlayer(player,command,victimName) if victimName then local victim = getPlayerFromName(victimName) if victim then if ( not isPlayerMuted(victim) ) then setPlayerMuted(victim, true) triggerClientEvent(victim,"changeMuteEffect",victim,true) outputChatBox("You have been muted.",victim) end else outputChatBox("Could not find player with name: "..tostring(victimName),player) end else outputChatBox("Usage: /mute ",player) end end addCommandHandler("mute",mutePlayer) And the client code at clientside. (not on the same file) Link to comment
Moderators Citizen Posted February 25, 2014 Moderators Share Posted February 25, 2014 IIYAMA said: @WhoAmI If I am make working code, why the hell are you going to rewrite it? Same question to you ... Why didn't you wrote your code according to myonlake's post ? Your code is just confusing Jade. Your code should look like what WhoAmI wrote just because it's exactly what myonlake suggested and that it's a way better than your triggers. (Why ? Just because element datas are synced between the two sides and you can use that element data everywhere else on the client side where you need it) Link to comment
Moderators IIYAMA Posted February 25, 2014 Moderators Share Posted February 25, 2014 Citizen said: IIYAMA said: @WhoAmI If I am make working code, why the hell are you going to rewrite it? Same question to you ... Why didn't you wrote the your code according to myonlake's post ? Your code is just confusing Jade. Your code should look like what WhoAmI wrote just because it's exactly what myonlake wrote and that it's a way better than your triggers. (Why ? Just because element datas are synced between the two sides and you can use that element data everywhere else on the client side where you need it) Why I didn't write code as myonlake, because every scripter has it's own style, I don't have to follow anybody his style. and no I don't write it down as WhoAmI, simply because it isn't how computers communicate between each other. Computers communicate directly and only to the ones that need information, the rest don't need those useless global information. Showing the score, ok fine. But this information is meant for 1 player and 1 player only. Quote and that it's a way better than your triggers. Dream on, the performance will drop after a amount of players(take mini-mission as example, true collapse), I am not going to discus this with you what is better. After you send it, you can even so use element data without synchronisation. So that isn't truly a super benefit after all. Discussed. (PM) Quote @Jade See my post before this one. Link to comment
myonlake Posted February 25, 2014 Share Posted February 25, 2014 and that it's a way better than your triggers. Dream on, the performance will drop after a amount of players(take mini-mission as example, true collapse), I am not going to discus this with you what is better. After you send it, you can even so use element data without synchronization. So that isn't truly a super benefit at all. To be honest, I have never seen a big performance drop with element data, especially because when you define something client-side, it'll always be triggered for the client instead of the server, which in this case is very very efficient, as it doesn't have to check the element data through the server each time. I know we've gone through this discussion many times before, but I just don't care to believe it's a bad choice to use element data until a developer proves me totally wrong in that. This is quite lightweight data as well, so it won't synchronize too much information and that's exactly why element data is useful. Unsure how he wanted the mute to be displayed on screen, so I made it in two different ways on both, element data and event triggers. Without element data None of these use element data as you dislike it so much. Server-side local _setPlayerMuted = setPlayerMuted function setPlayerMuted( player, state ) if ( isElement( player ) ) and ( getElementType( player ) == "player" ) and ( type( state ) == "boolean" ) then if ( _setPlayerMuted( player, state ) ) then triggerClientEvent( player, getResourceName( resource ) .. ":mute:sync", player, state ) return true end end return false end Approach #1 Display both muted and unmuted state on the screen as "Mute: Yes/No". The event is never removed. Client-side local is_muted local screen_width, screen_height = guiGetScreenSize( ) addEventHandler( "onClientRender", root, function( ) 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 ) addEvent( getResourceName( resource ) .. ":mute:sync", true ) addEventHandler( getResourceName( resource ) .. ":mute:sync", root, function( state ) is_muted = state end ) Approach #2 Display only muted state as "You are muted!" and remove the renderer when no longer muted. Client-side local is_muted local screen_width, screen_height = guiGetScreenSize( ) local function drawMuteDisplay( ) if ( not is_muted ) then return end local mute_text = "You are muted!" 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, 0, 0, 230 ), 2.0, "default", "left", "top", true, false, post_gui, false, false ) end addEvent( getResourceName( resource ) .. ":mute:sync", true ) addEventHandler( getResourceName( resource ) .. ":mute:sync", root, function( state ) local fn = ( is_muted ~= state and ( is_muted and removeEventHandler or addEventHandler ) or nil ) is_muted = state if ( fn ) then fn( "onClientRender", root, drawMuteDisplay ) end end ) With element data And these use element data instead of event triggers. Server-side 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 Approach #1 Display both muted and unmuted state on the screen as "Mute: Yes/No". The event is never removed. Client-side 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 ) Approach #2 Display only muted state as "You are muted!" and cancel rendering if not muted. Client-side local screen_width, screen_height = guiGetScreenSize( ) addEventHandler( "onClientRender", root, function( ) local is_muted = getElementData( localPlayer, getResourceName( resource ) .. ":muted" ) if ( not is_muted ) then return end local mute_text = "You are muted!" 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, 0, 0, 230 ), 2.0, "default", "left", "top", true, false, post_gui, false, false ) end ) Additionally I went on and tested all parts of the code and it seems to be working flawlessly. Hopefully this helped you. Link to comment
Moderators IIYAMA Posted February 25, 2014 Moderators Share Posted February 25, 2014 myonlake, true. Trigger event's have also a light sync variant. (triggerLatentClientEvent) There is only just 1 bug and it is a very known one.(I bet everybody has had this problem before) It happens when the client hasn't loaded yet. triggerClientEvent will have problems with sending to the client when he hasn't loaded yet. (he won't be displayed as muted) Also: Elementdata will have a problem when the player is unmuted after the resource has been stopped. (he will be displayed as muted when the resource starts even if he is unmuted) So a call back would be the fix. (not that you have to spend more time on the code you have already written ) Link to comment
myonlake Posted February 25, 2014 Share Posted February 25, 2014 It happens when the client hasn't loaded yet. In this case I don't think that matters, as I doubt no one is going to mute a player before they've loaded everything, if they do, then they should consider revamping their initialization techniques. Elementdata will have a problem when the player is unmuted after the resource has been stopped. Yeah, and I think I am not responsible for making that happen, as it's just an example of how the system could work. The rest is up to him, as he didn't request anything else than to display the muted state. And he's also able to export that function from another resource, so I doubt the resource is going to stay stopped for a long time, which would potentially cause these issues. This is why I brought up two different approaches on how to make it work. These are the only ways to make it work (unless you want to make it go through a web server or something stupid), so. Link to comment
Jade Posted February 25, 2014 Author Share Posted February 25, 2014 I have problems. didn't work. why Link to comment
Moderators Citizen Posted February 25, 2014 Moderators Share Posted February 25, 2014 I have problems. didn't work. why 1 - what are the problems, we can't see them if you don't show them to us. 2 - you have at least 4 working code on the previous page. Are you sure you know where to put this code ? Link to comment
Jade Posted February 25, 2014 Author Share Posted February 25, 2014 Quote With element data And these use element data instead of event triggers. Server-side 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 Approach #1 Display both muted and unmuted state on the screen as "Mute: Yes/No". The event is never removed. Client-side 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 ) I chose this /mute player /unmute player Link to comment
Moderators Citizen Posted February 25, 2014 Moderators Share Posted February 25, 2014 Show us the /mute function Link to comment
Moderators Citizen Posted February 25, 2014 Moderators Share Posted February 25, 2014 Oh you are muing from the admin panel ?! That's what you should say at the very begining of this thread. No one knew that ! Just add these lines on the server side but keep the myonlake's solution you selected. Server: addEventHandler("onPlayerMute", root, function() setPlayerMuted(source, true) end) addEventHandler("onPlayerUnmute", root, function() setPlayerMuted(source, false) end) Link to comment
Jade Posted February 25, 2014 Author Share Posted February 25, 2014 Sorry, I've added /mute player - bug full unmute not work mute i bug full mute not work unmute debugscript: S.lua:4: C stack overflow Link to comment
Castillo Posted February 25, 2014 Share Posted February 25, 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 ) Link to comment
Moderators Citizen Posted February 26, 2014 Moderators Share Posted February 26, 2014 Solidsnake14 said: local resName = getResourceName ( getThisResource ( ) ) addEventHandler ( "onPlayerMute", root, function ( ) setElementData ( source, resName ..":muted", true ) end ) addEventHandler ( "onPlayerUnmute", root, function ( ) setElementData ( source, resName ..":muted", false ) end ) That's what should do the new setPlayerMuted myonlake made. That's why I directly used that function again to let it set the element data. Link to comment
myonlake Posted February 26, 2014 Share Posted February 26, 2014 Make sure you use the element data script also instead of event triggers. 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