Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide UI Functions, Exports and In game Commands. #200

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 125 additions & 17 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,79 @@ local Menu = config.Menu
local CinematicHeight = 0.2
local w = 0
local radioActive = false
local isPauseMenuActive = false
local hudHidden = false



-- HUD VISIBILITY

local function shouldDisplayRadar()
if hudHidden then return false end
if isPauseMenuActive then return false end
if Menu.isHideMapChecked then return false end
if Menu.isCinematicModeChecked then return false end

local player = PlayerPedId()
local vehicle = GetVehiclePedIsIn(player, false)

if IsPedInAnyVehicle(player) and not IsThisModelABicycle(vehicle) then
return true
end

return Menu.isOutMapChecked
end

-- HUD Visibility Toggle Function
local function ToggleHudVisibility()
hudHidden = not hudHidden

if hudHidden then
SendNUIMessage({
action = 'hudtick',
show = false
})
SendNUIMessage({
action = 'car',
show = false
})
SendNUIMessage({
action = 'baseplate',
show = false
})
DisplayRadar(false)
else
if not isPauseMenuActive then
SendNUIMessage({
action = 'hudtick',
show = true
})
DisplayRadar(shouldDisplayRadar())
end
end
end

-- Export Functions
exports('ToggleHud', function()
ToggleHudVisibility()
end)

exports('SetHudState', function(state)
if hudHidden ~= not state then
ToggleHudVisibility()
end
DisplayRadar(shouldDisplayRadar())
end)

exports('IsHudHidden', function()
return hudHidden
end)

-- Event Handlers
RegisterNetEvent('qb-hud:client:ToggleHud', function()
ToggleHudVisibility()
end)


DisplayRadar(false)

