diff --git a/server-data/resources/[bpt_addons]/bpt_hud/LICENSE b/server-data/resources/[bpt_addons]/bpt_hud/LICENSE index 7c1b638e7..4bbe035a0 100644 --- a/server-data/resources/[bpt_addons]/bpt_hud/LICENSE +++ b/server-data/resources/[bpt_addons]/bpt_hud/LICENSE @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - Copyright (C) 2022-2024 bitpredator + bpt_hud Copyright (C) 2022-2024 bitpredator This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/server-data/resources/[bpt_addons]/bpt_hud/client/carhud.lua b/server-data/resources/[bpt_addons]/bpt_hud/client/carhud.lua index 55ab5425b..695f90f66 100644 --- a/server-data/resources/[bpt_addons]/bpt_hud/client/carhud.lua +++ b/server-data/resources/[bpt_addons]/bpt_hud/client/carhud.lua @@ -43,193 +43,161 @@ local currentFuel = 0.0 -- Main thread CreateThread(function() - -- Initialize local variable - local currSpeed = 0.0 - local cruiseSpeed = 999.0 - local prevVelocity = { x = 0.0, y = 0.0, z = 0.0 } - local cruiseIsOn = false - local seatbeltIsOn = false - - while true do - -- Loop forever and update HUD every frame - Wait(0) - - -- Get player PED, position and vehicle and save to locals - local player = GetPlayerPed(-1) - local position = GetEntityCoords(player) - local vehicle = GetVehiclePedIsIn(player, false) - - -- Set vehicle states - if IsPedInAnyVehicle(player, false) then - pedInVeh = true - else - -- Reset states when not in car - pedInVeh = false - cruiseIsOn = false - seatbeltIsOn = false - end - - -- Display Location and time when in any vehicle or on foot (if enabled) - if pedInVeh or locationAlwaysOn then - -- Get time and display - drawTxt(timeText, 4, locationColorText, 0.4, screenPosX, screenPosY + 0.048) - - -- Display remainder of HUD when engine is on and vehicle is not a bicycle - local vehicleClass = GetVehicleClass(vehicle) - if pedInVeh and GetIsVehicleEngineRunning(vehicle) and vehicleClass ~= 13 then - -- Save previous speed and get current speed - local prevSpeed = currSpeed - currSpeed = GetEntitySpeed(vehicle) - - -- Set PED flags - SetPedConfigFlag(PlayerPedId(), 32, true) - - -- Check if seatbelt button pressed, toggle state and handle seatbelt logic - if - IsControlJustReleased(0, seatbeltInput) - and (enableController or GetLastInputMethod(0)) - and vehicleClass ~= 8 - then - -- Toggle seatbelt status and play sound when enabled - seatbeltIsOn = not seatbeltIsOn - if seatbeltPlaySound then - PlaySoundFrontend(-1, "Faster_Click", "RESPAWN_ONLINE_SOUNDSET", 1) - end - end - if not seatbeltIsOn then - -- Eject PED when moving forward, vehicle was going over 45 MPH and acceleration over 100 G's - local vehIsMovingFwd = GetEntitySpeedVector(vehicle, true).y > 1.0 - local vehAcc = (prevSpeed - currSpeed) / GetFrameTime() - if - vehIsMovingFwd - and (prevSpeed > (seatbeltEjectSpeed / 2.237)) - and (vehAcc > (seatbeltEjectAccel * 9.81)) - then - SetEntityCoords(player, position.x, position.y, position.z - 0.47, true, true, true) - SetEntityVelocity(player, prevVelocity.x, prevVelocity.y, prevVelocity.z) - Wait(1) - SetPedToRagdoll(player, 1000, 1000, 0, 0, 0, 0) - else - -- Update previous velocity for ejecting player - prevVelocity = GetEntityVelocity(vehicle) - end - elseif seatbeltDisableExit then - -- Disable vehicle exit when seatbelt is on - DisableControlAction(0, 75) - end - - -- When player in driver seat, handle cruise control - if GetPedInVehicleSeat(vehicle, -1) == player then - -- Check if cruise control button pressed, toggle state and set maximum speed appropriately - if IsControlJustReleased(0, cruiseInput) and (enableController or GetLastInputMethod(0)) then - cruiseIsOn = not cruiseIsOn - cruiseSpeed = currSpeed - end - local maxSpeed = cruiseIsOn and cruiseSpeed - or GetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDriveMaxFlatVel") - SetEntityMaxSpeed(vehicle, maxSpeed) - else - -- Reset cruise control - cruiseIsOn = false - end - - -- Check what units should be used for speed - if ShouldUseMetricMeasurements() then - -- Get vehicle speed in KPH and draw speedometer - local speed = currSpeed * 3.6 - local speedColor = (speed >= speedLimit) and speedColorOver or speedColorUnder - drawTxt( - ("%.3d"):format(math.ceil(speed)), - 2, - speedColor, - 0.8, - screenPosX + 0.000, - screenPosY + 0.000 - ) - drawTxt("KPH", 2, speedColorText, 0.4, screenPosX + 0.030, screenPosY + 0.018) - else - -- Get vehicle speed in MPH and draw speedometer - local speed = currSpeed * 2.23694 - local speedColor = (speed >= speedLimit) and speedColorOver or speedColorUnder - drawTxt( - ("%.3d"):format(math.ceil(speed)), - 2, - speedColor, - 0.8, - screenPosX + 0.000, - screenPosY + 0.000 - ) - drawTxt("MPH", 2, speedColorText, 0.4, screenPosX + 0.030, screenPosY + 0.018) - end - - -- Draw fuel gauge - local fuelColor = (currentFuel >= fuelWarnLimit) and fuelColorOver or fuelColorUnder - drawTxt( - ("%.3d"):format(math.ceil(currentFuel)), - 2, - fuelColor, - 0.8, - screenPosX + 0.055, - screenPosY + 0.000 - ) - drawTxt("FUEL", 2, fuelColorText, 0.4, screenPosX + 0.085, screenPosY + 0.018) - - -- Draw cruise control status - local cruiseColor = cruiseIsOn and cruiseColorOn or cruiseColorOff - drawTxt("CRUISE", 2, cruiseColor, 0.4, screenPosX + 0.020, screenPosY + 0.048) - - -- Draw seatbelt status if not a motorcyle - if vehicleClass ~= 8 then - local seatbeltColor = seatbeltIsOn and seatbeltColorOn or seatbeltColorOff - drawTxt("SEATBELT", 2, seatbeltColor, 0.4, screenPosX + 0.080, screenPosY + 0.048) - end - end - end - end + -- Initialize local variable + local currSpeed = 0.0 + local cruiseSpeed = 999.0 + local prevVelocity = { x = 0.0, y = 0.0, z = 0.0 } + local cruiseIsOn = false + local seatbeltIsOn = false + + while true do + -- Loop forever and update HUD every frame + Wait(0) + + -- Get player PED, position and vehicle and save to locals + local player = PlayerPedId() + local position = GetEntityCoords(player) + local vehicle = GetVehiclePedIsIn(player, false) + + -- Set vehicle states + if IsPedInAnyVehicle(player, false) then + pedInVeh = true + else + -- Reset states when not in car + pedInVeh = false + cruiseIsOn = false + seatbeltIsOn = false + end + + -- Display Location and time when in any vehicle or on foot (if enabled) + if pedInVeh or locationAlwaysOn then + -- Get time and display + drawTxt(timeText, 4, locationColorText, 0.4, screenPosX, screenPosY + 0.048) + + -- Display remainder of HUD when engine is on and vehicle is not a bicycle + local vehicleClass = GetVehicleClass(vehicle) + if pedInVeh and GetIsVehicleEngineRunning(vehicle) and vehicleClass ~= 13 then + -- Save previous speed and get current speed + local prevSpeed = currSpeed + currSpeed = GetEntitySpeed(vehicle) + + -- Set PED flags + SetPedConfigFlag(PlayerPedId(), 32, true) + + -- Check if seatbelt button pressed, toggle state and handle seatbelt logic + if IsControlJustReleased(0, seatbeltInput) and (enableController or GetLastInputMethod(0)) and vehicleClass ~= 8 then + -- Toggle seatbelt status and play sound when enabled + seatbeltIsOn = not seatbeltIsOn + if seatbeltPlaySound then + PlaySoundFrontend(-1, "Faster_Click", "RESPAWN_ONLINE_SOUNDSET", 1) + end + end + if not seatbeltIsOn then + -- Eject PED when moving forward, vehicle was going over 45 MPH and acceleration over 100 G's + local vehIsMovingFwd = GetEntitySpeedVector(vehicle, true).y > 1.0 + local vehAcc = (prevSpeed - currSpeed) / GetFrameTime() + if vehIsMovingFwd and (prevSpeed > (seatbeltEjectSpeed / 2.237)) and (vehAcc > (seatbeltEjectAccel * 9.81)) then + SetEntityCoords(player, position.x, position.y, position.z - 0.47, true, true, true) + SetEntityVelocity(player, prevVelocity.x, prevVelocity.y, prevVelocity.z) + Wait(1) + SetPedToRagdoll(player, 1000, 1000, 0, 0, 0, 0) + else + -- Update previous velocity for ejecting player + prevVelocity = GetEntityVelocity(vehicle) + end + elseif seatbeltDisableExit then + -- Disable vehicle exit when seatbelt is on + DisableControlAction(0, 75) + end + + -- When player in driver seat, handle cruise control + if GetPedInVehicleSeat(vehicle, -1) == player then + -- Check if cruise control button pressed, toggle state and set maximum speed appropriately + if IsControlJustReleased(0, cruiseInput) and (enableController or GetLastInputMethod(0)) then + cruiseIsOn = not cruiseIsOn + cruiseSpeed = currSpeed + end + local maxSpeed = cruiseIsOn and cruiseSpeed or GetVehicleHandlingFloat(vehicle, "CHandlingData", "fInitialDriveMaxFlatVel") + SetEntityMaxSpeed(vehicle, maxSpeed) + else + -- Reset cruise control + cruiseIsOn = false + end + + -- Check what units should be used for speed + if ShouldUseMetricMeasurements() then + -- Get vehicle speed in KPH and draw speedometer + local speed = currSpeed * 3.6 + local speedColor = (speed >= speedLimit) and speedColorOver or speedColorUnder + drawTxt(("%.3d"):format(math.ceil(speed)), 2, speedColor, 0.8, screenPosX + 0.000, screenPosY + 0.000) + drawTxt("KPH", 2, speedColorText, 0.4, screenPosX + 0.030, screenPosY + 0.018) + else + -- Get vehicle speed in MPH and draw speedometer + local speed = currSpeed * 2.23694 + local speedColor = (speed >= speedLimit) and speedColorOver or speedColorUnder + drawTxt(("%.3d"):format(math.ceil(speed)), 2, speedColor, 0.8, screenPosX + 0.000, screenPosY + 0.000) + drawTxt("MPH", 2, speedColorText, 0.4, screenPosX + 0.030, screenPosY + 0.018) + end + + -- Draw fuel gauge + local fuelColor = (currentFuel >= fuelWarnLimit) and fuelColorOver or fuelColorUnder + drawTxt(("%.3d"):format(math.ceil(currentFuel)), 2, fuelColor, 0.8, screenPosX + 0.055, screenPosY + 0.000) + drawTxt("FUEL", 2, fuelColorText, 0.4, screenPosX + 0.085, screenPosY + 0.018) + + -- Draw cruise control status + local cruiseColor = cruiseIsOn and cruiseColorOn or cruiseColorOff + drawTxt("CRUISE", 2, cruiseColor, 0.4, screenPosX + 0.020, screenPosY + 0.048) + + -- Draw seatbelt status if not a motorcyle + if vehicleClass ~= 8 then + local seatbeltColor = seatbeltIsOn and seatbeltColorOn or seatbeltColorOff + drawTxt("SEATBELT", 2, seatbeltColor, 0.4, screenPosX + 0.080, screenPosY + 0.048) + end + end + end + end end) -- Secondary thread to update strings CreateThread(function() - while true do - -- Update when player is in a vehicle or on foot (if enabled) - if pedInVeh or locationAlwaysOn then - -- Get player, position and vehicle - local player = GetPlayerPed(-1) - local _ = GetEntityCoords(player) - - -- Update fuel when in a vehicle - if pedInVeh then - local vehicle = GetVehiclePedIsIn(player, false) - if fuelShowPercentage then - -- Display remaining fuel as a percentage - currentFuel = 100 - * GetVehicleFuelLevel(vehicle) - / GetVehicleHandlingFloat(vehicle, "CHandlingData", "fPetrolTankVolume") - else - -- Display remainign fuel in liters - currentFuel = GetVehicleFuelLevel(vehicle) - end - end - - -- Update every second - Wait(1000) - else - -- Wait until next frame - Wait(0) - end - end + while true do + -- Update when player is in a vehicle or on foot (if enabled) + if pedInVeh or locationAlwaysOn then + -- Get player, position and vehicle + local player = PlayerPedId() + local _ = GetEntityCoords(player) + + -- Update fuel when in a vehicle + if pedInVeh then + local vehicle = GetVehiclePedIsIn(player, false) + if fuelShowPercentage then + -- Display remaining fuel as a percentage + currentFuel = 100 * GetVehicleFuelLevel(vehicle) / GetVehicleHandlingFloat(vehicle, "CHandlingData", "fPetrolTankVolume") + else + -- Display remainign fuel in liters + currentFuel = GetVehicleFuelLevel(vehicle) + end + end + + -- Update every second + Wait(1000) + else + -- Wait until next frame + Wait(0) + end + end end) -- Helper function to draw text to screen function drawTxt(content, font, colour, scale, x, y) - SetTextFont(font) - SetTextScale(scale, scale) - SetTextColour(colour[1], colour[2], colour[3], 255) - SetTextEntry("STRING") - SetTextDropShadow(0, 0, 0, 0, 255) - SetTextDropShadow() - SetTextEdge(4, 0, 0, 0, 255) - SetTextOutline() - AddTextComponentString(content) - DrawText(x, y) + SetTextFont(font) + SetTextScale(scale, scale) + SetTextColour(colour[1], colour[2], colour[3], 255) + SetTextEntry("STRING") + SetTextDropShadow(0, 0, 0, 0, 255) + SetTextDropShadow() + SetTextEdge(4, 0, 0, 0, 255) + SetTextOutline() + AddTextComponentString(content) + DrawText(x, y) end diff --git a/server-data/resources/[bpt_addons]/bpt_hud/client/client.lua b/server-data/resources/[bpt_addons]/bpt_hud/client/client.lua index 9eca5adc2..afeede353 100644 --- a/server-data/resources/[bpt_addons]/bpt_hud/client/client.lua +++ b/server-data/resources/[bpt_addons]/bpt_hud/client/client.lua @@ -1,76 +1,76 @@ local minimap = RequestScaleformMovie("minimap") CreateThread(function() - while true do - Wait(1250) + while true do + Wait(1250) - if IsPauseMenuActive() then - SendNUIMessage({ mapfoil = true }) - SendNUIMessage({ mapoutline = false }) - else - SendNUIMessage({ mapfoil = false }) - SendNUIMessage({ mapoutline = true }) - end + if IsPauseMenuActive() then + SendNUIMessage({ mapfoil = true }) + SendNUIMessage({ mapoutline = false }) + else + SendNUIMessage({ mapfoil = false }) + SendNUIMessage({ mapoutline = true }) + end - SetRadarZoom(1150) + SetRadarZoom(1150) - if Config.Hidemapoutsidecar then - if Config.Hidemapwhenengineoff then - local player = PlayerPedId() - local vehicle = GetVehiclePedIsIn(player, false) - local vehicleIsOn = GetIsVehicleEngineRunning(vehicle) - if IsPedInAnyVehicle(player, false) and vehicleIsOn then - ToggleRadar(true) - SendNUIMessage({ mapoutline = true }) - TriggerVehicleLoop() - else - ToggleRadar(false) - SendNUIMessage({ mapoutline = false }) - end - else - local player = PlayerPedId() - if IsPedInAnyVehicle(player, false) then - ToggleRadar(true) - SendNUIMessage({ mapoutline = true }) - TriggerVehicleLoop() - else - ToggleRadar(false) - SendNUIMessage({ mapoutline = false }) - end - end - end - end + if Config.Hidemapoutsidecar then + if Config.Hidemapwhenengineoff then + local player = PlayerPedId() + local vehicle = GetVehiclePedIsIn(player, false) + local vehicleIsOn = GetIsVehicleEngineRunning(vehicle) + if IsPedInAnyVehicle(player, false) and vehicleIsOn then + ToggleRadar(true) + SendNUIMessage({ mapoutline = true }) + TriggerVehicleLoop() + else + ToggleRadar(false) + SendNUIMessage({ mapoutline = false }) + end + else + local player = PlayerPedId() + if IsPedInAnyVehicle(player, false) then + ToggleRadar(true) + SendNUIMessage({ mapoutline = true }) + TriggerVehicleLoop() + else + ToggleRadar(false) + SendNUIMessage({ mapoutline = false }) + end + end + end + end end) local x = -0.025 local y = -0.015 CreateThread(function() - RequestStreamedTextureDict("circlemap", false) - while not HasStreamedTextureDictLoaded("circlemap") do - Wait(100) - end + RequestStreamedTextureDict("circlemap", false) + while not HasStreamedTextureDictLoaded("circlemap") do + Wait(100) + end - AddReplaceTexture("platform:/textures/graphics", "radarmasksm", "circlemap", "radarmasksm") - SetMinimapClipType(1) - SetMinimapComponentPosition("minimap", "L", "B", -0.022, -0.026, 0.16, 0.245) - SetMinimapComponentPosition("minimap_mask", "L", "B", x + 0.21, y + 0.09, 0.071, 0.164) - SetMinimapComponentPosition("minimap_blur", "L", "B", -0.032, -0.04, 0.18, 0.22) - ThefeedSpsExtendWidescreenOn() - SetRadarBigmapEnabled(true, false) - SetRadarBigmapEnabled(false, false) + AddReplaceTexture("platform:/textures/graphics", "radarmasksm", "circlemap", "radarmasksm") + SetMinimapClipType(1) + SetMinimapComponentPosition("minimap", "L", "B", -0.022, -0.026, 0.16, 0.245) + SetMinimapComponentPosition("minimap_mask", "L", "B", x + 0.21, y + 0.09, 0.071, 0.164) + SetMinimapComponentPosition("minimap_blur", "L", "B", -0.032, -0.04, 0.18, 0.22) + ThefeedSpsExtendWidescreenOn() + SetRadarBigmapEnabled(true, false) + SetRadarBigmapEnabled(false, false) end) ToggleRadar = function(state) - DisplayRadar(state) - BeginScaleformMovieMethod(minimap, "SETUP_HEALTH_ARMOUR") - ScaleformMovieMethodAddParamInt(3) - EndScaleformMovieMethod() + DisplayRadar(state) + BeginScaleformMovieMethod(minimap, "SETUP_HEALTH_ARMOUR") + ScaleformMovieMethodAddParamInt(3) + EndScaleformMovieMethod() end TriggerVehicleLoop = function() - CreateThread(function() - ToggleRadar(true) - SetRadarBigmapEnabled(false, false) - end) + CreateThread(function() + ToggleRadar(true) + SetRadarBigmapEnabled(false, false) + end) end diff --git a/server-data/resources/[bpt_addons]/bpt_hud/client/status.lua b/server-data/resources/[bpt_addons]/bpt_hud/client/status.lua index fd2a624c5..666d7a0fe 100644 --- a/server-data/resources/[bpt_addons]/bpt_hud/client/status.lua +++ b/server-data/resources/[bpt_addons]/bpt_hud/client/status.lua @@ -7,29 +7,29 @@ local posi = "bottom" ESX = exports["es_extended"]:getSharedObject() AddEventHandler("playerSpawned", function() -- Enable hud only after player spawn - CreateThread(function() - while true do - Wait(0) - if IsEntityDead(GetPlayerPed(-1)) then - health = 0 - else - health = math.ceil(GetEntityHealth(GetPlayerPed(-1)) - 100) - end - armor = math.ceil(GetPedArmour(GetPlayerPed(-1))) - TriggerEvent("bpt_status:getStatus", "hunger", function(status) - food = status.getPercent() - end) - TriggerEvent("bpt_status:getStatus", "thirst", function(status) - thirst = status.getPercent() - end) - SendNUIMessage({ - posi = posi, - show = IsPauseMenuActive(), -- Disable hud if settings menu is active - health = health, - armor = armor, - food = food, - thirst = thirst, - }) - end - end) + CreateThread(function() + while true do + Wait(0) + if IsEntityDead(PlayerPedId()) then + health = 0 + else + health = math.ceil(GetEntityHealth(PlayerPedId()) - 100) + end + armor = math.ceil(GetPedArmour(PlayerPedId())) + TriggerEvent("bpt_status:getStatus", "hunger", function(status) + food = status.getPercent() + end) + TriggerEvent("bpt_status:getStatus", "thirst", function(status) + thirst = status.getPercent() + end) + SendNUIMessage({ + posi = posi, + show = IsPauseMenuActive(), -- Disable hud if settings menu is active + health = health, + armor = armor, + food = food, + thirst = thirst, + }) + end + end) end) diff --git a/server-data/resources/[bpt_addons]/bpt_hud/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_hud/fxmanifest.lua index 395202164..13839ba0d 100644 --- a/server-data/resources/[bpt_addons]/bpt_hud/fxmanifest.lua +++ b/server-data/resources/[bpt_addons]/bpt_hud/fxmanifest.lua @@ -3,20 +3,20 @@ fx_version("adamant") game("gta5") author("bitpredator") description("bitpredator HUD") -version("1.0.1") +version("1.0.2") ui_page("html/ui.html") shared_script("@es_extended/imports.lua") files({ - "html/*.css", - "html/*.js", - "html/*.png", - "html/ui.html", + "html/*.css", + "html/*.js", + "html/*.png", + "html/ui.html", }) client_scripts({ - "client/*.lua", - "config.lua", + "client/*.lua", + "config.lua", })