script_name('Event Helper')
-- libs
local imgui = require('mimgui')
local encoding = require('encoding')
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local sf = string.format
-- frames
local general = imgui.new.bool(false)
local demo = imgui.new.bool(false)
local frames = {}
-- imgui params
local sizeButton = imgui.ImVec2(70, 40)
local plvehModelCarId = imgui.new.int(541)
local plvehMaxDistance = imgui.new.int(100)
local plvehTwinTurbo = imgui.new.bool(false)
-- other params
local plvehStatusGive = false
local function setBlueTheme()
imgui.SwitchContext()
local st = imgui.GetStyle()
local cl = st.Colors
local icl = imgui.Col
st.WindowPadding = imgui.ImVec2(15, 15)
st.WindowRounding = 10.0
st.ChildRounding = 6.0
st.FramePadding = imgui.ImVec2(8, 7)
st.FrameRounding = 8.0
st.ItemSpacing = imgui.ImVec2(8, 8)
st.ItemInnerSpacing = imgui.ImVec2(10, 6)
st.IndentSpacing = 25.0
st.ScrollbarSize = 13.0
st.ScrollbarRounding = 12.0
st.GrabMinSize = 10.0
st.GrabRounding = 6.0
st.PopupRounding = 8
st.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
st.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
cl[icl.Text] = imgui.ImVec4(0.90, 0.90, 0.93, 1.00)
cl[icl.TextDisabled] = imgui.ImVec4(0.40, 0.40, 0.45, 1.00)
cl[icl.WindowBg] = imgui.ImVec4(0.12, 0.12, 0.14, 1.00)
cl[icl.ChildBg] = imgui.ImVec4(0.18, 0.20, 0.22, 0.30)
cl[icl.PopupBg] = imgui.ImVec4(0.13, 0.13, 0.15, 1.00)
cl[icl.Border] = imgui.ImVec4(0.30, 0.30, 0.35, 1.00)
cl[icl.BorderShadow] = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
cl[icl.FrameBg] = imgui.ImVec4(0.18, 0.18, 0.20, 1.00)
cl[icl.FrameBgHovered] = imgui.ImVec4(0.25, 0.25, 0.28, 1.00)
cl[icl.FrameBgActive] = imgui.ImVec4(0.30, 0.30, 0.34, 1.00)
cl[icl.TitleBg] = imgui.ImVec4(0.15, 0.15, 0.17, 1.00)
cl[icl.TitleBgCollapsed] = imgui.ImVec4(0.10, 0.10, 0.12, 1.00)
cl[icl.TitleBgActive] = imgui.ImVec4(0.15, 0.15, 0.17, 1.00)
cl[icl.MenuBarBg] = imgui.ImVec4(0.12, 0.12, 0.14, 1.00)
cl[icl.ScrollbarBg] = imgui.ImVec4(0.12, 0.12, 0.14, 1.00)
cl[icl.ScrollbarGrab] = imgui.ImVec4(0.30, 0.30, 0.35, 1.00)
cl[icl.ScrollbarGrabHovered] = imgui.ImVec4(0.40, 0.40, 0.45, 1.00)
cl[icl.ScrollbarGrabActive] = imgui.ImVec4(0.50, 0.50, 0.55, 1.00)
cl[icl.CheckMark] = imgui.ImVec4(0.70, 0.70, 0.90, 1.00)
cl[icl.SliderGrab] = imgui.ImVec4(0.70, 0.70, 0.90, 1.00)
cl[icl.SliderGrabActive] = imgui.ImVec4(0.80, 0.80, 0.90, 1.00)
cl[icl.Button] = imgui.ImVec4(0.18, 0.18, 0.20, 1.00)
cl[icl.ButtonHovered] = imgui.ImVec4(0.60, 0.60, 0.90, 1.00)
cl[icl.ButtonActive] = imgui.ImVec4(0.28, 0.56, 0.96, 1.00)
cl[icl.Header] = imgui.ImVec4(0.20, 0.20, 0.23, 1.00)
cl[icl.HeaderHovered] = imgui.ImVec4(0.25, 0.25, 0.28, 1.00)
cl[icl.HeaderActive] = imgui.ImVec4(0.30, 0.30, 0.34, 1.00)
cl[icl.Separator] = imgui.ImVec4(0.40, 0.40, 0.45, 1.00)
cl[icl.SeparatorHovered] = imgui.ImVec4(0.50, 0.50, 0.55, 1.00)
cl[icl.SeparatorActive] = imgui.ImVec4(0.60, 0.60, 0.65, 1.00)
cl[icl.ResizeGrip] = imgui.ImVec4(0.20, 0.20, 0.23, 1.00)
cl[icl.ResizeGripHovered] = imgui.ImVec4(0.25, 0.25, 0.28, 1.00)
cl[icl.ResizeGripActive] = imgui.ImVec4(0.30, 0.30, 0.34, 1.00)
cl[icl.PlotLines] = imgui.ImVec4(0.61, 0.61, 0.64, 1.00)
cl[icl.PlotLinesHovered] = imgui.ImVec4(0.70, 0.70, 0.75, 1.00)
cl[icl.PlotHistogram] = imgui.ImVec4(0.61, 0.61, 0.64, 1.00)
cl[icl.PlotHistogramHovered] = imgui.ImVec4(0.70, 0.70, 0.75, 1.00)
cl[icl.TextSelectedBg] = imgui.ImVec4(0.30, 0.30, 0.34, 1.00)
cl[icl.ModalWindowDimBg] = imgui.ImVec4(0.10, 0.10, 0.12, 0.80)
cl[icl.Tab] = imgui.ImVec4(0.18, 0.20, 0.22, 1.00)
cl[icl.TabHovered] = imgui.ImVec4(0.60, 0.60, 0.90, 1.00)
cl[icl.TabActive] = imgui.ImVec4(0.28, 0.56, 0.96, 1.00)
end
local function alert(text)
local tag = thisScript().name
local fmt = sf('[%s] {FFFFFF}%s', tag, text)
sampAddChatMessage(fmt, 0x4D00B3FF)
-- format color sampAddChatMessage: 0xRRGGBBAA, 0xRedGreenBlueAlpha
end
local function giveAllPlveh()
plvehStatusGive = not plvehStatusGive
if not plvehStatusGive then
alert('Внезапно закончил выдачу авто')
return
end
lua_thread.create(function()
alert('Начинаю выдачу авто')
for playerId = 0, sampGetMaxPlayerId(false) do
if not plvehStatusGive then break end -- прерывание цикл если give окажется отрицательный
if sampIsPlayerConnected(playerId) then -- игрок в сети?
local exist, playerPed = sampGetCharHandleBySampPlayerId(playerId)
-- существует? и чар тоже существует? и чар не находится в машинке?
if exist and doesCharExist(playerPed) and not isCharInAnyCar(playerPed) then
local myPos = { getCharCoordinates(PLAYER_PED) }
local plPos = { getCharCoordinates(playerPed) }
local distance = getDistanceBetweenCoords3d(
myPos[1], myPos[2], myPos[3],
plPos[1], plPos[2], plPos[3]
)
if distance < tonumber(plvehMaxDistance) then
local command = sf(
'/plveh %d %d %d',
playerId, plvehModelCarId[0],
plvehTwinTurbo[0] and 1 or 0
)
sampSendChat(command)
wait(1000)
-- лучше поставить задержку после отправки чата. вдруг он не в радиусе?
else
local playerNickname = sampGetPlayerNickname(playerId)
local fmt = sf(
'Игрок %s[%d] находится вне радиуса (%d м.)',
playerNickname, playerId, distance
)
alert(fmt)
end
end
end
end
if plvehStatusGive then
plvehStatusGive = false
alert('Закончил выдачу авто')
end
end)
end
imgui.OnInitialize(function()
imgui.GetIO().IniFilename = nil
setBlueTheme()
end)
frames.demo = imgui.OnFrame(function() return demo[0] end, function()
imgui.ShowDemoWindow()
end)
frames.general = imgui.OnFrame(function() return general[0] end, function()
local screen = imgui.ImVec2(getScreenResolution())
imgui.SetNextWindowSize(imgui.ImVec2(950, 550), imgui.Cond.FirstUseEver)
imgui.SetNextWindowPos(imgui.ImVec2(screen.x / 2, screen.y / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
if imgui.Begin(u8(thisScript().name .. ' - Основное меню'), general, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse) then
-- Навигация
imgui.SetCursorPos(imgui.ImVec2(5, 35))
imgui.BeginGroup()
if imgui.Button(u8 'Основное', sizeButton) then tab = 0 end
if imgui.Button(u8 'Дерби', sizeButton) then tab = 1 end
imgui.EndGroup()
-- Вколадки
if tab == 0 then
-- empty code
elseif tab == 1 then
imgui.SetCursorPos(imgui.ImVec2(90, 30))
imgui.Text(u8 'Выдача авто в радиусе')
imgui.SetCursorPos(imgui.ImVec2(90, 60))
imgui.PushItemWidth(50)
imgui.InputInt(u8 'Максимум радиус выдачи', plvehMaxDistance)
imgui.PopItemWidth()
imgui.SetCursorPos(imgui.ImVec2(90, 90))
imgui.PushItemWidth(50)
imgui.InputInt(u8 'ID Model Car', plvehModelCarId)
imgui.PopItemWidth()
imgui.SetCursorPos(imgui.ImVec2(190, 120))
imgui.Checkbox(u8 'TwinTurbo', plvehTwinTurbo)
imgui.SetCursorPos(imgui.ImVec2(90, 120))
if imgui.Button(u8 'Выдать авто') then
giveAllPlveh()
end
end
end
imgui.End()
end)
function main()
repeat wait(0) until isSampAvailable()
alert('Скрипт загружен')
sampRegisterChatCommand('event', function()
general[0] = not general[0]
tab = 0
end)
sampRegisterChatCommand('demo', function()
demo[0] = not demo[0]
end)
-- если замечаешь что скрипт открылся и внезапно закрылся, то указать:
-- wait(-1)
end