Как сделать привязку по нику.

Karvies

Известный
Автор темы
16
1
Версия MoonLoader
Другое
Всем привет, как сделать привязку по нику, допустим либо человек вписывает в окно imgui свой ник, и если этот ник допустим вписан где то, тогда отрубает скрипт или не дает работать. Ну или просто скрипт будет читать с каким ником зашел, и сверяя с сайтом pastebin, из raw будет отключать скрипт если такого ника нет там.
Код:
require 'lib.sampfuncs'
require 'lib.moonloader'

script_name('Automatic REPORT')
script_properties('work-in-pause')
script_version('2.1')
script_authors("KARVIES")
script_version_number(1)

local hook            = require('lib.samp.events')
local inicfg        = require 'inicfg'
local encoding         = require('encoding')
local imgui         = require 'imgui'
local key             = require 'vkeys'
local main_color     = 0x5A90CE
local main_window_state = imgui.ImBool(false)

encoding.default = "cp1251"
u8 = encoding.UTF8

local def = {
    config = {
        nick = "",
    }
}

local save = inicfg.load(def, "lovlyareporta_save")

nick = imgui.ImBuffer(tostring(save.config.nick), 256)

function capture_report(arg)
    report = not report
    if report then
        printStringNow('On', 2000)
    else
        printStringNow('Off', 2000)
    end
end

function hook.onServerMessage(color, text)
    if report then
        if text:find("%[Жалоба%] от .+:") then -- что ищет в чате
            sampSendChat(string.format('/ot', text))
        end
    end

    local id = sampGetPlayerIdByCharHandle(PLAYER_PED)

    if report then
      if text:find("Администратор "..u8:decode(nick.v).."%[(%d+)] ответил игроку (.+)%[(%d+)]:{FFFFFF} (.+)") then
        report = false
      end
    end
end

function imgui.OnDrawFrame()
  if main_window_state.v then -- чтение и запись значения такой переменной осуществляется через поле v (или Value)
    imgui.SetNextWindowSize(imgui.ImVec2(700, 400), imgui.Cond.FirstUseEver) -- меняем размер
    imgui.SetNextWindowPos(imgui.ImVec2(620, 350), imgui.Cond.FirstUseEver)
    imgui.Begin('Report Capture', main_window_state)
    imgui.Text(u8"NICK (Пример: Имя Фамилия)") imgui.SameLine(270)
    if imgui.InputText('##prefix', nick) then
        save.config.nick = nick.v end       
    imgui.End()
  end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end 
  
    sampAddChatMessage("[RepCapture]{7FFFD4} Скрипт подгружен. Версия скрипта 2.2", main_color)
    sampRegisterChatCommand("ar", capture_report) 

    while true do wait(0)
    if wasKeyPressed(key.VK_F10) then -- активация по нажатию клавиши X
        main_window_state.v = not main_window_state.v -- переключаем статус активности окна, не забываем про .v
    end
    imgui.Process = main_window_state.v -- теперь значение imgui.Process всегда будет задаваться в зависимости от активности основного окна 
    end
end 

function onScriptTerminate(script, quitGame)
    if script == thisScript() then
        showCursor(false, false)
        cfgSave()
    end
end

function onQuitGame()
    cfgSave()
end

function cfgSave(v)
    if f == nil then
        inicfg.save(def, "lovlyareporta_save")
        return
    end
    return
end
 
Решение
Не работает

Код:
[18:55:22.358692] (system)    ML-ReloadAll: Loaded successfully.
[18:55:22.358692] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:55:22.358692] (debug)    New script: 1091629C
[18:55:22.380665] (system)    Automatic REPORT: Loaded successfully.
[18:55:22.380665] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\SF Integration.lua'...
[18:55:22.380665] (debug)    New script: 1091DAE4
[18:55:22.383596] (system)    SF Integration: Loaded successfully.
[18:55:24.022800] (system)    Installing post-load hooks...
[18:55:24.022800] (system)    Hooks installed.
[18:56:00.185377] (script)    ML-AutoReboot: Reloading "Automatic REPORT"...
[18:56:01.080905] (system)    Automatic...

Fott

Простреленный
3,431
2,270
 

Karvies

Известный
Автор темы
16
1
Не работает
Код:
[18:55:22.358692] (system)    ML-ReloadAll: Loaded successfully.
[18:55:22.358692] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:55:22.358692] (debug)    New script: 1091629C
[18:55:22.380665] (system)    Automatic REPORT: Loaded successfully.
[18:55:22.380665] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\SF Integration.lua'...
[18:55:22.380665] (debug)    New script: 1091DAE4
[18:55:22.383596] (system)    SF Integration: Loaded successfully.
[18:55:24.022800] (system)    Installing post-load hooks...
[18:55:24.022800] (system)    Hooks installed.
[18:56:00.185377] (script)    ML-AutoReboot: Reloading "Automatic REPORT"...
[18:56:01.080905] (system)    Automatic REPORT: Script terminated. (1091629C)
[18:56:01.081881] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:56:01.081881] (debug)    New script: 4BDBCAD4
[18:56:01.119969] (system)    Automatic REPORT: Loaded successfully.
[18:57:08.691059] (script)    ML-AutoReboot: Reloading "Automatic REPORT"...
[18:57:09.534340] (system)    Automatic REPORT: Script terminated. (4BDBCAD4)
[18:57:09.536292] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:57:09.536292] (debug)    New script: 4BDBC01C
[18:57:09.560219] (system)    Automatic REPORT: Loaded successfully.
 

