Sign in to follow this  
Guest

mute problem

Recommended Posts

Guest
local serialMute = { }

	function doAction(thePlayer, cmd, actionId, playername, arg3)
	if getElementData(thePlayer, "player.key") == "Warlock" or getElementData(thePlayer, "player.key") == "Wind:Oer" or getElementData(thePlayer, "player.key") == "Ivan" or getElementData(thePlayer, "player.key") == "Scorpio1" or getElementData(thePlayer, "player.key") == "vievsonic" then
		if actionId then
			local actionId = tonumber(actionId) 
			local player = getPlayerFromNamePart(playername or "")
			local name = getPlayerName(thePlayer)
			if player then
				if actionId == 1 then
					local duration = (tonumber(arg3) or 0) * 60 * 1000
					setPlayerMuted(player, true)
					outputChatBox(getPlayerName(player).." #005A0Ehas been muted by #FFFFFF"..name.."#005A0E.#FFFFFF Reason: insulting #005A0EDuration #FFFFFF["..math.floor((duration *1.66666667 * 1/100000)).." mins].", root, 255, 255, 255, true)
					local timer = setTimer ( unmute, duration, 1, player )
					serialMute [ getPlayerSerial ( player ) ] = { duration, timer })
				end
			else
				outputChatBox("Could not find the player.",thePlayer, 255, 0, 0)
			end
		end
	end
end
addCommandHandler("action", doAction)

function unmutePlayer(player,command,victimName)
	if victimName then
		local victim = getPlayerFromNamePart(victimName or "")
		if victim then
			if ( isPlayerMuted(victim) ) then
				setPlayerMuted(victim, false)
			end
		end
	end
end
addCommandHandler("unmute",unmutePlayer)

function onJoin ()
    local serial = getPlayerSerial(source)
    local muted = serialMute [ serial ]
    if ( type ( muted ) == "table" ) then
        if ( muted [ 1 ] ) then
            setPlayerMuted ( source, true )
            local timer = setTimer ( unmute, muted [ 1 ], 1, source )
            serialMute [ serial ] [ 2 ] = timer
 
            return
        end
    end
    setPlayerMuted ( source, false )
end
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin )
 
addEventHandler ( "onPlayerQuit", root,
    function ( )
        local serial = getPlayerSerial ( source )
        local muted = serialMute [ serial ]
        if ( type ( muted ) == "table" ) then
            if isTimer ( muted [ 2 ] ) then
                local timeLeft = getTimerDetails ( muted [ 2 ] )
                killTimer ( muted [ 2 ] )
                serialMute [ serial ] [ 1 ] = timeLeft
            end
        end
    end
)
 
function unmute ( thePlayer )
    if isElement ( thePlayer ) then
        setPlayerMuted ( thePlayer, false )
        serialMute [ getPlayerSerial ( thePlayer ) ] = nil
        outputChatBox ( "You have been unmuted by Console.", thePlayer, 0, 255, 100 )
    end
end

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

When i do /action [mute id ] [Player name] [Time] 

nothing happens

Share this post


Link to post

Did you verify all that

getElementData()

you're doing on line 4 ?

Share this post


Link to post
Guest

Oh , no

If i remove line 4 it works but with some bugs

can you tell me what is it mean ( Line 4)

because my friend gave me the code

Share this post


Link to post

Line 4 is checking for data related to the player, It's there because the script is taken from another game mode, or considered connected to other scripts.

Replace line 4 with this line and post any errors you have

if (isElement( thePlayer )) then

Next time, please write your own code

Share this post


Link to post
Guest

Working, Thanks you very very much bro

 

But player can mute/ban/kick

how to make this function works only with staffs?

Share this post


Link to post

Many ways to do that, but you can just go on the wiki and look for an ACL function that checks that.

I can tell you what function that is but you should spend some time :)

Share this post


Link to post
Guest

i have more than 30 minutes searching

i founded this code

   local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 

But nothing happened

Edited by Guest

Share this post


Link to post

Did you restart the server after you added yourself?

If so, repost your code.

Share this post


Link to post
Guest

i used this

bool aclReload ()

local serialMute = { }

	function doAction(thePlayer, cmd, actionId, playername, arg3)
    if (isElement( thePlayer )) then
		if actionId then
			local actionId = tonumber(actionId) 
			local player = getPlayerFromNamePart(playername or "")
			local name = getPlayerName(thePlayer)
			if player then
				if actionId == 1 then
					local duration = (tonumber(arg3) or 0) * 60 * 1000
					setPlayerMuted(player, true)
					outputChatBox(getPlayerName(player).." #005A0Ehas been muted by #FFFFFF"..name.."#005A0E.#FFFFFF Reason: insulting #005A0EDuration #FFFFFF["..math.floor((duration *1.66666667 * 1/100000)).." mins].", root, 255, 255, 255, true)
					local timer = setTimer ( unmute, duration, 1, player )
					serialMute [ getPlayerSerial ( player ) ] = { duration, timer })
				end
			else
				outputChatBox("Could not find the player.",thePlayer, 255, 0, 0)
			end
		end
	end