Expand Down Expand Up @@ -349,7 +422,7 @@ end)
RegisterNUICallback('HideMap', function(_, cb)
Wait(50)
Menu.isHideMapChecked = not Menu.isHideMapChecked
DisplayRadar(not Menu.isHideMapChecked)
DisplayRadar(shouldDisplayRadar())
TriggerEvent('hud:client:playHudChecklistSound')
saveSettings()
cb('ok')
Expand Down Expand Up @@ -678,7 +751,7 @@ local function getFuelLevel(vehicle)
end

-- HUD Update loop

-- UPDATED TO RESPECT THE HUD HIDDEN STATE
CreateThread(function()
local wasInVehicle = false
while true do
Expand All @@ -687,38 +760,64 @@ CreateThread(function()
else
Wait(50)
end

if LocalPlayer.state.isLoggedIn then
local show = true
local show = not hudHidden
local player = PlayerPedId()
local playerId = PlayerId()

-- Check pause menu state
local currentPauseState = IsPauseMenuActive()
if currentPauseState ~= isPauseMenuActive then
isPauseMenuActive = currentPauseState
if isPauseMenuActive then
show = false
end
DisplayRadar(shouldDisplayRadar())
end

-- If pause menu is active, hide HUD elements
if isPauseMenuActive then
SendNUIMessage({
action = 'hudtick',
show = false
})
SendNUIMessage({
action = 'car',
show = false
})
Wait(100)
goto continue
end

local weapon = GetSelectedPedWeapon(player)
-- Player hud
if not config.WhitelistedWeaponArmed[weapon] then
if weapon ~= `WEAPON_UNARMED` then
armed = true
else
armed = false
end
end

playerDead = IsEntityDead(player) or PlayerData.metadata['inlaststand'] or PlayerData.metadata['isdead'] or false
parachute = GetPedParachuteState(player)

-- Stamina
if not IsEntityInWater(player) then
oxygen = 100 - GetPlayerSprintStaminaRemaining(playerId)
end

-- Oxygen
if IsEntityInWater(player) then
oxygen = GetPlayerUnderwaterTimeRemaining(playerId) * 10
end
-- Player hud

local talking = NetworkIsPlayerTalking(playerId)
local voice = 0
if LocalPlayer.state['proximity'] then
voice = LocalPlayer.state['proximity'].distance
end
if IsPauseMenuActive() then
show = false
end

local vehicle = GetVehiclePedIsIn(player)
if not (IsPedInAnyVehicle(player) and not IsThisModelABicycle(vehicle)) then
updatePlayerHud({
Expand Down Expand Up @@ -752,23 +851,27 @@ CreateThread(function()
-1,
Menu.isCinematicModeChecked,
dev,
radioActive,
radioActive
})
end
-- Vehicle hud

-- Vehicle HUD
if IsPedInAnyHeli(player) or IsPedInAnyPlane(player) then
showAltitude = true
showSeatbelt = false
end

if IsPedInAnyVehicle(player) and not IsThisModelABicycle(vehicle) then
if not wasInVehicle then
DisplayRadar(true)
wasInVehicle = true
DisplayRadar(shouldDisplayRadar())
end
wasInVehicle = true

local engineHealth = GetVehicleEngineHealth(vehicle)
if engineHealth ~= engineHealth then -- This checks for NaN, as any NaN value is not equal to itself
if engineHealth ~= engineHealth then
engineHealth = 0
end

updatePlayerHud({
show,
Menu.isDynamicHealthChecked,
Expand Down Expand Up @@ -800,20 +903,22 @@ CreateThread(function()
(engineHealth / 10),
Menu.isCinematicModeChecked,
dev,
radioActive,
radioActive
})

updateVehicleHud({
show,
IsPauseMenuActive(),
isPauseMenuActive,
seatbeltOn,
math.ceil(GetEntitySpeed(vehicle) * speedMultiplier),
getFuelLevel(vehicle),
math.ceil(GetEntityCoords(player).z * 0.5),
showAltitude,
showSeatbelt,
showSquareB,
showCircleB,
showCircleB
})

showAltitude = false
showSeatbelt = true
else
Expand All @@ -829,13 +934,16 @@ CreateThread(function()
cruiseOn = false
harness = false
end
DisplayRadar(Menu.isOutMapChecked)
DisplayRadar(shouldDisplayRadar())
end

::continue::
else
SendNUIMessage({
action = 'hudtick',
show = false
})
DisplayRadar(false)
end
end
end)
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ game 'gta5'
lua54 'yes'
author 'Kakarot'
description 'Heads-up display letting players track their hunger, thirst, stress, and more'
version '2.2.0'
version '2.2.1'

shared_scripts {
'@qb-core/shared/locale.lua',
Expand Down
26 changes: 26 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local QBCore = exports['qb-core']:GetCoreObject()
local ResetStress = false
local hiddenStates = {} -- Added Variable to track hud toggle state (On/Off)

QBCore.Commands.Add('cash', 'Check Cash Balance', {}, false, function(source, _)
local Player = QBCore.Functions.GetPlayer(source)
Expand Down Expand Up @@ -68,3 +69,28 @@ end)
QBCore.Functions.CreateCallback('hud:server:getMenu', function(_, cb)
cb(Config.Menu)
end)

local function ToggleHudForPlayer(source, shouldHide)
TriggerClientEvent('qb-hud:client:ToggleHud', source, shouldHide)
end

exports('ToggleHudForPlayer', ToggleHudForPlayer)


QBCore.Commands.Add('togglehud', 'Toggle HUD visibility', {}, false, function(source)
hiddenStates[source] = not hiddenStates[source]
if hiddenStates[source] then
TriggerClientEvent('QBCore:Notify', source, 'HUD Hidden', 'error')
else
TriggerClientEvent('QBCore:Notify', source, 'HUD Visible', 'success')
end

-- Trigger the client event to actually toggle the HUD
TriggerClientEvent('qb-hud:client:ToggleHud', source)
end)

-- Add player cleanup when they disconnect
AddEventHandler('playerDropped', function()
local source = source
hiddenStates[source] = nil
end)