Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script_name('NEWS-HELPER')
- script_author("Serhiy_Rubin")
- local inicfg, sampev, milisec, vkeys = require 'inicfg', require 'lib.samp.events', require 'socket', require 'lib.vkeys'
- require 'lib.sampfuncs'
- require 'lib.moonloader'
- local antiflood = os.clock() * 1000 ; timer = os.clock() ; adid = 21 ; arrayAD = {} ; ad_check = 0
- function main()
- if not isSampLoaded() or not isSampfuncsLoaded() then return end
- while not isSampAvailable() do wait(100) end
- repeat wait(0) until sampGetCurrentServerName() ~= 'SA-MP'
- repeat
- wait(0)
- for id = 0, 2303 do
- if sampTextdrawIsExists(id) and sampTextdrawGetString(id):find('Samp%-Rp.Ru') then
- samp_rp = true
- end
- end
- until samp_rp ~= nil
- _, my_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
- my_nick = sampGetPlayerNickname(my_id)
- ini = inicfg.load({
- Settings = {
- send_number = 0,
- mili_time = 100,
- ad_cena = 100
- },
- Activation = {
- [my_nick] = false,
- },
- Auto = {
- [my_nick] = false,
- },
- Render = {
- FontName='Segoe UI',
- FontSize=10,
- FontFlag=15,
- Color='FFFFFF'
- },
- Pos = {
- X = 0,
- Y = 0
- },
- Key = {
- read = 'VK_1',
- send = 'VK_3',
- auto = 'VK_4',
- ad_list = 'VK_N',
- check_ad = 'VK_O'
- }
- })
- inicfg.save(ini)
- font = renderCreateFont(ini.Render.FontName, ini.Render.FontSize, ini.Render.FontFlag)
- -- Auto-Send settings
- last_send = tonumber(os.date("%S")) ; next_second = math.fmod(last_send + 16, 60) ; status = false
- if math.fmod(next_second, 2) ~= ini.Settings.send_number then
- next_second = next_second - 1
- end
- while true do
- wait(0)
- if ini.Activation[my_nick] then
- doAutoSend()
- doRender()
- doKeyCheck()
- doPos()
- doSetKey()
- end
- end
- end
- -- main
- function doAutoSend()
- local this_second = tonumber(os.date("%S"))
- local this_milisecond = tonumber(tostring(milisec.gettime()):sub(12, 14))
- if this_milisecond ~= nil and this_milisecond ~= 999 and this_second == next_second and this_milisecond > ini.Settings.mili_time then
- status = true
- end
- if ini.Auto[my_nick] and status and (os.clock() * 1000 - antiflood) > 1000 then
- sampSendChat("/adsend "..adid)
- end
- end
- function doRender()
- if sampIsScoreboardOpen() or not sampIsChatVisible() or isKeyDown(116) or isKeyDown(121) then return end
- local S1 = os.clock() * 1000
- local S2 = timer * 1000
- local S3 = (S1 - S2) / 1000
- local autot = (ini.Auto[my_nick] and '!' or '')
- local rttext = string.format("{%s}%s%0.1f", ini.Render.Color, autot, S3)
- renderFontDrawText(font, rttext, ini.Pos.X, ini.Pos.Y, 0xFFFFFFFF)
- end
- function doKeyCheck()
- if (not sampIsDialogActive() or (sampGetCurrentDialogType() ~= 1 and sampGetCurrentDialogType() ~= 3)) and not sampIsChatInputActive() then
- if wasKeyPressed(vkeys[ini.Key.read]) then
- sampSendChat("/adedit "..adid)
- end
- if wasKeyPressed(vkeys[ini.Key.send]) then
- sampSendChat("/adsend "..adid)
- end
- if wasKeyPressed(vkeys[ini.Key.auto]) then
- ini.Auto[my_nick] = not ini.Auto[my_nick]
- inicfg.save(ini)
- end
- if wasKeyPressed(vkeys[ini.Key.ad_list]) then
- list_ad = 1
- lua_thread.create(function()
- repeat
- wait(0)
- if list_ad == 1 and (os.clock() * 1000) - antiflood > 1100 then
- list_ad = -1
- sampSendChat('/n')
- end
- until list_ad == 0
- end)
- end
- if wasKeyPressed(vkeys[ini.Key.check_ad]) then
- ad_check = 1
- lua_thread.create(function()
- repeat
- wait(0)
- if ad_check == 1 and (os.clock() * 1000) - antiflood > 1100 then
- ad_check = -1
- sampSendChat('/n')
- end
- until ad_check == 0
- end)
- end
- end
- end
- function doPos()
- if setpos ~= nil then
- sampSetCursorMode(3)
- curX, curY = getCursorPos()
- ini.Pos.X = curX
- ini.Pos.Y = curY
- if isKeyJustPressed(1) then
- sampSetCursorMode(0)
- setpos = nil
- inicfg.save(ini)
- end
- end
- end
- function doSetKey()
- if setkey ~= nil then
- local key = ""
- for k, v in pairs(vkeys) do
- if wasKeyPressed(v) and k ~= "VK_ESCAPE" and k ~= "VK_RETURN" then
- key = k
- end
- end
- if key ~= '' then
- ini.Key[setkey] = key
- inicfg.save(ini)
- setkey = nil
- Dialog()
- start_dialog(dialog[1])
- end
- end
- end
- -- HOOK
- function sampev.onSendChat(message) antiflood = os.clock() * 1000 end
- function sampev.onSendCommand(cmd) antiflood = os.clock() * 1000
- if cmd:lower() == "/nn" then
- lua_thread.create(function()
- Dialog()
- start_dialog(dialog[1])
- end)
- return false
- end
- end
- function sampev.onServerMessage(color, message)
- if message:find("сотрудник News (.*): (.*)") and my_nick ~= nil then
- if message:find(my_nick) and ini.Auto[my_nick] then
- ini.Auto[my_nick] = false
- inicfg.save(ini)
- end
- last_send = tonumber(os.date("%S"))
- next_second = math.fmod(last_send + 16, 60)
- if math.fmod(next_second, 2) ~= ini.Settings.send_number then
- next_second = next_second - 1
- end
- timer = os.clock()
- status = false
- end
- if message:find('Добавлено новое объявление от .+. Номер объявления (%d+)') then
- local id = tonumber(message:match('Добавлено новое объявление от .+. Номер объявления (%d+)'))
- arrayAD[id] = nil
- end
- if status and message == " Объявления с таким ID не существует" or message == ' Объявление больше не существует' then
- status = false
- end
- if message == ' Не флуди!' then
- if ad_check == -1 then
- ad_check = 1
- end
- if list_ad == -1 then
- list_ad = 1
- end
- end
- if message == ' Вы не репортер' then
- ad_check = 0
- list_ad = 0
- ini.Auto[my_nick] = false
- end
- end
- function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
- if title == 'Репортеры' and text:find('%[3%] Объявления') then -- Меню /n
- if ad_check == -1 then
- ad_check = 2
- ThreadSendDialog(90, dialogId, 1, 3, '[3] Объявления')
- lua_thread.create(function()
- checking, checkall = 0, 0
- repeat wait(0)
- local text = 'Checking '..checking..'/'..checkall
- local x, y = getScreenResolution()
- x = x - renderGetFontDrawTextLength(font, text)
- y = y - renderGetFontDrawHeight(font)
- renderFontDrawText(font, text, x, y, -1)
- until ad_check == 0
- end)
- return false
- end
- if list_ad == -1 then
- list_ad = 0
- ThreadSendDialog(90, dialogId, 1, 3, '[3] Объявления')
- return false
- end
- end
- if title == 'Объявления' and text:find('%[id: ') then -- Объявления
- local array = split(text, '\n')
- local dialogText = ''
- if ad_check == 2 then
- dialogArray = {}
- end
- for k,v in pairs(array) do
- local id = tonumber(v:match('%[id: (%d+)%]'))
- if id ~= nil then
- if ad_check == 2 and not v:find('Проверил') and arrayAD[id] == nil then
- checkall = checkall + 1
- dialogArray[#dialogArray + 1] = { text = v, list = k-1, id = id}
- end
- if arrayAD[id] ~= nil then
- v = v:gsub('%[id', string.format('{59de00}[%s$]{FFFFFF} [id', arrayAD[id]))
- end
- dialogText = string.format('%s%s\n', dialogText, v)
- end
- end
- if ad_check == 2 then ad_check = -2 end
- if ad_check == -2 or ad_check == 3 then
- if dialogArray[#dialogArray] ~= nil then
- adstring = dialogArray[#dialogArray].text
- adid = dialogArray[#dialogArray].id
- ad_check = 3
- ThreadSendDialog(90, 22, 1, dialogArray[#dialogArray].list, adstring)
- dialogArray[#dialogArray] = nil
- return false
- else
- ad_check = 0
- end
- end
- return {dialogId, style, title, button1, button2, dialogText}
- end
- if title == 'Меню' and text:find('%[0%] Читать') then -- Меню редактировать, отправить
- ShowNewsMenu = 1
- if ad_check == 3 then
- ad_check = -3
- ThreadSendDialog(90, dialogId, 1, 0, '[0] Читать')
- return false
- end
- if ad_check == 4 then
- ad_check = -2
- ThreadSendDialog(90, dialogId, 0, 0, '[0] Читать')
- return false
- end
- end
- if title == 'Сообщение' or title == 'Ввод параметра' and ShowNewsMenu ~= nil then -- Диалог с текстом объявления
- ShowNewsMenu = nil
- if adstring ~= nil and not adstring:find('Проверил') then
- arrayAD[adid] = ((#text * ini.Settings.ad_cena) / 100) * 60
- end
- if ad_check == -3 then
- ad_check = 4
- checking = checking + 1
- ThreadSendDialog(90, dialogId, 0, 0, '')
- return false
- end
- end
- end
- function ThreadSendDialog(sleep, id, button, listitem, input)
- lua_thread.create(function(sleep, id, button, listitem, input)
- wait(sleep)
- sampSendDialogResponse(id, button, listitem, input)
- end, sleep, id, button, listitem, input)
- end
- function sampev.onSendDialogResponse(dialogId, button, listboxId, input)
- -- Получаем ID последнего открытого объявления.
- if string.find(sampGetDialogCaption(), "Объявления") and button == 1 then
- local array = split(sampGetDialogText(), '\n')
- for k,v in pairs(array) do
- if listboxId == (k - 1) then
- adid = tonumber(string.match(v, "%[id: (%d+)%]"))
- adstring = input
- end
- end
- end
- end
- -- Dialog
- function Dialog()
- dialog = {
- {
- settings = {title = "NEWS-HELPER" ,style = 4 ,btn1 = "Далее" ,btn2 = "Закрыть" ,forward = "{ffffff}" ,backwards = "\n" ,score = true},
- {
- {
- title = "Таймер объявлений\t"..ON_OFF(ini.Activation[my_nick]),
- click = function(button, list, input , outs)
- if button == 1 then
- ini.Activation[my_nick] = not ini.Activation[my_nick]
- inicfg.save(ini)
- Dialog()
- return dialog[1]
- end
- end
- },
- {
- title = "Сменить позицию таймера\t",
- click = function(button, list, input , outs)
- if button == 1 then
- setpos = 1
- Dialog()
- return dialog[1]
- end
- end
- },
- {
- title = "[AUTO] Условие 1\t"..(ini.Settings.send_number == 0 and 'Чётные' or 'Нечётные'),
- click = function(button, list, input , outs)
- if button == 1 then
- ini.Settings.send_number = (ini.Settings.send_number == 0 and 1 or 0)
- inicfg.save(ini)
- Dialog()
- return dialog[1]
- end
- end
- },
- {
- title = "[AUTO] Условие 2\t"..ini.Settings.mili_time..' мс.',
- click = function(button, list, input , outs)
- if button == 1 then
- return dialog[2]
- end
- end
- },
- {
- title = "Кнопка для проверки\t"..ini.Key.read:gsub("VK_", ''),
- click = function(button, list, input , outs)
- if button == 1 then
- setkey = 'read'
- sampShowDialog(584, "SET POS", "{FFFFFF}Нажмите на нужную клавишу", "Сохранить", "Назад", 0)
- end
- end
- },
- {
- title = "Кнопка для отправки\t"..ini.Key.send:gsub("VK_", ''),
- click = function(button, list, input , outs)
- if button == 1 then
- setkey = 'send'
- sampShowDialog(584, "SET POS", "{FFFFFF}Нажмите на нужную клавишу", "Сохранить", "Назад", 0)
- end
- end
- },
- {
- title = "Кнопка для авто-отправки\t"..ini.Key.auto:gsub("VK_", ''),
- click = function(button, list, input , outs)
- if button == 1 then
- setkey = 'auto'
- sampShowDialog(584, "SET POS", "{FFFFFF}Нажмите на нужную клавишу", "Сохранить", "Назад", 0)
- end
- end
- },
- {
- title = "Кнопка для открытия списка объявлений\t"..ini.Key.ad_list:gsub("VK_", ''),
- click = function(button, list, input , outs)
- if button == 1 then
- setkey = 'ad_list'
- sampShowDialog(584, "SET POS", "{FFFFFF}Нажмите на нужную клавишу", "Сохранить", "Назад", 0)
- end
- end
- },
- {
- title = "Кнопка для проверки стоимости объявлений\t"..ini.Key.check_ad:gsub("VK_", ''),
- click = function(button, list, input , outs)
- if button == 1 then
- setkey = 'check_ad'
- sampShowDialog(584, "SET POS", "{FFFFFF}Нажмите на нужную клавишу", "Сохранить", "Назад", 0)
- end
- end
- },
- },
- },
- {
- settings = {title = "NEWS-TIMER" ,style = 1 ,btn1 = "Сохранить",btn2 = "Назад",forward = "{ff0000}" ,backwards = "\n" ,score = false},
- {
- text = "{ffffff}Введите миллисекунды от 0 до 1000.",
- {
- click = function(button, list, input , outs)
- if button == 0 then
- return dialog[1]
- else
- sampAddChatMessage("Вы написали в диалог вот это: "..input, 0xffcecece)
- if input:find('%d+') then
- ini.Settings.mili_time = tonumber(input:match('%d+'))
- inicfg.save(ini)
- Dialog()
- return dialog[1]
- else
- sampAddChatMessage("Ошибка. Введите число от 0 до 1000.", 0xffcecece)
- return dialog[2]
- end
- end
- end
- }
- }
- },
- }
- end
- function ON_OFF(bool)
- return (bool and '{45d900}ON' or '{ff0000}OFF')
- end
- -- Function Dialog
- function start_dialog(menu)
- function _dialog(menu, id, outs)
- sampShowDialog(id, menu.settings.title, tbl_split(menu.settings.style, menu, menu.settings.forward ,menu.settings.backwards ,menu.settings.score), menu.settings.btn1, (menu.settings.btn2 ~= nil and menu.settings.btn2 or _), menu.settings.style)
- repeat
- wait(0)
- local result, button, list, input = sampHasDialogRespond(id)
- if result then
- local out, outs = menu[((menu.settings.style == 0 or menu.settings.style == 1 or menu.settings.style == 3) and 1 or ((list + 1) > #menu[1] and 2 or 1))][((menu.settings.style == 0 or menu.settings.style == 1 or menu.settings.style == 3) and 1 or ((list + 1) > #menu[1] and (list - #menu[1]) + 1 or list + 1))].click(button, list, input, outs)
- if type(out) == "table" then
- return _dialog(out, id - 1, outs)
- elseif type(out) == "boolean" then
- if not out then
- return out
- end
- return _dialog(menu, id, outs)
- end
- end
- until result
- end
- function tbl_split(style, tbl, forward ,backwards ,score)
- if style == 2 or style == 4 or style == 5 then
- text = (style == 5 and tbl[1].text.."\n" or "")
- for i, val in ipairs(tbl[1]) do
- text = text..""..forward..""..(score and "["..i.."]{ffffff} " or "")..""..val.title..""..backwards
- end
- if tbl[2] ~= nil then
- for _, val in ipairs(tbl[2]) do
- text = text..""..forward..""..val.title..""..backwards
- end
- end
- return text
- end
- return tbl[1].text
- end
- return _dialog(menu, 1337, outs)
- end
- --- Function split
- function split(str, delim, plain)
- local tokens, pos, plain = {}, 1, not (plain == false) --[[ delimiter is plain text by default ]]
- repeat
- local npos, epos = string.find(str, delim, pos, plain)
- table.insert(tokens, string.sub(str, pos, npos and npos - 1))
- pos = epos and epos + 1
- until not pos
- return tokens
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement