Hazard| Posted July 25, 2014 Share Posted July 25, 2014 Hello guys, could any of you fix this? no errors, but clearly it's wrong The try is to mute the player, and unmute, with the same command = mmute thx function mutePlayerCommand (thePlayer, command, source) local mutedPlayer = getPlayerFromNamePart ( source ) local source = mutedPlayer local muteData = getElementData( source, "isPlayerMuted" ) if ( hasObjectPermissionTo ( thePlayer, "function.setPlayerMuted", true ) ) then if (mutedPlayer) then if (muteData == true) then if getElementType ( mutedPlayer ) == "player" then setElementData ( source, "isPlayerMuted", false ) outputChatBox ( getPlayerName( source ).." has been unmuted by "..getPlayerName( thePlayer ).." (mainchat only)", root, 33, 255, 95) elseif (muteData == false) then if getElementType ( mutedPlayer ) == "player" then setElementData ( source, "isPlayerMuted", true ) outputChatBox ( getPlayerName( source ).." has been muted by "..getPlayerName( thePlayer ).." (mainchat only)", root, 255, 0, 0) end end end end end end addCommandHandler("mmute", mutePlayerCommand) Link to comment
LonelyRoad Posted July 25, 2014 Share Posted July 25, 2014 We cannot do a great deal to help without knowing what is broken, however a couple of things I notice are as follows: You're using a useful function without including its code, see wiki page for getPlayerFromNamePart - you need to include the function's code before it will work. You're using the command args in reverse, and are possibly conflicting with a globally defined internal for all functions 'source'. You should use (source, command, targetPlayer) - and hence everything that is source should be targetPlayer, or if you so wish 'mutedPlayer'. You're explicitly defining (a check for) another possible return value with 'elseif' - when there are only two possible states for this script in its current format. What I mean is why have an 'elseif' if they can only be muted or not muted - in which case you can always apply the opposite. Btw, your script is very bloated in this case, as you can just use 'not currentstate' to apply the opposite to whatever they already have. * *: All need is something like this pseudo-code - DO NOT JUST COPY AND PASTE WHAT IS BELOW AND EXPECT IT TO WORK OR YOU WILL BE SHOT: function mmuteply(src, cmd, tgt) if isElement(tgt) then local target = getPlayerFromNamePart(tgt) if (hasPermission(src, muteplayer), true) then local mutestate = getElementData(target, "mutestate") or false local newstate = not mutestate setElementData(target, "mutestate", newstate) end end addCommandHandler("mmute", mmuteply) Also, you could add a outputChatBox that will adapt itself to the mute state to tell the player whether they are muted or not, but due to the time of night and me writing without a great deal of thought - I cannot remember how to do this. Someone else may help though. Link to comment
RottenFlesh Posted July 25, 2014 Share Posted July 25, 2014 i would do it like this: function mute_command(commander, _, player_to_mute) if hasObjectPermissionTo(commander, "command.mute", false) then local player_to_mute = getPlayerFromNamePart(player_to_mute) if player_to_mute then local is_muted = isPlayerMuted(player_to_mute) setPlayerMuted(player_to_mute, not is_muted) local text = is_muted and "unmuted" or "muted" outputChatBox(getPlayerName(player_to_mute).." has been "..text.." by "..getPlayerName(commander), root, 255, 255, 255, true) end end end addCommandHandler('mmute', mute_command) I have not tested it. Link to comment
_DrXenon Posted July 25, 2014 Share Posted July 25, 2014 One more thing! Add the resource to the Admin ACL Link to comment
Hazard| Posted July 25, 2014 Author Share Posted July 25, 2014 What's broken: It doesn't output in the chat who I am muting or unmuting, probably because the whole function is broken. That's the problem Link to comment
_DrXenon Posted July 25, 2014 Share Posted July 25, 2014 It doesn't output, so it does mute? Link to comment
Hazard| Posted July 25, 2014 Author Share Posted July 25, 2014 It does nothing exactly, but no errors when *trying to mute or unmute. This is just a small part of the code tho, I just want to make the unmutecommand and mutecommand work with same command-name="mmute" 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