• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.3] !mute command

Deepling

Just a spammer
Joined
Jun 29, 2015
Messages
1,835
Solutions
1
Reaction score
555
Location
Poland
Hello

I need command which mutes player on World Chat [id 3] for specified time.
I want it to look this way !mute playername, time, reason.

00:00 Deepling has been muted for 5 minutes from World Chat. Reason: Spamming.

Thanks!
 
Solution
in talkactions put
Lua:
function onSay(player, words, param)
    local storage = 1500
    local mutetime = 5
    local reason = 'No reason'
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if not getPlayerFlagValue(player, PlayerFlag_CanBroadcast) then
        return true
    end
    local split = param:split(",")
    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end
    if split[2] ~= nil then
        mutetime = split[2]
        if split[3] ~= nil then
            reason = split[3]
        end
    end
    local msg =...
in talkactions put
Lua:
function onSay(player, words, param)
    local storage = 1500
    local mutetime = 5
    local reason = 'No reason'
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if not getPlayerFlagValue(player, PlayerFlag_CanBroadcast) then
        return true
    end
    local split = param:split(",")
    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end
    if split[2] ~= nil then
        mutetime = split[2]
        if split[3] ~= nil then
            reason = split[3]
        end
    end
    local msg = target:getName()..' has been muted for '..mutetime..' minutes.  Reason:'..reason..'.'
    print("> " .. player:getName() .. " broadcasted: \"" .. msg .. "\".")
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendPrivateMessage(player, msg, TALKTYPE_BROADCAST)
    end
    target:setStorageValue(storage,os.time()+mutetime*60*1000)
    return false
end
then in chatchannels, in the lua of the channel you want to be muted from, add below
Lua:
function onSpeak(player, type, message)
this:
Lua:
    local mutedstorage = 1500
    if player:getStorageValue(mutedstorage) > os.time() then
        player:sendCancelMessage("You have been muted, try again later.")
        return false
    end
not tested
 
Solution
in talkactions put
Lua:
function onSay(player, words, param)
    local storage = 1500
    local mutetime = 5
    local reason = 'No reason'
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if not getPlayerFlagValue(player, PlayerFlag_CanBroadcast) then
        return true
    end
    local split = param:split(",")
    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end
    if split[2] ~= nil then
        mutetime = split[2]
        if split[3] ~= nil then
            reason = split[3]
        end
    end
    local msg = target:getName()..' has been muted for '..mutetime..' minutes.  Reason:'..reason..'.'
    print("> " .. player:getName() .. " broadcasted: \"" .. msg .. "\".")
    for _, targetPlayer in ipairs(Game.getPlayers()) do
        targetPlayer:sendPrivateMessage(player, msg, TALKTYPE_BROADCAST)
    end
    target:setStorageValue(storage,os.time()+mutetime*60*1000)
    return false
end
then in chatchannels, in the lua of the channel you want to be muted from, add below
Lua:
function onSpeak(player, type, message)
this:
Lua:
    local mutedstorage = 1500
    if player:getStorageValue(mutedstorage) > os.time() then
        player:sendCancelMessage("You have been muted, try again later.")
        return false
    end
not tested
Thanks @Aled it worked perfectly!
Just you missed one 'end' in the script, to make it work I had to add it in line 32.
Edit: I muted player for one minute, already 5 minutes passed and he is still muted. Any suggestions?
 
/mute playername, channelId, time(in minutes), optional reason.

Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")
    if split[3] == nil then
        player:sendCancelMessage("Insufficient parameters. /muted playername, channel Id, time, reason.")
        return false
    end

    local target = Player(split[1])
    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end

    local channelId = tonumber(split[2])
    if type(channelId) ~= 'number' or channelId > 8 then
        player:sendCancelMessage("Channel ID is invalid.")
        return false
    end
  
    local mutedTime = tonumber(split[3])
    if type(mutedTime) ~= 'number' then
        player:sendCancelMessage("Muted time is invalid.")
        return false
    end

    local reasonText = ""
    if reasonTime ~= nil then
    reasonTime = tostring(split[4])
    end
  
local muted = Condition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT)
muted:setParameter(CONDITION_PARAM_SUBID, channelId)
muted:setParameter(CONDITION_PARAM_TICKS, mutedTime * 60 * 1000)

target:addCondition(muted)
sendChannelMessage(channelId, TALKTYPE_CHANNEL_O, string.format("Player %s has been muted for %d minutes. Reason: %s.", target:getName(), mutedTime, reasonText))
    return false
end

Add something like this to every channel script you want:
Lua:
        if player:getCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNELIDHERE) then
        player:sendCancelMessage("You are muted from the CHANNELNAMEHERE for using it inappropriately.")
        return false
    end
 
Thanks @Aled it worked perfectly!
Just you missed one 'end' in the script, to make it work I had to add it in line 32.
Edit: I muted player for one minute, already 5 minutes passed and he is still muted. Any suggestions?
lol my bad, os.time() is not in milliseconds
change
Lua:
target:setStorageValue(storage,os.time()+mutetime*60*1000)
to
Lua:
target:setStorageValue(storage,os.time()+mutetime*60)
he is muted for 17 hours or so, to fix it just mute him again lol
2Rec does exactly the same thing just in a different way, arguably better
 
Back
Top