Fott

Простреленный
3,431
2,270
Не работает

Код:
[18:55:22.358692] (system)    ML-ReloadAll: Loaded successfully.
[18:55:22.358692] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:55:22.358692] (debug)    New script: 1091629C
[18:55:22.380665] (system)    Automatic REPORT: Loaded successfully.
[18:55:22.380665] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\SF Integration.lua'...
[18:55:22.380665] (debug)    New script: 1091DAE4
[18:55:22.383596] (system)    SF Integration: Loaded successfully.
[18:55:24.022800] (system)    Installing post-load hooks...
[18:55:24.022800] (system)    Hooks installed.
[18:56:00.185377] (script)    ML-AutoReboot: Reloading "Automatic REPORT"...
[18:56:01.080905] (system)    Automatic REPORT: Script terminated. (1091629C)
[18:56:01.081881] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:56:01.081881] (debug)    New script: 4BDBCAD4
[18:56:01.119969] (system)    Automatic REPORT: Loaded successfully.
[18:57:08.691059] (script)    ML-AutoReboot: Reloading "Automatic REPORT"...
[18:57:09.534340] (system)    Automatic REPORT: Script terminated. (4BDBCAD4)
[18:57:09.536292] (system)    Loading script 'C:\Games\osnovaSOS\moonloader\reportcapture.lua'...
[18:57:09.536292] (debug)    New script: 4BDBC01C
[18:57:09.560219] (system)    Automatic REPORT: Loaded successfully.
Lua:
require 'lib.sampfuncs'
require 'lib.moonloader'

script_name('Automatic REPORT')
script_properties('work-in-pause')
script_version('2.1')
script_authors("KARVIES")
script_version_number(1)

local hook            = require('lib.samp.events')
local inicfg        = require 'inicfg'
local encoding         = require('encoding')
local imgui         = require 'imgui'
local key             = require 'vkeys'
local requests = require('requests')
local main_color     = 0x5A90CE
local main_window_state = imgui.ImBool(false)

encoding.default = "cp1251"
u8 = encoding.UTF8

local def = {
    config = {
        nick = "",
    }
}

local save = inicfg.load(def, "lovlyareporta_save")

nick = imgui.ImBuffer(tostring(save.config.nick), 256)

function capture_report(arg)
    report = not report
    if report then
        printStringNow('On', 2000)
    else
        printStringNow('Off', 2000)
    end
end

function hook.onServerMessage(color, text)
    if report then
        if text:find("%[Жалоба%] от .+:") then -- что ищет в чате
            sampSendChat(string.format('/ot', text))
        end
    end

    local id = sampGetPlayerIdByCharHandle(PLAYER_PED)

    if report then
      if text:find("Администратор "..u8:decode(nick.v).."%[(%d+)] ответил игроку (.+)%[(%d+)]:{FFFFFF} (.+)") then
        report = false
      end
    end
end

function imgui.OnDrawFrame()
  if main_window_state.v then -- чтение и запись значения такой переменной осуществляется через поле v (или Value)
    imgui.SetNextWindowSize(imgui.ImVec2(700, 400), imgui.Cond.FirstUseEver) -- меняем размер
    imgui.SetNextWindowPos(imgui.ImVec2(620, 350), imgui.Cond.FirstUseEver)
    imgui.Begin('Report Capture', main_window_state)
    imgui.Text(u8"NICK (Пример: Имя Фамилия)") imgui.SameLine(270)
    if imgui.InputText('##prefix', nick) then
        save.config.nick = nick.v end       
    imgui.End()
  end
end

function main()
    repeat wait(0) until isSampAvailable()
    local request = requests.get('ссылка на текст с никами, каждый ник с новой строчки')
    local nick = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
    local function res()
        for n in request.text:gmatch('[^\r\n]+') do
            if nick:find(n) then return true end
        end
        return false
    end
    if not res() then error('не привязан иди покупай') end
    sampAddChatMessage("[RepCapture]{7FFFD4} Скрипт подгружен. Версия скрипта 2.2", main_color)
    sampRegisterChatCommand("ar", capture_report)
    while true do wait(0)
    if wasKeyPressed(key.VK_F10) then -- активация по нажатию клавиши X
        main_window_state.v = not main_window_state.v -- переключаем статус активности окна, не забываем про .v
    end
    imgui.Process = main_window_state.v -- теперь значение imgui.Process всегда будет задаваться в зависимости от активности основного окна
    end
end

function onScriptTerminate(script, quitGame)
    if script == thisScript() then
        showCursor(false, false)
        cfgSave()
    end
