- 39
- 0
почему-то не вписывает текст в инпут, к примеру при поиске сообщения из чата
должно ловить ники где нету заглавных букв типо nick_name
должно ловить ники где нету заглавных букв типо nick_name
Lua:
Игрок djhdhddhbd_djdjfjdnd[440] {4EFF2B}Использует мобильный лаунчер!
Lua:
local imgui = require 'mimgui'
local encoding = require 'encoding'
local sampev = require 'lib.samp.events'
local ffi = require 'ffi'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local renderWindow = imgui.new.bool(false)
local nrpTextBuf = ffi.new("char[?]", 1024 * 10)
local started = false
local maxId = 1000
local responseBuffer = {}
local scanStart = 0
imgui.OnInitialize(function()
imgui.GetIO().IniFilename = nil
end)
local function appendToBuffer(text)
local current = ffi.string(nrpTextBuf)
local newText = (current == "" and text or (current .. "\n" .. text))
if #newText < ffi.sizeof(nrpTextBuf) then
ffi.copy(nrpTextBuf, newText)
end
end
imgui.OnFrame(
function() return renderWindow[0] end,
function()
local resX, resY = getScreenResolution()
local sizeX, sizeY = 400, 400
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
if imgui.Begin('Main Window', renderWindow) then
if imgui.Button("Запустить проверку") then
startCheck()
end
imgui.Separator()
imgui.Text("Найденные НРП ники:")
imgui.InputTextMultiline("##nrptext", nrpTextBuf, ffi.sizeof(nrpTextBuf), imgui.ImVec2(-1, -1))
imgui.End()
end
end
)
function main()
repeat wait(0) until isSampAvailable()
sampRegisterChatCommand('nrplist', function()
renderWindow[0] = not renderWindow[0]
end)
wait(-1)
end
function startCheck()
if started then
sampAddChatMessage(u8:decode"[NRPCheck] Проверка уже запущена!", 0xFF5555)
return
end
started = true
ffi.copy(nrpTextBuf, "")
responseBuffer = {}
scanStart = os.clock()
lua_thread.create(function()
for i = 0, maxId - 1 do
if sampIsPlayerConnected(i) then
sampSendChat("/cl " .. i)
wait(50)
end
end
wait(6000)
started = false
sampAddChatMessage(string.format(u8:decode"[NRPCheck] Проверка завершена за %.2f секунд.", os.clock() - scanStart), 0x80FF80)
end)
end
local function copyToBuffer(buf, str)
ffi.copy(buf, str)
buf[#str] = 0
end
function sampev.onServerMessage(color, text)
if not text or text == '' then return end
local ok, decoded = pcall(function()
return u8:decode(encoding.cp1251_to_utf8(text))
end)
if not ok or not decoded then return end
text = decoded
if started then
local fullNick = text:match("Игрок ([^%s]+%[%d+%])")
if fullNick and not responseBuffer[fullNick] then
local nick = fullNick:match("([^%[]+)%[%d+%]")
if nick and nick:lower() == nick then
responseBuffer[fullNick] = true
local current = ffi.string(nrpTextBuf)
local newText = (current == "" and fullNick or (current .. "\n" .. fullNick))
if #newText < ffi.sizeof(nrpTextBuf) then
copyToBuffer(nrpTextBuf, newText)
end
end
end
end
end
function isNRPName(name)
if not name:find("_") then
return false
end
return not name:find("%u")
end