script_name('Script for CNN') -- название скрипта
script_author('Raffaello_Sabiny') -- автор скрипта
script_description('CNN by Sabiny') -- описание скрипта
require "lib.moonloader" -- подключение библиотеки
local imgui = require 'imgui'
local vkeys = require 'vkeys'
local fa = require 'fAwesome5'
local mc = 0x5A90CE
local gc = 0x00FF00
local imgui = require 'imgui' -- загружаем библиотеку
local encoding = require 'encoding' -- загружаем библиотеку
encoding.default = 'CP1251' -- указываем кодировку по умолчанию, она должна совпадать с кодировкой файла. CP1251 - это Windows-1251
u8 = encoding.UTF8 -- и создаём короткий псевдоним для кодировщика UTF-8
local test_text_buffer = imgui.ImBuffer(256)
local main_window_state = imgui.ImBool(false)
local russian_characters = {
[168] = 'Ё', [184] = 'ё', [192] = 'А', [193] = 'Б', [194] = 'В', [195] = 'Г', [196] = 'Д', [197] = 'Е', [198] = 'Ж', [199] = 'З', [200] = 'И', [201] = 'Й', [202] = 'К', [203] = 'Л', [204] = 'М', [205] = 'Н', [206] = 'О', [207] = 'П', [208] = 'Р', [209] = 'С', [210] = 'Т', [211] = 'У', [212] = 'Ф', [213] = 'Х', [214] = 'Ц', [215] = 'Ч', [216] = 'Ш', [217] = 'Щ', [218] = 'Ъ', [219] = 'Ы', [220] = 'Ь', [221] = 'Э', [222] = 'Ю', [223] = 'Я', [224] = 'а', [225] = 'б', [226] = 'в', [227] = 'г', [228] = 'д', [229] = 'е', [230] = 'ж', [231] = 'з', [232] = 'и', [233] = 'й', [234] = 'к', [235] = 'л', [236] = 'м', [237] = 'н', [238] = 'о', [239] = 'п', [240] = 'р', [241] = 'с', [242] = 'т', [243] = 'у', [244] = 'ф', [245] = 'х', [246] = 'ц', [247] = 'ч', [248] = 'ш', [249] = 'щ', [250] = 'ъ', [251] = 'ы', [252] = 'ь', [253] = 'э', [254] = 'ю', [255] = 'я',
}
local searchButton = imgui.ImBuffer(128)
-- Сюда добавлять названия для кнопок, продолжать можешь сколько угодно
local buttonName = {
u8'Бар 51',
u8'Продажа дома в ЛВ',
u8'Продажа дома в ЛС',
u8'Продажа дома в СФ',
u8'Промокод Самп',
u8'Продам Маска демона',
u8'Куплю Замок на грудь'
}
-- Сюда добавлять текст для диалога, продолжать можешь сколько угодно
local buttonText = {
"В баре 51 на пляже Санта-Мария отдыхает много людей.Ждем всех",
"Продам дом в г.Лас-Вентурас.Цена: договорная",
"Продам дом в г.Лос-Сантос.Цена: договорная",
"Продам дом в г.Сан-Фиерро.Цена: договорная",
"Вводите купон #самп и получите приятные бонусы",
"Продам а/с Маска Демона.Цена: договорная",
"Куплю а/с Замок на грудь.Бюджет:свободный"
}
math.randomseed(os.time() - os.clock() * 1000)
function main()
sampAddChatMessage("[CNN by Sabiny]:{FFFFFF} Редактор обьявлений успешно загружен.", gc)
sampRegisterChatCommand("redak", function() main_window_state.v = not main_window_state.v end) -- Команда /cnn
while true do
wait(0)
local result, button, list, input = sampHasDialogRespond(557)
if result then
if button == 1 then
if list == 0 then
lua_thread.create(function(input)
sampSendChat('')
end, input)
end
end
end
imgui.Process = main_window_state.v
end
end
function imgui.OnDrawFrame()
if main_window_state.v then
local sw, sh = getScreenResolution()
imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(500, 250), imgui.Cond.FirstUseEver)
imgui.Begin(u8'Sabiny', main_window_state, imgui.WindowFlags.NoResize)
imgui.InputText('##search', searchButton)
for i = 1, #buttonName do
if searchButton.v == "" then
if imgui.Button(buttonName[i], imgui.ImVec2(-0.1, 20) )then
sampSendDialogResponse(557, 1, 1, buttonText[i])
end
elseif string.lower(buttonName[i]):find(searchButton.v) or string.upper(buttonName[i]):find(searchButton.v) or string.rlower(u8:decode(buttonName[i])):find(u8:decode(searchButton.v)) or string.rupper(u8:decode(buttonName[i])):find(u8:decode(searchButton.v)) then
if imgui.Button(buttonName[i], imgui.ImVec2(-0.1, 20) )then
sampSendDialogResponse(557, 1, 1, buttonText[i])
end
end
end
imgui.End()
end
end
function string.rlower(s)
s = s:lower()
local strlen = s:len()
if strlen == 0 then return s end
s = s:lower()
local output = ''
for i = 1, strlen do
local ch = s:byte(i)
if ch >= 192 and ch <= 223 then
output = output .. russian_characters[ch + 32]
elseif ch == 168 then
output = output .. russian_characters[184]
else
output = output .. string.char(ch)
end
end
return output
end
function string.rupper(s)
s = s:upper()
local strlen = s:len()
if strlen == 0 then return s end
s = s:upper()
local output = ''
for i = 1, strlen do
local ch = s:byte(i)
if ch >= 224 and ch <= 255 then
output = output .. russian_characters[ch - 32]
elseif ch == 184 then
output = output .. russian_characters[168]
else
output = output .. string.char(ch)
end
end
return output
end