micheal1230 Posted June 25, 2012 Share Posted June 25, 2012 Bad Arg At Line 2 When you dont type the name, if you do then it doesnt mute the target. function mute(player, command, target) local targetAcc = getAccountName( getPlayerAccount( getPlayerFromNamePart( tostring( target ) ) ) ) if ( hasObjectPermissionTo ( player, "command.aexec", true ) ) then if( targetAcc ) then local mute = setPlayerMuted(target,true) if ( mute ) then setAccountData(targetAcc, "muted", mute) outputChatBox(""..targetAcc.." has been muted!", player) end end else outputChatBox("SYNTAX: /"..command.." [PlayerName]", player) end end addCommandHandler("mute", mute) Link to comment
Flaker Posted June 25, 2012 Share Posted June 25, 2012 Try this: function mute(thePlayer, command, target) if ( hasObjectPermissionTo ( thePlayer, "command.aexec", true ) ) then local TargetPlayer = getPlayerFromNamePart( tostring( target ) ) if TargetPlayer then local targetAcc = getAccountName( getPlayerAccount( TargetPlayer ) ) if ( targetAcc ) then if ( not isPlayerMuted(TargetPlayer) ) then if setPlayerMuted(TargetPlayer,true) then setAccountData(getPlayerAccount( TargetPlayer ), "muted", true) outputChatBox(""..targetAcc.." has been muted!", player) end else if setPlayerMuted(TargetPlayer,false) then setAccountData(getPlayerAccount( TargetPlayer ), "muted", false) outputChatBox(""..targetAcc.." has been unmuted!", player) end end end else outputChatBox("SYNTAX: /"..command.." [PlayerName]", player) end end end addCommandHandler("mute", mute) Link to comment
Anderl Posted June 25, 2012 Share Posted June 25, 2012 (edited) You forgot to put the function "getPlayerFromNamePart" and your code have some errors, Flaker. Try that, michael: function mute( player, command, target ) if( hasObjectPermissionTo( getThisResource( ), 'function.setPlayerMuted', true ) ) then if( hasObjectPermissionTo( player, 'command.aexec', true ) ) then local targetPlayer = getPlayerFromNamePart( target ); if( targetPlayer ) then if( not isGuestAccount( getPlayerAccount( targetPlayer ) ) ) then if( not isPlayerMuted( targetPlayer ) ) then if( setPlayerMuted( targetPlayer, true ) ) then setAccountData( getPlayerAccount( targetPlayer ), 'muted', true ); outputChatBox( targetPlayer .. ' has been muted!', root, 255, 0, 0, false ); else outputChatBox( 'Unable to mute player!', player, 255, 0, 0, false ); end else outputChatBox( 'The player is already muted!', player, 255, 0, 0, false ); end else if( setPlayerMuted( targetPlayer, true ) ) then outputChatBox( targetPlayer .. ' has been muted!', root, 255, 0, 0, false ); else outputChatBox( 'Unable to mute player!', player, 255, 0, 0, false ); end end else outputChatBox( 'Unable to find player!', player, 255, 0, 0, false ); end else outputChatBox( 'You do not have permission to do that!', player, 255, 0, 0, false ); end else outputChatBox( 'The resource does not have permission to mute players!', player, 255, 0, 0, false ); end end addCommandHandler( 'mute', mute ); function getPlayerFromNamePart( string ) if( string and type( string ) == 'string' ) then local matches = { } for k,v in ipairs( getElementsByType 'player' ) do if( string.find( getPlayerName( v ), tostring( string ), 0 ) ) then table.insert( matches, v ); end end if( #matches == 1 ) then return matches[1]; end end return false; end Don't forget to add the resource to the ACL Group "Admin" or anyone which has access to "setPlayerMuted" function. Edited June 25, 2012 by Guest Link to comment
Guest Guest4401 Posted June 25, 2012 Share Posted June 25, 2012 I might be wrong, but if someone types /mute without the target, the target will be nil. And tostring(nil) is "nil" local targetPlayer = getPlayerFromNamePart( tostring( target ) ); Someone's name contains "nil", he'll be muted? Draken you forgot "addCommandHandler("mute",mute)" Link to comment
Anderl Posted June 25, 2012 Share Posted June 25, 2012 If you mean, if someone's name contains the string "nil" or it's just "nil", of course he will be muted cuz it's a string, it can contain everything. But, see my code, I used statement to check if target player exists. Link to comment
Guest Guest4401 Posted June 25, 2012 Share Posted June 25, 2012 (edited) Yes, you are checking if the targetPlayer exists or not, not the arg1 of the command (i.e, target). local targetPlayer = getPlayerFromNamePart( tostring( target ) ); --> if target was nil, ( /mute ) (no target specified) local targetPlayer = getPlayerFromNamePart( tostring ( nil ) ); --> local targetPlayer = getPlayerFromNamePart ( "nil" ); --> if there was a player containing "nil", it would catch that player if targetPlayer then -- this is obviously satisfied, if a player had "nil" in his name I think a condition like this would be necessary if target then Edited June 25, 2012 by Guest4401 Link to comment
Anderl Posted June 25, 2012 Share Posted June 25, 2012 It does the same. If target is nil = targetPlayer will be nil too. It's not necessary. Link to comment
Guest Guest4401 Posted June 25, 2012 Share Posted June 25, 2012 If target is nil = targetPlayer will be nil too. If you are using tostring, It won't be nil. It will be a string: "nil" target = nil tostring(target) --> "nil" [string] Link to comment
Anderl Posted June 25, 2012 Share Posted June 25, 2012 If target is nil = targetPlayer will be nil too. If you are using tostring, It won't be nil. It will be a string: "nil" target = nil tostring(target) --> "nil" [string] Oh, you're right. Let me edit the code. Link to comment
micheal1230 Posted June 25, 2012 Author Share Posted June 25, 2012 If target is nil = targetPlayer will be nil too. If you are using tostring, It won't be nil. It will be a string: "nil" target = nil tostring(target) --> "nil" [string] Oh, you're right. Let me edit the code. attempt to concanate local targetplayer a user value, plus it doesnt output that you have muted the player and that the player has been muted Link to comment
Guest Guest4401 Posted June 25, 2012 Share Posted June 25, 2012 attempt to concanate local targetplayer a user value, plus it doesnt output that you have muted the player and that the player has been mutedLooks like you aren't learning to correct small mistakes. But if you so desire to copy-paste stuff without understanding how it actually works, targetPlayer is a player element ( userdata value ). To get the player name from player element, use getPlayerName(). Change outputChatBox( targetPlayer .. ' has been muted!', root, 255, 0, 0, false ) to outputChatBox( getPlayerName ( targetPlayer ) .. ' has been muted!', root, 255, 0, 0, false ) The problem was that you had to output the player's name, not the element. Link to comment
micheal1230 Posted June 25, 2012 Author Share Posted June 25, 2012 attempt to concanate local targetplayer a user value, plus it doesnt output that you have muted the player and that the player has been mutedLooks like you aren't learning to correct small mistakes. But if you so desire to copy-paste stuff without understanding how it actually works, targetPlayer is a player element ( userdata value ). To get the player name from player element, use getPlayerName(). Change outputChatBox( targetPlayer .. ' has been muted!', root, 255, 0, 0, false ) to outputChatBox( getPlayerName ( targetPlayer ) .. ' has been muted!', root, 255, 0, 0, false ) The problem was that you had to output the player's name, not the element. Karthik i knew what the problem is just not how to fix it. Link to comment
Jaysds1 Posted June 25, 2012 Share Posted June 25, 2012 If this is not solved yet, try this: addCommandHandler("mute",function(player,command, target) if not(target)then outputChatBox("SYNTAX: /"..command.." [PlayerName]", player) end local target = string(target) local playerName = getPlayerFromNamePart(target) if(playerName)then local targetAcc = getAccountName(getPlayerAccount(playerName)) if(hasObjectPermissionTo(player,"command.aexec",false))then if(targetAcc)then local mute = setPlayerMuted(target,true) if ( mute ) then setAccountData(targetAcc, "muted", mute) outputChatBox(""..targetAcc.." has been muted!", player) end end else outputChatBox("Sorry, you don't have permission to mute a player.",player) end else outputChatBox("Sorry, that player name doesn't exist.",player) end end) Link to comment
Anderl Posted June 25, 2012 Share Posted June 25, 2012 Your code is completely messed up, Jay Here all my code fixed, I think: function mute( player, command, target ) if( hasObjectPermissionTo( getThisResource( ), 'function.setPlayerMuted', true ) ) then if( hasObjectPermissionTo( player, 'command.aexec', true ) ) then local targetPlayer = getPlayerFromNamePart( target ); if( targetPlayer ) then if( not isGuestAccount( getPlayerAccount( targetPlayer ) ) ) then if( not isPlayerMuted( targetPlayer ) ) then if( setPlayerMuted( targetPlayer, true ) ) then setAccountData( getPlayerAccount( targetPlayer ), 'muted', true ); outputChatBox( getPlayerName( targetPlayer ) .. ' has been muted!', root, 255, 0, 0, false ); else outputChatBox( 'Unable to mute player!', player, 255, 0, 0, false ); end else outputChatBox( 'The player is already muted!', player, 255, 0, 0, false ); end else if( setPlayerMuted( targetPlayer, true ) ) then outputChatBox( getPlayerName( targetPlayer ) .. ' has been muted!', root, 255, 0, 0, false ); else outputChatBox( 'Unable to mute player!', player, 255, 0, 0, false ); end end else outputChatBox( 'Unable to find player!', player, 255, 0, 0, false ); end else outputChatBox( 'You do not have permission to do that!', player, 255, 0, 0, false ); end else outputChatBox( 'The resource does not have permission to mute players!', player, 255, 0, 0, false ); end end addCommandHandler( 'mute', mute ); function getPlayerFromNamePart( string ) if( string and type( string ) == 'string' ) then local matches = { } for k,v in ipairs( getElementsByType 'player' ) do if( string.find( getPlayerName( v ), tostring( string ), 0 ) ) then table.insert( matches, v ); end end if( #matches == 1 ) then return matches[1]; end end return false; end Off-topic: I don't know why, but I ever forget to use getPlayerName lol Link to comment
micheal1230 Posted June 25, 2012 Author Share Posted June 25, 2012 Your code is completely messed up, Jay Here all my code fixed, I think: function mute( player, command, target ) if( hasObjectPermissionTo( getThisResource( ), 'function.setPlayerMuted', true ) ) then if( hasObjectPermissionTo( player, 'command.aexec', true ) ) then local targetPlayer = getPlayerFromNamePart( target ); if( targetPlayer ) then if( not isGuestAccount( getPlayerAccount( targetPlayer ) ) ) then if( not isPlayerMuted( targetPlayer ) ) then if( setPlayerMuted( targetPlayer, true ) ) then setAccountData( getPlayerAccount( targetPlayer ), 'muted', true ); outputChatBox( getPlayerName( targetPlayer ) .. ' has been muted!', root, 255, 0, 0, false ); else outputChatBox( 'Unable to mute player!', player, 255, 0, 0, false ); end else outputChatBox( 'The player is already muted!', player, 255, 0, 0, false ); end else if( setPlayerMuted( targetPlayer, true ) ) then outputChatBox( getPlayerName( targetPlayer ) .. ' has been muted!', root, 255, 0, 0, false ); else outputChatBox( 'Unable to mute player!', player, 255, 0, 0, false ); end end else outputChatBox( 'Unable to find player!', player, 255, 0, 0, false ); end else outputChatBox( 'You do not have permission to do that!', player, 255, 0, 0, false ); end else outputChatBox( 'The resource does not have permission to mute players!', player, 255, 0, 0, false ); end end addCommandHandler( 'mute', mute ); function getPlayerFromNamePart( string ) if( string and type( string ) == 'string' ) then local matches = { } for k,v in ipairs( getElementsByType 'player' ) do if( string.find( getPlayerName( v ), tostring( string ), 0 ) ) then table.insert( matches, v ); end end if( #matches == 1 ) then return matches[1]; end end return false; end Off-topic: I don't know why, but I ever forget to use getPlayerName lol Thanks for all your help guys *Topic Closed* 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