end
addCommandHandler("action", doAction)

function unmutePlayer(player,command,victimName)
	if victimName then
		local victim = getPlayerFromNamePart(victimName or "")
		if victim then
			if ( isPlayerMuted(victim) ) then
				setPlayerMuted(victim, false)
			end
		end
	end
end
addCommandHandler("unmute",unmutePlayer)

function onJoin ()
    local serial = getPlayerSerial(source)
    local muted = serialMute [ serial ]
    if ( type ( muted ) == "table" ) then
        if ( muted [ 1 ] ) then
            setPlayerMuted ( source, true )
            local timer = setTimer ( unmute, muted [ 1 ], 1, source )
            serialMute [ serial ] [ 2 ] = timer
 
            return
        end
    end
    setPlayerMuted ( source, false )
end
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin )
 
addEventHandler ( "onPlayerQuit", root,
    function ( )
        local serial = getPlayerSerial ( source )
        local muted = serialMute [ serial ]
        if ( type ( muted ) == "table" ) then
            if isTimer ( muted [ 2 ] ) then
                local timeLeft = getTimerDetails ( muted [ 2 ] )
                killTimer ( muted [ 2 ] )
                serialMute [ serial ] [ 1 ] = timeLeft
            end
        end
    end
)
 
function unmute ( thePlayer )
    if isElement ( thePlayer ) then
        setPlayerMuted ( thePlayer, false )
        serialMute [ getPlayerSerial ( thePlayer ) ] = nil
        outputChatBox ( "You have been unmuted by Console.", thePlayer, 0, 255, 100 )
    end
end
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
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

 

Edited by Guest

Share this post


Link to post

What the hell is that? line 74 and 75 are not in a function.. What..

Share this post


Link to post
Guest

Help me to understand.. I'm still new in scripting

   function ( thePlayer )   
   local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 

What about this?

Share this post


Link to post
    local serialMute = { }

    	function doAction(thePlayer, cmd, actionId, playername, arg3)
        if (isElement( thePlayer )) then
    		if actionId then
    			local actionId = tonumber(actionId) 
    			local player = getPlayerFromNamePart(playername or "")
    			local name = getPlayerName(thePlayer)
    			if player then
    				if actionId == 1 then
						local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
         				if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
	    					local duration = (tonumber(arg3) or 0) * 60 * 1000
	    					setPlayerMuted(player, true)
	    					outputChatBox(getPlayerName(player).." #005A0Ehas been muted by #FFFFFF"..name.."#005A0E.#FFFFFF Reason: insulting #005A0EDuration #FFFFFF["..math.floor((duration *1.66666667 * 1/100000)).." mins].", root, 255, 255, 255, true)
	    					local timer = setTimer ( unmute, duration, 1, player )
	    					serialMute [ getPlayerSerial ( player ) ] = { duration, timer })
    					end
    				end
    			else
    				outputChatBox("Could not find the player.",thePlayer, 255, 0, 0)
    			end
    		end
    	end
    end
    addCommandHandler("action", doAction)

    function unmutePlayer(player,command,victimName)
    	if victimName then
    		local victim = getPlayerFromNamePart(victimName or "")
    		if victim then
    			if ( isPlayerMuted(victim) ) then
    				setPlayerMuted(victim, false)
    			end
    		end
    	end
    end
    addCommandHandler("unmute",unmutePlayer)

    function onJoin ()
        local serial = getPlayerSerial(source)
        local muted = serialMute [ serial ]
        if ( type ( muted ) == "table" ) then
            if ( muted [ 1 ] ) then
                setPlayerMuted ( source, true )
                local timer = setTimer ( unmute, muted [ 1 ], 1, source )
                serialMute [ serial ] [ 2 ] = timer
     
                return
            end
        end
        setPlayerMuted ( source, false )
    end
    addEventHandler ( "onPlayerJoin", getRootElement(), onJoin )
     
    addEventHandler ( "onPlayerQuit", root,
        function ( )
            local serial = getPlayerSerial ( source )
            local muted = serialMute [ serial ]
            if ( type ( muted ) == "table" ) then
                if isTimer ( muted [ 2 ] ) then
                    local timeLeft = getTimerDetails ( muted [ 2 ] )
                    killTimer ( muted [ 2 ] )
                    serialMute [ serial ] [ 1 ] = timeLeft
                end
            end
        end
    )
     
    function unmute ( thePlayer )
        if isElement ( thePlayer ) then
            setPlayerMuted ( thePlayer, false )
            serialMute [ getPlayerSerial ( thePlayer ) ] = nil
            outputChatBox ( "You have been unmuted by Console.", thePlayer, 0, 255, 100 )
        end
    end

    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

Try this

Share this post


Link to post

I just added it in the right place and added an "end" for the if.

Just copy my code, you need to learn more from the wiki how Lua works

Share this post


Link to post
Guest

You are right bro 

thank you very mch

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.