Jump to content

question about mute


Chaos

Recommended Posts

hi,

im trying to make mute command but the problem is with time when i mute someone 4 min he will be muted for 24000 minutes

  
            function muteSomeone(player, cmd, target, reason, time) 
            if (target and reason and time) then 
                    local target = getPlayerFromName(target) 
                    if (not isElement(target)) then 
                            outputChatBox("There is no player with this name", player, 255, 255, 0) 
                            return 
                    end 
                    if (tonumber(time) and tonumber(time) >= 1 and not isPlayerMuted(target)) then 
                            local minutes = math.floor(time * 60 * 1000) 
                            outputChatBox(getPlayerName(target).." has been muted for "..tostring(minutes).." minutes ("..reason..") .", root,255, 0, 0) 
                            setPlayerMuted(target, true) 
                    else 
                            outputChatBox("Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0) 
                    end 
            end 
    end 
    addCommandHandler("mmute", muteSomeone) 

Link to comment

He will be muted for ever because there's no timer in your code executing function which is responsible for unmute, outputChatBox displays 24 minutes because variable minutes contains this value.

Currently it works like that: 4*60*1000 so minutes is equal to 240000 right now - your 4 minutes in milliseconds, so if you want to display it as minutes you've got to divide it by 1000 and then by 60.

outputChatBox(getPlayerName(target).." has been muted for "..tostring(((minutes/1000)/60))).." minutes ("..reason..") .", root,255, 0, 0) 

Except this you should use setTimer to actually get it working.

setTimer 

Link to comment
like this ?
setTimer(setPlayerMuted(muted, false), time*60*1000, 1) 

Use your minutes variable, for this reason it's created... isn't it?

[...] 
local minutes = math.floor(time * 60 * 1000) 
outputChatBox(getPlayerName(target).." has been muted for "..tostring(((minutes/1000)/60)).." minutes ("..reason..") .", root,255, 0, 0) 
setPlayerMuted(target, true) 
setTimer(setPlayerMuted, minutes, 1, target, false) 
[...] 

Best regards.

Link to comment
function muteSomeone ( player, cmd, target, reason, time ) 
    if ( target and reason and time ) then 
        local target = getPlayerFromName ( 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 ) 
        else 
            outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) 
        end 
    end 
end 
addCommandHandler ( "mmute", muteSomeone ) 

Link to comment

is that true ?

       local mutedSerials = { } 
         
    function muteSomeone ( player, cmd, target, reason, time ) 
        if ( target and reason and time ) then 
            local target = getPlayerFromName ( 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 afterreconnect (target) 
    local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] 
    if ( milliseconds ) then 
                outputChatBox ( getPlayerName ( target ) .." has been muted by Console", root, 255, 0, 0 ) 
                setPlayerMuted ( target, true ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect  

Link to comment
  local mutedSerials = { } 
         
    function muteSomeone ( player, cmd, target, reason, time ) 
        if ( target and reason and time ) then 
            local target = getPlayerFromName ( 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 afterreconnect (source) 
    local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] 
    if ( milliseconds ) then 
    setPlayerMuted ( source, true ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) 

not working when i reconnect and i will get unmuted when reconnect

Link to comment
        local mutedSerials = { } 
         
    function muteSomeone ( player, cmd, target, reason, time ) 
        if ( target and reason and time ) then 
            local target = getPlayerFromName ( 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 afterreconnect () 
    local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] 
    if ( milliseconds ) then 
    setTimer ( setPlayerMuted, milliseconds, 1, source, false )] 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) 

true ?

Link to comment

i can't really understand how to put it is that true ?

    function muteSomeone ( player, cmd, target, reason, time ) 
        if ( target and reason and time ) then 
            if target then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
  
            local target = getPlayerFromName ( target ) 
            if ( not isElement ( target ) ) then 
                outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) 
                return 
            end 
            end 
            end 
            end  
            return false 
            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 ) 

Link to comment
        local mutedSerials = { } 
         
    function muteSomeone ( player, cmd, target, reason, time ) 
        if ( target and reason and time ) then 
             
            local target = getPlayerNameFromNamePart("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 
  
  

true ?

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