end

function onQuitGame()
    cfgSave()
end

function cfgSave(v)
    if f == nil then
        inicfg.save(def, "lovlyareporta_save")
        return
    end
    return
end
 

Karvies

Известный
Автор темы
16
1
Lua:
require 'lib.sampfuncs'
require 'lib.moonloader'

script_name('Automatic REPORT')
script_properties('work-in-pause')
script_version('2.1')
script_authors("KARVIES")
script_version_number(1)

local hook            = require('lib.samp.events')
local inicfg        = require 'inicfg'
local encoding         = require('encoding')
local imgui         = require 'imgui'
local key             = require 'vkeys'
local requests = require('requests')
local main_color     = 0x5A90CE
local main_window_state = imgui.ImBool(false)

encoding.default = "cp1251"
u8 = encoding.UTF8

local def = {
    config = {
        nick = "",
    }
}

local save = inicfg.load(def, "lovlyareporta_save")

nick = imgui.ImBuffer(tostring(save.config.nick), 256)

function capture_report(arg)
    report = not report
    if report then
        printStringNow('On', 2000)
    else
        printStringNow('Off', 2000)
    end
end

function hook.onServerMessage(color, text)
    if report then
        if text:find("%[Жалоба%] от .+:") then -- что ищет в чате
            sampSendChat(string.format('/ot', text))
        end
    end

    local id = sampGetPlayerIdByCharHandle(PLAYER_PED)

    if report then
      if text:find("Администратор "..u8:decode(nick.v).."%[(%d+)] ответил игроку (.+)%[(%d+)]:{FFFFFF} (.+)") then
        report = false
      end
    end
end

function imgui.OnDrawFrame()
  if main_window_state.v then -- чтение и запись значения такой переменной осуществляется через поле v (или Value)
    imgui.SetNextWindowSize(imgui.ImVec2(700, 400), imgui.Cond.FirstUseEver) -- меняем размер
    imgui.SetNextWindowPos(imgui.ImVec2(620, 350), imgui.Cond.FirstUseEver)
    imgui.Begin('Report Capture', main_window_state)
    imgui.Text(u8"NICK (Пример: Имя Фамилия)") imgui.SameLine(270)
    if imgui.InputText('##prefix', nick) then
        save.config.nick = nick.v end     
    imgui.End()
  end
end

function main()
    repeat wait(0) until isSampAvailable()
    local request = requests.get('ссылка на текст с никами, каждый ник с новой строчки')
    local nick = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
    local function res()
        for n in request.text:gmatch('[^\r\n]+') do
            if nick:find(n) then return true end
        end
        return false
    end
    if not res() then error('не привязан иди покупай') end
    sampAddChatMessage("[RepCapture]{7FFFD4} Скрипт подгружен. Версия скрипта 2.2", main_color)
    sampRegisterChatCommand("ar", capture_report)
    while true do wait(0)
    if wasKeyPressed(key.VK_F10) then -- активация по нажатию клавиши X
        main_window_state.v = not main_window_state.v -- переключаем статус активности окна, не забываем про .v
    end
    imgui.Process = main_window_state.v -- теперь значение imgui.Process всегда будет задаваться в зависимости от активности основного окна
    end
end

function onScriptTerminate(script, quitGame)
    if script == thisScript() then
        showCursor(false, false)
        cfgSave()
    end
end

function onQuitGame()
    cfgSave()
end

function cfgSave(v)
    if f == nil then
        inicfg.save(def, "lovlyareporta_save")
        return
    end
    return
end
Код:
[ML] (error) Automatic REPORT: C:\Games\osnovaSOS\moonloader\reportcapture.lua:79:  не привязан иди покупай
stack traceback:
    [C]: in function 'error'
    C:\Games\osnovaSOS\moonloader\reportcapture.lua:79: in function <C:\Games\osnovaSOS\moonloader\reportcapture.lua:69>
[ML] (error) Automatic REPORT: Script died due to an error. (4BDBC01C)
 

Fott

Простреленный
3,431
2,270
Код:
[ML] (error) Automatic REPORT: C:\Games\osnovaSOS\moonloader\reportcapture.lua:79:  не привязан иди покупай
stack traceback:
    [C]: in function 'error'
    C:\Games\osnovaSOS\moonloader\reportcapture.lua:79: in function <C:\Games\osnovaSOS\moonloader\reportcapture.lua:69>
[ML] (error) Automatic REPORT: Script died due to an error. (4BDBC01C)
[ML] (error) Automatic REPORT: C:\Games\osnovaSOS\moonloader\reportcapture.lua:79: не привязан иди покупай
if not res() then error('не привязан иди покупай') end
Ник свой в пастебин список добавь
 

Karvies

Известный
Автор темы
16
1
[ML] (error) Automatic REPORT: C:\Games\osnovaSOS\moonloader\reportcapture.lua:79: не привязан иди покупай
if not res() then error('не привязан иди покупай') end
Ник свой в пастебин список добавь
1598112539186.png