Jump to content

some bugs with mute command


Chaos

Recommended Posts

hi,

i have some bugs with this code

1.when the timer of mute is finished then when the player is reconnect he will return muted

2.i can't put space with reason

3.there is no outputchatbox when the timer is finished

here is the script:

            local mutedSerials = { } 
            
        function muteSomeone ( player, cmd, target, reason, time ) 
            if ( target and reason and time ) then 
                
            local target = getPlayerFromNamePart ( target ) 
                
                
                
                
                
                
                if ( not isElement ( target ) ) then 
                    outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) 
                    return 
                end 
          
                local time = tonumber ( time ) 
                if ( time and time >= 1 and not isPlayerMuted ( target ) ) then 
                    local milliseconds = math.floor ( time * 60000 ) 
      
                    outputChatBox ( getPlayerName ( target ) .." has been muted for ".. tostring ( time ) .." minutes (".. reason ..") .", root, 255, 0, 0 ) 
                    setPlayerMuted ( target, true ) 
                    setTimer ( setPlayerMuted, milliseconds, 1, target, false ) 
                    mutedSerials [ getPlayerSerial ( target ) ] = milliseconds 
                else 
                    outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) 
                end 
            end 
        end 
        addCommandHandler ( "mmute", muteSomeone ) 
      
      
    function getPlayerFromNamePart(name) 
        if name then 
            for i, player in ipairs(getElementsByType("player")) do 
                if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                    return player 
                end 
            end 
        end 
        return false 
    end 
      
      
      
      
      
         function afterreconnect () 
    local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] 
    if ( milliseconds ) then 
    setPlayerMuted ( source, true ) 
    setTimer ( setPlayerMuted, milliseconds, 1, source, false ) 
    else 
    setPlayerMuted ( source, false ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) 
  

Edited by Guest
Link to comment
local mutedSerials = { } 
  
function muteSomeone ( player, cmd, target, time, ... ) 
    local reason = table.concat ( { ... }, " " ) 
    if ( target and reason and time ) then 
        local target = getPlayerFromNamePart ( target )       
        if ( not isElement ( target ) ) then 
            outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) 
            return 
        end 
  
        local time = tonumber ( time ) 
        if ( time and time >= 1 and not isPlayerMuted ( target ) ) then 
            local milliseconds = math.floor ( time * 60000 ) 
            outputChatBox ( getPlayerName ( target ) .." has been muted for ".. tostring ( time ) .." minutes (".. reason ..") .", root, 255, 0, 0 ) 
            setPlayerMuted ( target, true ) 
            local timer = setTimer ( unMute, milliseconds, 1, target ) 
            mutedSerials [ getPlayerSerial ( target ) ] = { milliseconds, timer } 
        else 
            outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) 
        end 
    end 
end 
addCommandHandler ( "mmute", muteSomeone ) 
  
function getPlayerFromNamePart(name) 
    if name then 
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player 
            end 
        end 
    end 
    return false 
end 
  
function afterreconnect (  
    local serial = getPlayerSerial ( source ) 
    local muted = mutedSerials [ serial ] 
    if ( type ( muted ) == "table" ) then 
        if ( muted [ 1 ] ) then 
            setPlayerMuted ( source, true ) 
            local timer = setTimer ( unMute, muted [ 1 ], 1, source ) 
            mutedSerials [ serial ] [ 2 ] = timer 
  
            return 
        end 
    end 
  
    setPlayerMuted ( source, false ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        local serial = getPlayerSerial ( source ) 
        local muted = mutedSerials [ serial ] 
        if ( type ( muted ) == "table" ) then 
            if isTimer ( muted [ 2 ] ) then 
                killTimer ( muted [ 2 ] ) 
            end 
        end 
    end 
) 
  
function unMute ( thePlayer ) 
    if isElement ( thePlayer ) then 
        setPlayerMuted ( thePlayer, false ) 
        mutedSerials [ getPlayerSerial ( thePlayer ) ] = nil 
        outputChatBox ( "You have been unmuted.", thePlayer, 0, 255, 0 ) 
    end 
end 

That should fix the 3 problems.

Link to comment

That's right, try this to save time left:

local mutedSerials = { } 
  
function muteSomeone ( player, cmd, target, time, ... ) 
    local reason = table.concat ( { ... }, " " ) 
    if ( target and reason and time ) then 
        local target = getPlayerFromNamePart ( target )       
        if ( not isElement ( target ) ) then 
            outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) 
            return 
        end 
  
        local time = tonumber ( time ) 
        if ( time and time >= 1 and not isPlayerMuted ( target ) ) then 
            local milliseconds = math.floor ( time * 60000 ) 
            outputChatBox ( getPlayerName ( target ) .." has been muted for ".. tostring ( time ) .." minutes (".. reason ..") .", root, 255, 0, 0 ) 
            setPlayerMuted ( target, true ) 
            local timer = setTimer ( unMute, milliseconds, 1, target ) 
            mutedSerials [ getPlayerSerial ( target ) ] = { milliseconds, timer } 
        else 
            outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) 
        end 
    end 
end 
addCommandHandler ( "mmute", muteSomeone ) 
  
function getPlayerFromNamePart(name) 
    if name then 
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player 
            end 
        end 
    end 
    return false 
end 
  
function afterreconnect ( 
    local serial = getPlayerSerial ( source ) 
    local muted = mutedSerials [ serial ] 
    if ( type ( muted ) == "table" ) then 
        if ( muted [ 1 ] ) then 
            setPlayerMuted ( source, true ) 
            local timer = setTimer ( unMute, muted [ 1 ], 1, source ) 
            mutedSerials [ serial ] [ 2 ] = timer 
  
            return 
        end 
    end 
  
    setPlayerMuted ( source, false ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        local serial = getPlayerSerial ( source ) 
        local muted = mutedSerials [ serial ] 
        if ( type ( muted ) == "table" ) then 
            if isTimer ( muted [ 2 ] ) then 
                local timeLeft = getTimerDetails ( muted [ 2 ] ) 
                killTimer ( muted [ 2 ] ) 
                mutedSerials [ serial ] [ 1 ] = timeLeft 
            end 
        end 
    end 
) 
  
function unMute ( thePlayer ) 
    if isElement ( thePlayer ) then 
        setPlayerMuted ( thePlayer, false ) 
        mutedSerials [ getPlayerSerial ( thePlayer ) ] = nil 
        outputChatBox ( "You have been unmuted.", thePlayer, 0, 255, 0 ) 
    end 
end 

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