- 76
- 35
- Версия MoonLoader
- .026-beta
У меня есть например поле для ввода текста. В него человек вводит свой номер телефона. Как мне сохранить номер в ини файл который ввёл игрок в поле? Вот код
Lua:
imgui.PushItemWidth(200)
imgui.InputText(u8"Ваш номер телефона", textPhone)
imgui.PopItemWidth()
Код ини файла:
INI:
[config]
name=Test
age=22
phone=228666777
Фулл код
Lua:
script_name("GOV | Grand Role Play")
script_author("Degrando", "Jesus_McWood")
script_version("1.0")
require "lib.moonloader"
require "lib.sampfuncs"
require "lib.vkeys"
local imgui = require 'imgui'
local inicfg = require 'inicfg'
local fa = require 'fAwesome5'
local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
local sampev = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local two_window_state = imgui.ImBool(false)
local three_window_state = imgui.ImBool(false)
local for_window_state = imgui.ImBool(false)
local textName = imgui.ImBuffer(256)
local textPhone = imgui.ImBuffer(256)
local textAge = imgui.ImBuffer(256)
local combo_rang = imgui.ImInt(0)
local arr_str = {u8"Водитель", u8"Сотрудник СБ", u8"Начальник СБ", u8"Секретарь", u8"Помощник советника", u8"Советник", u8"Адвокат", u8"Депутат", u8"Вице-Президент", u8"Президент"}
local sw, sh = getScreenResolution()
local ImVec2 = imgui.ImVec2
local tag = "{008080}[GOV]"
local main_color = 0x20B2AA
local main_color_text = "{008080}"
local white_color = "{FFFFFF}"
local directIni = "moonloader\\GOV\\settings.ini"
local mainIni = inicfg.load(nil, directIni)
--local stateIni = inicfg.save(mainIni, directIni)
function imgui.BeforeDrawFrame()
if fa_font == nil then
local font_config = imgui.ImFontConfig()
font_config.MergeMode = true
fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 20.0, font_config, fa_glyph_ranges)
end
end
function apply_custom_style()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
style.WindowRounding = 2.0
style.WindowTitleAlign = ImVec2(0.5, 0.5)
style.ChildWindowRounding = 2.0
style.FrameRounding = 2.0
style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
style.ScrollbarSize = 13.0
style.ScrollbarRounding = 0
style.GrabMinSize = 8.0
style.GrabRounding = 1.0
colors[clr.FrameBg] = ImVec4(0.16, 0.48, 0.42, 0.54)
colors[clr.FrameBgHovered] = ImVec4(0.26, 0.98, 0.85, 0.40)
colors[clr.FrameBgActive] = ImVec4(0.26, 0.98, 0.85, 0.67)
colors[clr.TitleBg] = ImVec4(0.04, 0.04, 0.04, 1.00)
colors[clr.TitleBgActive] = ImVec4(0.16, 0.48, 0.42, 1.00)
colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
colors[clr.CheckMark] = ImVec4(0.26, 0.98, 0.85, 1.00)
colors[clr.SliderGrab] = ImVec4(0.24, 0.88, 0.77, 1.00)
colors[clr.SliderGrabActive] = ImVec4(0.26, 0.98, 0.85, 1.00)
colors[clr.Button] = ImVec4(0.26, 0.98, 0.85, 0.40)
colors[clr.ButtonHovered] = ImVec4(0.26, 0.98, 0.85, 1.00)
colors[clr.ButtonActive] = ImVec4(0.06, 0.98, 0.82, 1.00)
colors[clr.Header] = ImVec4(0.26, 0.98, 0.85, 0.31)
colors[clr.HeaderHovered] = ImVec4(0.26, 0.98, 0.85, 0.80)
colors[clr.HeaderActive] = ImVec4(0.26, 0.98, 0.85, 1.00)
colors[clr.Separator] = colors[clr.Border]
colors[clr.SeparatorHovered] = ImVec4(0.10, 0.75, 0.63, 0.78)
colors[clr.SeparatorActive] = ImVec4(0.10, 0.75, 0.63, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.26, 0.98, 0.85, 0.25)
colors[clr.ResizeGripHovered] = ImVec4(0.26, 0.98, 0.85, 0.67)
colors[clr.ResizeGripActive] = ImVec4(0.26, 0.98, 0.85, 0.95)
colors[clr.PlotLines] = ImVec4(0.61, 0.61, 0.61, 1.00)
colors[clr.PlotLinesHovered] = ImVec4(1.00, 0.81, 0.35, 1.00)
colors[clr.TextSelectedBg] = ImVec4(0.26, 0.98, 0.85, 0.35)
colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.TextDisabled] = ImVec4(0.50, 0.50, 0.50, 1.00)
colors[clr.WindowBg] = ImVec4(0.06, 0.06, 0.06, 0.94)
colors[clr.ChildWindowBg] = ImVec4(1.00, 1.00, 1.00, 0.00)
colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
colors[clr.ComboBg] = colors[clr.PopupBg]
colors[clr.Border] = ImVec4(0.43, 0.43, 0.50, 0.50)
colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
colors[clr.MenuBarBg] = ImVec4(0.14, 0.14, 0.14, 1.00)
colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.53)
colors[clr.ScrollbarGrab] = ImVec4(0.31, 0.31, 0.31, 1.00)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
colors[clr.ScrollbarGrabActive] = ImVec4(0.51, 0.51, 0.51, 1.00)
colors[clr.CloseButton] = ImVec4(0.41, 0.41, 0.41, 0.50)
colors[clr.CloseButtonHovered] = ImVec4(0.98, 0.39, 0.36, 1.00)
colors[clr.CloseButtonActive] = ImVec4(0.98, 0.39, 0.36, 1.00)
colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
colors[clr.ModalWindowDarkening] = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
while not sampIsLocalPlayerSpawned() do wait(0) end
sampAddChatMessage(tag .. " {FFFFFF}Скрипт успешно загружен. Автор: {008080}Degrando", 0x008080)
sampAddChatMessage(tag .. " {FFFFFF}Перевод на Lua By {008080}Jesus_McWood", 0x008080)
sampAddChatMessage(tag .. " {FFFFFF}Главное меню скрипта - {008080}/gg", 0x008080)
sampRegisterChatCommand("gg", cmd_gg)
sampRegisterChatCommand("govhelp", cmd_help)
sampRegisterChatCommand("rpt", cmd_rpt)
while true do
wait(0)
imgui.Process = main_window_state.v or two_window_state.v or for_window_state.v
end
end
function cmd_gg()
main_window_state.v = not main_window_state.v
end
function imgui.OnDrawFrame()
if main_window_state.v then --Главное окно
imgui.SetNextWindowSize(imgui.ImVec2(700, 487))
imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.Begin(u8'GOV | Главное меню', main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar)
if imgui.Button(fa.ICON_FA_LIST .. u8" Главная", imgui.ImVec2(120, 80)) then
main_window_state.v = true
end
if imgui.Button(fa.ICON_FA_WRENCH .. u8" Настройки", imgui.ImVec2(120, 80)) then
main_window_state.v = false
two_window_state.v = not two_window_state.v
end
if imgui.Button(fa.ICON_FA_CROWN .. u8" Меню лидера", imgui.ImVec2(120, 80)) then
main_window_state.v = false
three_window_state.v = not three_window_state.v
end
imgui.SameLine(250)
imgui.BeginChild("line",imgui.ImVec2(370, 83), true)
imgui.Text(u8"Информация: \n\nВаше имя: "..mainIni.config.name.. u8"\nВаша возраст: "..mainIni.config.age.. u8" \nВаш телефон:"..mainIni.config.phone)
imgui.EndChild()
if imgui.Button(fa.ICON_FA_INFO_CIRCLE .. u8" О скрипте", imgui.ImVec2(120, 80)) then
main_window_state.v = false
three_window_state.v = not three_window_state.v
end
if imgui.Button(fa.ICON_FA_PEOPLE_CARRY .. u8" Разработчики", imgui.ImVec2(120, 80)) then
main_window_state.v = false
for_window_state.v = not for_window_state.v
end
imgui.Text(u8"Автор скрипта: Degrando")
imgui.Text(u8"Версия скрипта: v1.0")
imgui.End()
end
if two_window_state.v then --Окно настройки
imgui.SetNextWindowSize(imgui.ImVec2(700, 485))
imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.Begin(u8'GOV | Настройки', two_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar)
imgui.PushItemWidth(200)
imgui.InputText(u8"Ваше имя", textName)
imgui.SameLine()
imgui.TextQuestion(u8'Пример: Vasya Pupkin')
imgui.PopItemWidth()
imgui.NewLine()
imgui.PushItemWidth(200)
imgui.Combo(u8"Ваша должность", combo_rang, arr_str, #arr_str)
imgui.PopItemWidth()
imgui.NewLine()
imgui.PushItemWidth(200)
imgui.InputText(u8"Ваш номер телефона", textPhone)
imgui.PopItemWidth()
imgui.NewLine()
imgui.PushItemWidth(200)
imgui.InputText(u8"Ваш возраст", textAge)
imgui.PopItemWidth()
imgui.End()
end
if for_window_state.v then --Окно разработчики
imgui.SetNextWindowSize(imgui.ImVec2(700, 485))
imgui.SetNextWindowPos(imgui.ImVec2((sw / 2), sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.Begin(u8'GOV | Разработчики', for_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar)
if imgui.Button(fa.ICON_FA_LIST .. u8" Главная", imgui.ImVec2(120, 80)) then
for_window_state.v = false
main_window_state.v = not main_window_state.v
end
if imgui.Button(fa.ICON_FA_WRENCH .. u8" Настройки", imgui.ImVec2(120, 80)) then
for_window_state.v = false
two_window_state.v = not two_window_state.v
end
if imgui.Button(fa.ICON_FA_CROWN .. u8" Меню лидера", imgui.ImVec2(120, 80)) then
for_window_state.v = false
three_window_state.v = not three_window_state.v
end
imgui.SameLine(220)
imgui.BeginChild("line",imgui.ImVec2(370, 60), true)
imgui.Text(u8"Скрипт был создан специально для сервера Grand Role Play \n Автор скрипта: Degrando. Перевод на Lua By Jesus_McWood \n Версия скрипта: v1.0")
imgui.EndChild()
if imgui.Button(fa.ICON_FA_INFO_CIRCLE .. u8" О скрипте", imgui.ImVec2(120, 80)) then
for_window_state.v = false
three_window_state.v = not three_window_state.v
end
if imgui.Button(fa.ICON_FA_PEOPLE_CARRY .. u8" Разработчики", imgui.ImVec2(120, 80)) then
for_window_state.v = true
end
imgui.Text(u8"Автор скрипта: Degrando")
imgui.Text(u8"Версия скрипта: v1.0")
imgui.End()
end
end
function imgui.TextQuestion(text)
imgui.TextDisabled('(?)')
if imgui.IsItemHovered() then
imgui.BeginTooltip()
imgui.PushTextWrapPos(450)
imgui.TextUnformatted(text)
imgui.PopTextWrapPos()
imgui.EndTooltip()
end
end