Lua P-Mute | Блокируем чат недругу

Carrentine

Потрачен
569
460
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Работает по типу записи в переменную замученных игроков и проверки на онлайн?
 
  • Нравится
Реакции: Const

FYS

Потрачен
982
236
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Не знаю связанно ли это как-то с сервером. Но на Аризоне над игроком всёравно появляется текст.
На всех сейчас так, даже после обновы скрипта, все равно на головой не пропадает
 
  • Нравится
Реакции: ya.veter

VRush

https://t.me/vrushscript
Проверенный
2,342
1,089
в моей подписи "Установщик библиотек"

Lua:
script_authors("mxGzz")

local sampev = require 'lib.samp.events'
local inicfg = require 'inicfg'

local defaults = {
    muted = {

    }
}

local ini = inicfg.load(defaults, 'pmuted.ini')

if not doesFileExist('moonloader/mutedtext.log') then
    local log = io.open("moonloader/mutedtext.log", "w")
    log:write('')
    log:close()
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('pmute', pmute)
    sampRegisterChatCommand('punmute', punmute)
    sampRegisterChatCommand('pmutelist', pml)
    while true do
        for nick, time in pairs(ini.muted) do
            if time < os.time() then
                ini.muted[nick] = nil
                inicfg.save(ini, 'pmuted.ini')
                printStringNow(nick .. ' MUTE EXPIRED', 3000)
            end
        end
        wait(1000)
    end
end

function sampev.onServerMessage(color, text)
    for nick, time in pairs(ini.muted) do
        if text:find(nick) then
            local log = io.open("moonloader/mutedtext.log", "a+")
            log:write(os.date('[%H:%M:%S] ') .. text .. '\n')
            return false
        end
    end
end


function pml()
    local text = 'ID\tИгровой ник\tВремя (сек)'
    local dialText = ''
    for nick, time in pairs(ini.muted) do
        --print(1)
        dialText = dialText .. '\n' .. sampGetPlayerIdByNickname(nick) .. '\t' .. nick .. '\t' .. tostring(tonumber(time) - os.time())
    end
    if dialText == '' then
        sampShowDialog(6767, 'Список заткнутых игроков', 'Список заткнутых игроков пуст', 'OK', '', 0)
    else
        --printStringNow('ALIVe', 1000)
        sampShowDialog(6768, 'Список заткнутых игроков', text .. dialText, 'OK', '', 5)
    end
end

function pmute(args)
    if not args:match('%d- %d*') then
        sampAddChatMessage('[P-MUTE]: Используйте /pmute [ID] [Время]', 0x1E90FF)
        return
    end
    local id, time = args:match('(%d-) (%d*)')
    if not sampIsPlayerConnected(id) then
        sampAddChatMessage('[P-MUTE]: Игрок не в сети', 0x1E90FF)
        return
    end
    if ini.muted[sampGetPlayerNickname(id)] then
        sampAddChatMessage('[P-MUTE]: Чат игроку уже заблокирован', 0x1E90FF)
        return
    end
    ini.muted[sampGetPlayerNickname(id)] = os.time() + time*60
    inicfg.save(ini, 'pmuted.ini')
    sampAddChatMessage(sampGetPlayerNickname(id) .. ' был замучен ' .. time .. ' минут', 0x1E90FF)
end

function punmute(id)
    if not sampIsPlayerConnected(id) then
        sampAddChatMessage('[P-MUTE]: Игрок не в сети', 0x1E90FF)
        return
    end
    if not ini.muted[sampGetPlayerNickname(id)] then
        sampAddChatMessage('[P-MUTE]: Игрок не замучен', 0x1E90FF)
        return
    end
    ini.muted[sampGetPlayerNickname(id)] = nil
    inicfg.save(ini, 'pmuted.ini')
    sampAddChatMessage('[P-MUTE]: Затычка с игрока была снята', 0x1E90FF)
end

function sampGetPlayerIdByNickname(nick)
    for i = 0, 999 do
        if sampIsPlayerConnected(i) and sampGetPlayerNickname(i) == nick then
            return i
        end
    end
    return 'N/A'
end
Убрать _ из команд, так лучше как по мне