Улучши функционал скрипта, реализуй полноценную работу скрипта, сделай чтобы координаты…
- User
Улучши функционал скрипта, реализуй полноценную работу скрипта, сделай чтобы координаты ближайшей машины обновлялись, а не были всегда одни, пофикси баги.
local imgui = require("imgui") local encoding = require("encoding") encoding.default = "CP1251" u8 = encoding.UTF8 local window = imgui.ImBool(false) local vehiclesWhitelist = {} local logs = {} local currentTab = imgui.ImInt(1) -- Variable to keep track of the selected tab function main() while not isSampAvailable() do wait(200) end sampAddChatMessage(u8"Скрипт интерфейса запущен. Нажмите F5 для открытия меню.", 0xFFFFFF) imgui.Process = false while true do wait(0) if wasKeyPressed(0x74) then window.v = not window.v imgui.Process = window.v end end end function imgui.OnDrawFrame() if window.v then local resX, resY = getScreenResolution() local sizeX, sizeY = 500, 400 -- Размер окна imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver) imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver) imgui.Begin(u8"Управление транспортом", window) -- Используем переключатели для выбора вкладки if imgui.RadioButton(u8"Белый список", currentTab.v == 1) then currentTab.v = 1 end imgui.SameLine() if imgui.RadioButton(u8"Информация о транспорте", currentTab.v == 2) then currentTab.v = 2 end imgui.SameLine() if imgui.RadioButton(u8"Логи", currentTab.v == 3) then currentTab.v = 3 end imgui.Separator() -- Отображаем содержимое выбранной вкладки if currentTab.v == 1 then drawWhitelistTab() elseif currentTab.v == 2 then drawVehicleInfoTab() elseif currentTab.v == 3 then drawLogsTab() end imgui.End() end end -- Функция для отрисовки вкладки белого списка function drawWhitelistTab() imgui.Text(u8"Добавить транспорт в белый список:") if imgui.Button(u8"Добавить ближайший транспорт") then local vehicle = getNearestVehicle() if vehicle then vehiclesWhitelist[vehicle] = true sampAddChatMessage(u8"Транспорт добавлен в белый список.", 0x00FF00) else sampAddChatMessage(u8"Ближайший транспорт не найден.", 0xFF0000) end end imgui.Separator() imgui.Text(u8"Список транспорта в белом списке:") for veh, _ in pairs(vehiclesWhitelist) do local modelId = getCarModel(veh) local modelName = getVehicleName(modelId) imgui.BulletText(u8(string.format("ID: %d, Модель: %s", veh, modelName))) end end -- Функция для отрисовки вкладки информации о транспорте function drawVehicleInfoTab() local vehicle = getNearestVehicle() if vehicle then local distance = getDistanceToVehicle(vehicle) local health = getCarHealth(vehicle) local passengers = getVehiclePassengerCount(vehicle) imgui.Text(u8(string.format("Расстояние до транспорта: %.2f м", distance))) imgui.Text(u8(string.format("HP транспорта: %d", health))) imgui.Text(u8(string.format("Количество пассажиров: %d", passengers))) else imgui.Text(u8"Ближайший транспорт не найден.") end end -- Функция для отрисовки вкладки логов function drawLogsTab() if imgui.Button(u8"Очистить логи") then logs = {} sampAddChatMessage(u8"Логи очищены.", 0x00FF00) end imgui.Separator() imgui.Text(u8"Журнал событий:") for _, log in ipairs(logs) do imgui.BulletText(u8(log)) end end -- Вспомогательная функция для получения ближайшего транспорта function getNearestVehicle() local vehicles = getAllVehicles() if #vehicles == 0 then return nil end local playerX, playerY, playerZ = getCharCoordinates(PLAYER_PED) local nearestVehicle = nil local minDistanceSquared = nil local MAX_DISTANCE_SQUARED = 10000 -- Максимальное расстояние 100 метров (10 000 кв.м) for _, vehicle in ipairs(vehicles) do if not isCarDead(vehicle) then local vehX, vehY, vehZ = getCarCoordinates(vehicle) local dx = playerX - vehX local dy = playerY - vehY local dz = playerZ - vehZ local distanceSquared = dx * dx + dy * dy + dz * dz if distanceSquared <= MAX_DISTANCE_SQUARED and (minDistanceSquared == nil or distanceSquared < minDistanceSquared) then minDistanceSquared = distanceSquared nearestVehicle = vehicle end end end return nearestVehicle end -- Функция для вычисления расстояния до транспорта function getDistanceToVehicle(vehicle) local playerX, playerY, playerZ = getCharCoordinates(PLAYER_PED) local vehX, vehY, vehZ = getCarCoordinates(vehicle) local dx = playerX - vehX local dy = playerY - vehY local dz = playerZ - vehZ local distance = math.sqrt(dx * dx + dy * dy + dz * dz) return distance end -- Функция для получения количества пассажиров в транспорте function getVehiclePassengerCount(vehicle) local count = 0 for seat = 0, getMaximumNumberOfPassengers(vehicle) do if not isCarPassengerSeatFree(vehicle, seat) then count = count + 1 end end return count end -- Обработчик событий (пример записи логов) function onSomeEvent() -- Пример добавления записи в логи table.insert(logs, os.date("%X") .. u8" Произошло событие.") end - Assistant