Jump to content

muteRandomPlayer


Recommended Posts

Hey guys,

since a few weeks I'm trying to script with some help from scripters.

I've tried to make a command which mutes a randomplayer for 1 minute.

but it seems to fail.

Maybe you guys can help me

  
  
local randomPlayer = getRandomPlayer ( ) 
  
function mute(randomPlayer) 
    outputChatBox(getPlayerName(randomPlayer).." is now muted", getRootElement(), 255, 0, 0, true) 
    mutePlayer(randomPlayer) 
setTimer(60000,1, unmuterandomPlayer) 
end 
addCommandHandler("idiot", mute) 
  

Regards Killerbee_x.

Link to comment
function mute(player) 
    local randomPlayer = getRandomPlayer ( ) 
    outputChatBox(getPlayerName(randomPlayer).." is now muted", getRootElement(), 255, 0, 0, true) 
    mutePlayer(randomPlayer) 
setTimer(60000,1, unmuterandomPlayer) 
end 
addCommandHandler("idiot", mute) 

Link to comment

Addition to JR10, which is actually the problem of all this: the setTimer syntax is incorrect. You used the function to call at the end, it has to be at the first argument.

setTimer ( unmuterandomPlayer, 60000, 1, randomPlayer ) 

The last argument is needed to determine who was the random player. See the wiki for a full documentation about setTimer.

Link to comment
function mute(player) 
     repeat randomPlayer = getRandomPlayer ( ) until randomPlayer ~= player 
     outputChatBox(getPlayerName(randomPlayer).." is now muted", getRootElement(), 255, 0, 0, true) 
     mutePlayer(randomPlayer) 
     setTimer ( unmuterandomPlayer, 60000, 1, randomPlayer ) 
end 
addCommandHandler("idiot", mute) 

Link to comment

There is no such function 'mutePlayer'. Use setPlayerMuted instead. Next code should work (not tested though). By the way, make sure your resource has rights to mute players (it should be noted in ACL.xml).

  
local timers = {} 
local muteDuration = 60 --seconds 
  
addCommandHandler( "idiot", function( player, cmd ) 
  local rndPlayer = getRandomPlayer() 
  --if random player is not muted 
  if not timers[ rndPlayer ] then 
    setPlayerMuted( rndPlayer, true ) 
    timers[ rndPlayer ] = setTimer( setPlayerMuted, muteDuration*1000, 1, rndPlayer, false ) 
    outputChatBox( getPlayerName( rndPlayer ).." is now muted", root, 255, 0, 0, true ) 
  end 
end ) 
  
--if a player leaves the server and he has been muted, then remove the timer 
addEventHandler( "onPlayerQuit", root, function() 
  if timers[ source ] then 
    killTimer( timers[ source ] ) 
    timers[ source ] = nil 
  end 
end ) 

Link to comment

Hmm, replace the 10th line:

timers[ rndPlayer ] = setTimer( function( rplayer ) 
  setPlayerMuted( rplayer, false ) 
  outputChatBox( getPlayerName( rplayer ).." is now unmuted", root, 255, 255, 0, true ) 
end, muteDuration*1000, 1, rndPlayer ) 

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