Atualização do HUD no VRP
Atualização do HUD no VRP
------------------------------------------------------
-- VRP
-----------------------------------------------------------------------------------
------------------------------------------------------
local Tunnel = module("vrp","lib/Tunnel")
local Proxy = module("vrp","lib/Proxy")
vRP = [Link]("vRP")
-----------------------------------------------------------------------------------
------------------------------------------------------
-- CONNECTION
-----------------------------------------------------------------------------------
------------------------------------------------------
local Srr = {}
[Link]("hud", Srr)
vSERVER = [Link]("hud")
-----------------------------------------------------------------------------------
------------------------------------------------------
-- VARIABLES
-----------------------------------------------------------------------------------
------------------------------------------------------
local
health,armour,hunger,thirst,stamine,frequency,voiceLevel,voiceActive,gems,passport,
NitroFuel = 100,100,100,100,100,0,0,0,0,0,0
local hudVisibility,pausemenu,weaponVisibility,NitroFlame,PurgeActive =
true,false,false,false,false
local LightTrails,LightParticles,PurgeSprays,PurgeParticles = {},{},{},{}
local hungerTimer,thirstTimer = GetGameTimer(),GetGameTimer()
local stress = 0
local lastUpdateTime = GetGameTimer()
local loggedStreets = {}
-- Log para ruas sem tradução (apenas uma vez por rua para evitar spam)
if not loggedStreets[street] then
print("[HUD] Tradução não encontrada para: \"" .. street .. "\"")
loggedStreets[street] = true
end
-----------------------------------------------------------------------------------
------------------------------------------------------
-- VISIBILITY
-----------------------------------------------------------------------------------
------------------------------------------------------
RegisterNetEvent("hud:Active")
AddEventHandler("hud:Active",function(status)
hudVisibility = status
SendNUIMessage({ action = "setVisibility", data = status })
-----------------------------------------------------------------------------------
------------------------------------------------------
-- NOTIFY
-----------------------------------------------------------------------------------
------------------------------------------------------
local title = {
["fome"] = "Fome",
["sede"] = "Sede",
["amarelo"] = "Aviso",
["azul"] = "Notificação",
["vermelho"] = "Negado",
["verde"] = "Sucesso",
}
RegisterNetEvent("Notify")
AddEventHandler("Notify",function(type,message,time)
if not time then time = 5000 end
SendNUIMessage({ action = "addNotify", data = { theme = type, title =
title[type] or "Notificação", message = message, delay = time } })
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- PROGRESS
-----------------------------------------------------------------------------------
------------------------------------------------------
RegisterNetEvent("Progress")
AddEventHandler("Progress",function(message,delay)
if not delay or not message then return end
SendNUIMessage({action = "addProgress",data = { title = "Progresso", message =
message, delay = delay }})
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- ALERTS
-----------------------------------------------------------------------------------
------------------------------------------------------
RegisterNetEvent("Alerts")
AddEventHandler("Alerts",function(data)
SendNUIMessage({ action = "addAlert", data = { icon = [Link], color =
[Link], time = [Link], title = [Link], author = [Link], message =
[Link], delay = [Link] }})
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- HEALTH
-----------------------------------------------------------------------------------
------------------------------------------------------
AddEventHandler('gameEventTriggered', function (name, args)
if name == "CEventNetworkEntityDamage" then
if PlayerPedId() ~= args[1] then return end
-- Atualizar vida mesmo quando HUD estiver invisível
local newHealth = GetEntityHealth(args[1]) - 100
-- Calcular vida como porcentagem de 200 (vida máxima)
local healthPercentage = [Link]((newHealth / 100) * 100)
if healthPercentage > 100 then healthPercentage = 100 end
if healthPercentage < 0 then healthPercentage = 0 end
health = healthPercentage
SendNUIMessage({action = "setStats", data = { health = health }})
end
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- THREAD
-----------------------------------------------------------------------------------
------------------------------------------------------
CreateThread(function()
LoadPtfxAsset("veh_xs_vehicle_mods")
DisplayRadar(false)
RequestStreamedTextureDict("circlemap", false)
while not HasStreamedTextureDictLoaded("circlemap") do
Wait(500)
end
AddReplaceTexture("platform:/textures/graphics", "radarmasksm", "circlemap",
"radarmasksm")
SetNuiFocus(false)
while true do
-- Atualizações de vida/colete/stamina SEM depender da visibilidade
local ped = PlayerPedId()
local newHealthVal = GetEntityHealth(ped) - 100
local newArmour = GetPedArmour(ped)
local newStamine = GetPlayerStamina(PlayerId())
SetTimeout(500,function()
DoScreenFadeIn(0)
end)
ApplyDamageToPed(ped,[Link](2),false)
TriggerEvent("Notify","fome","Sofrendo com a
fome.",2500)
end
end
end
Wait(250) -- Intervalo ajustado para bom equilíbrio entre performance e
responsividade
end
end)
RegisterNetEvent("hud:Weapon")
AddEventHandler("hud:Weapon",function(Status,Hash)
weaponVisibility = Status
if not Status then
SendNUIMessage({ action = "setWeapon", data = false })
return
end
CreateThread(function()
while weaponVisibility do
local ped = PlayerPedId()
if IsPedArmed(ped,6) then
local weapon = GetSelectedPedWeapon(ped)
local __, ammoClip = GetAmmoInClip(ped, weapon)
local maxAmmo = GetAmmoInPedWeapon(ped, weapon)
local Ammo = maxAmmo - ammoClip
if Config["Weapon"][weapon] then
SendNUIMessage({ action = "setWeapon", data = { image
= Config["Weapon"][weapon].image or "", name = Config["Weapon"][weapon].name or
"", ammo = ammoClip.."/"..Ammo }})
else
SendNUIMessage({ action = "setWeapon", data = { image
= "Arma Indefinida", name = "", ammo = ammoClip.."/"..Ammo }})
end
else
if weaponVisibility then
SendNUIMessage({ action = "setWeapon", data = false })
weaponVisibility = false
end
end
Wait(100)
end
end)
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- VEHICLE
-----------------------------------------------------------------------------------
------------------------------------------------------
local seatbeltSpeed = 0
local seatbeltLock = false
local seatbeltVelocity = vec3(0,0,0)
if GetVehicleDoorLockStatus(vehicle) == 2 or seatbeltLock
then
DisableControlAction(1,75,true)
end
TriggerServerEvent("hud:VehicleEject",seatbeltVelocity)
Wait(500)
SetEntityNoCollisionEntity(ped,vehicle,true)
SetEntityNoCollisionEntity(vehicle,ped,true)
end
seatbeltVelocity = GetEntityVelocity(vehicle)
seatbeltSpeed = speed
end
end
if seatbeltSpeed ~= 0 then
seatbeltSpeed = 0
end
if seatbeltLock then
seatbeltLock = false
end
if NitroFlame then
NitroDisable()
end
end
end)
RegisterCommand("Beltz",function(source)
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
if not IsPedOnAnyBike(ped) and not IsPedInAnyHeli(ped) and not
IsPedInAnyPlane(ped) then
if seatbeltLock then
TriggerEvent("sounds:Private","unbelt",0.5)
seatbeltLock = false
SendNUIMessage({ action = "setVehicleData", data =
{seatbelt = seatbeltLock}})
else
TriggerEvent("sounds:Private","belt",0.5)
seatbeltLock = true
SendNUIMessage({ action = "setVehicleData", data =
{seatbelt = seatbeltLock}})
end
end
end
end)
RegisterKeyMapping("Beltz","Colocar/Retirar o cinto.","keyboard","G")
-----------------------------------------------------------------------------------
------------------------------------------------------
-- UPDATEINFOS
-----------------------------------------------------------------------------------
------------------------------------------------------
AddStateBagChangeHandler("Weather", nil, function(_, __, value)
weather = value
end)
RegisterNetEvent("cda_hud:updateKm")
AddEventHandler("cda_hud:updateKm",function(km)
SendNUIMessage({ action = "setVehicleData", data = { mileage = km }})
end)
RegisterNetEvent("hud:Voice")
AddEventHandler("hud:Voice",function(status)
voiceActive = status
SendNUIMessage({action = "setInfos", data = { voiceActive = voiceActive }})
end)
RegisterNetEvent("hud:Voip")
AddEventHandler("hud:Voip",function(mode)
voiceLevel = mode
SendNUIMessage({action = "setInfos", data = { voiceLevel = voiceLevel }})
end)
RegisterNetEvent("hud:Radio")
AddEventHandler("hud:Radio",function(number)
frequency = number
SendNUIMessage({action = "setInfos", data = { frequency = frequency }})
end)
RegisterNetEvent("hud:Passport")
AddEventHandler("hud:Passport",function(id)
passport = id
SendNUIMessage({action = "setInfos", data = { userId = passport }})
SendNUIMessage({action = "setInfos", data = { voiceLevel = 2 }})
end)
RegisterNetEvent("hud:AddGems")
AddEventHandler("hud:AddGems",function(amount)
gems = amount + gems
SendNUIMessage({action = "setInfos", data = { gems = gems }})
end)
RegisterNetEvent("hud:RemoveGems")
AddEventHandler("hud:RemoveGems",function(amount)
gems = gems - amount
SendNUIMessage({action = "setInfos", data = { gems = gems }})
end)
RegisterNetEvent("hud:Thirst")
AddEventHandler("hud:Thirst",function(number)
thirst = number
SendNUIMessage({action = "setStats", data = { thirst = thirst }})
end)
RegisterNetEvent("hud:Hunger")
AddEventHandler("hud:Hunger",function(number)
hunger = number
SendNUIMessage({action = "setStats", data = { hunger = hunger }})
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- EXPORTS
-----------------------------------------------------------------------------------
------------------------------------------------------
exports("Wanted",function()
return false
end)
exports("Reposed",function()
return false
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- TIME
-----------------------------------------------------------------------------------
------------------------------------------------------
[Link](function()
while true do
SetWeatherTypeNow(weather)
SetWeatherTypePersist(weather)
SetWeatherTypeNowPersist(weather)
NetworkOverrideClockTime(hours, minutes, 00)
[Link](1000)
end
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- REQUEST
-----------------------------------------------------------------------------------
------------------------------------------------------
local activeRequest = false
local resultRequest = false
local timeRequest = GetGameTimer()
local idRequest = 0
function [Link](Message)
if activeRequest then
return false
end
idRequest = idRequest + 1
SendNUIMessage({ action = "addRequest", data = { id = idRequest, title =
"Pergunta", description = Message, author = "Sistema", delay = 15000 } })
timeRequest = GetGameTimer() + 15000
activeRequest = true
while activeRequest do
if GetGameTimer() >= timeRequest then
SendNUIMessage({ action = "remRequest", data = idRequest })
resultRequest = false
activeRequest = false
end
Wait(0)
end
return resultRequest
end
RegisterCommand("cda:acceptRequest",function()
if activeRequest then
resultRequest = true
activeRequest = false
SendNUIMessage({ action = "remRequest", data = idRequest })
end
end)
RegisterCommand("cda:declineRequest",function()
if activeRequest then
resultRequest = false
activeRequest = false
SendNUIMessage({ action = "remRequest", data = idRequest })
end
end)
RegisterKeyMapping("cda:acceptRequest","Aceitar requisições.","keyboard","Y")
RegisterKeyMapping("cda:declineRequest","Rejeitar requisições.","keyboard","U")
-----------------------------------------------------------------------------------
------------------------------------------------------
-- PROMPT
-----------------------------------------------------------------------------------
------------------------------------------------------
local promptStatus = ""
local promptActive = false
function [Link](Text,DefaultText)
if not DefaultText then DefaultText = "" end
if promptActive then
return false
end
promptStatus = ""
promptActive = true
SendNUIMessage({ action = "showPrompt", data = { title = Text, defaultValue =
DefaultText } })
SetNuiFocus(true,true)
RegisterNUICallback("removeFocus",function(Data,Callback)
if promptActive then
promptStatus = false
promptActive = false
SetNuiFocus(false,false)
end
-- if chatStatus then
-- TriggerEvent("cda:ChatVisible",false)
-- end
end)
RegisterNUICallback("submitPrompt",function(Data,Callback)
promptActive = false
promptStatus = [Link]
SetNuiFocus(false,false)
end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- SHORTCUTS
-----------------------------------------------------------------------------------
------------------------------------------------------
function ShowShortcuts()
local Shortcuts = [Link]()
SendNUIMessage({ action = "setHotbar", data = Shortcuts })
end
function HideShortcuts()
SendNUIMessage({ action = "setHotbar", data = false })
end
RegisterCommand("+shortcuts",ShowShortcuts)
RegisterCommand("-shortcuts",HideShortcuts)
RegisterKeyMapping("+shortcuts","Visualizar atalhos.","keyboard","TAB")
-----------------------------------------------------------------------------------
------------------------------------------------------
-- NOTIFYPUSH
-----------------------------------------------------------------------------------
------------------------------------------------------
-- RegisterNetEvent("NotifyPush")
-- AddEventHandler("NotifyPush",function(Data)
-- local streetName =
GetStreetNameFromHashKey(GetStreetNameAtCoord(Data["x"],Data["y"],Data["z"]))
-- if parseInt(Data["code"]) == 13 then
-- TriggerEvent("sounds:Private","deathcop",0.5)
-- end
-- SetBlipSprite(Blip,270)
-- SetBlipDisplay(Blip,4)
-- SetBlipAsShortRange(Blip,true)
-- SetBlipColour(Blip,Data["blipColor"])
-- SetBlipScale(Blip,0.9)
-- BeginTextCommandSetBlipName("STRING")
-- AddTextComponentString(Data["title"])
-- EndTextCommandSetBlipName(Blip)
-- SetTimeout(60000,function()
-- if DoesBlipExist(Blip) then
-- RemoveBlip(Blip)
-- end
-- end)
-- end)
-- RegisterNUICallback("NotifyPush:pingGps",function(Data,Callback)
-- SetNewWaypoint(Data["x"] + 0.0001,Data["y"] + 0.0001)
-- end)
-- RegisterNUICallback("NotifyPush:call",function(Data,Callback)
-- exports["smartphone"]:callPlayer(Data["phone"])
-- end)
-- RegisterCommand("NotifyCall",function()
-- if not LocalPlayer["state"]["Commands"] and not LocalPlayer["state"]
["Handcuff"] and not IsPauseMenuActive() then
-- SendNUIMessage({ action = "NotifyPush:history", data = true })
-- end
-- end)
-- RegisterKeyMapping("NotifyCall","Consultar as notificações.","keyboard","F2")
-----------------------------------------------------------------------------------
------------------------------------------------------
-- CHAT
-----------------------------------------------------------------------------------
------------------------------------------------------
-- local chatStatus = false
-- RegisterCommand("cda:chat", function()
-- TriggerEvent("cda:ChatVisible",true)
-- SetNuiFocus(true, true)
-- end)
RegisterNUICallback("getChatChannels",function(data,cb)
cb({})
end)
-- RegisterNUICallback("submitCommand",function(data,cb)
-- if not data then return end
-- local command = [Link][1]
-- ExecuteCommand(command:sub(2))
-- chatStatus = false
-- SetNuiFocus(chatStatus, chatStatus)
-- cb(true)
-- end)
-- RegisterNUICallback("submitChatMessage",function(data,cb)
-- if not data then return end
-- TriggerServerEvent("cda_hud:serverMessage",[Link],[Link])
-- chatStatus = false
-- SetNuiFocus(chatStatus, chatStatus)
-- cb(true)
-- end)
-- RegisterNetEvent("cda_hud:clientMessage")
-- AddEventHandler("cda_hud:clientMessage",function(text,author)
-- SendNUIMessage( {
-- action = "Chat:addMessage",
-- data = {
-- label = author,
-- author = "",
-- color = "#ff5050",
-- time = {hours, minutes},
-- content = text,
-- },
-- })
-- Wait(500)
-- SendNUIMessage({ action = "Chat:showMessages", data = true })
-- SetTimeout(4000, function()
-- SendNUIMessage({ action = "Chat:showMessages", data = false })
-- end)
-- end)
-----------------------------------------------------------------------------------
------------------------------------------------------
-- NITRO
-----------------------------------------------------------------------------------
------------------------------------------------------
function NitroEnable()
if GetGameTimer() >= NitroButton and not IsPauseMenuActive() then
local ped = PlayerPedId()
if IsPedInAnyVehicle(ped) then
NitroButton = GetGameTimer() + 1000
while LocalPlayer["state"]["Nitro"]
do
if NitroFuel >= 1 then
NitroFuel = NitroFuel -
1
SetVehicleRocketBoostActive(Vehicle,true)
SetVehicleNitroEnabled(Vehicle,true)
SetVehicleBoostActive(Vehicle,true)
ModifyVehicleTopSpeed(Vehicle,50.0)
SetLightTrail(Vehicle,true)
NitroFlame = Plate
end
else
if NitroFlame then
SetVehicleRocketBoostActive(Vehicle,false)
Entity(Vehicle).state:set('Nitro', NitroFuel)
SetVehicleNitroEnabled(Vehicle,false)
SetVehicleBoostActive(Vehicle,false)
ModifyVehicleTopSpeed(Vehicle,0.0)
SetLightTrail(Vehicle,false)
NitroFlame = false
LocalPlayer["state"]["Nitro"] = false
end
end
Wait(1)
end
else
SetPurgeSprays(Vehicle,true)
PurgeActive = true
end
else
SetPurgeSprays(Vehicle,true)
PurgeActive = true
end
end
end
end
end
end
end
function NitroDisable()
local Vehicle = GetLastDrivenVehicle()
if NitroFlame then
SetVehicleRocketBoostActive(Vehicle,false)
Entity(Vehicle).state:set('Nitro', NitroFuel)
SetVehicleNitroEnabled(Vehicle,false)
SetVehicleBoostActive(Vehicle,false)
ModifyVehicleTopSpeed(Vehicle,0.0)
SetLightTrail(Vehicle,false)
NitroFlame = false
LocalPlayer["state"]["Nitro"] = false
end
if PurgeActive then
SetPurgeSprays(Vehicle,false)
PurgeActive = false
end
end
RegisterCommand("+activeNitro",NitroEnable)
RegisterCommand("-activeNitro",NitroDisable)
RegisterKeyMapping("+activeNitro","Ativação do nitro.","keyboard","LMENU")
function SetLightTrail(Vehicle,Enable)
if LightTrails[Vehicle] == Enable then
return
end
if Enable then
local Particles = {}
local LeftTrail =
CreateLightTrail(Vehicle,GetEntityBoneIndexByName(Vehicle,"taillight_l"))
local RightTrail =
CreateLightTrail(Vehicle,GetEntityBoneIndexByName(Vehicle,"taillight_r"))
Particles[#Particles + 1] = LeftTrail
Particles[#Particles + 1] = RightTrail
LightTrails[Vehicle] = true
LightParticles[Vehicle] = Particles
else
if LightParticles[Vehicle] and #LightParticles[Vehicle] > 0 then
for _,v in ipairs(LightParticles[Vehicle]) do
StopLightTrail(v)
end
end
LightTrails[Vehicle] = nil
LightParticles[Vehicle] = nil
end
end
function CreateLightTrail(Vehicle,Bone)
UseParticleFxAssetNextCall("core")
local Particle =
StartParticleFxLoopedOnEntityBone("veh_light_red_trail",Vehicle,0.0,0.0,0.0,0.0,0.0
,0.0,Bone,1.0,false,false,false)
SetParticleFxLoopedEvolution(Particle,"speed",1.0,false)
return Particle
end
function StopLightTrail(Particle)
CreateThread(function()
local endTime = GetGameTimer() + 500
while GetGameTimer() < endTime do
Wait(0)
local now = GetGameTimer()
local Scale = (endTime - now) / 500
SetParticleFxLoopedScale(Particle,Scale)
SetParticleFxLoopedAlpha(Particle,Scale)
end
StopParticleFxLooped(Particle)
end)
end
function SetPurgeSprays(Vehicle,Enable)
if PurgeSprays[Vehicle] == Enable then
return
end
if Enable then
local Particles = {}
local Bone = GetEntityBoneIndexByName(Vehicle,"bonnet")
local Position = GetWorldPositionOfEntityBone(Vehicle,Bone)
local Offset =
GetOffsetFromEntityGivenWorldCoords(Vehicle,Position["x"],Position["y"],Position["z
"])
for i = 0,3 do
local LeftPurge = CreatePurgeSprays(Vehicle,Offset["x"] -
0.5,Offset["y"] + 0.05,Offset["z"],40.0,-20.0,0.0,0.5)
local RightPurge = CreatePurgeSprays(Vehicle,Offset["x"] +
0.5,Offset["y"] + 0.05,Offset["z"],40.0,20.0,0.0,0.5)
Particles[#Particles + 1] = LeftPurge
Particles[#Particles + 1] = RightPurge
end
PurgeSprays[Vehicle] = true
PurgeParticles[Vehicle] = Particles
else
if PurgeParticles[Vehicle] then
RemoveParticleFxFromEntity(Vehicle)
end
PurgeSprays[Vehicle] = nil
PurgeParticles[Vehicle] = nil
end
end
function CreatePurgeSprays(Vehicle,xOffset,yOffset,zOffset,xRot,yRot)
UseParticleFxAssetNextCall("core")
return
StartNetworkedParticleFxNonLoopedOnEntity("ent_sht_steam",Vehicle,xOffset,yOffset,z
Offset,xRot,yRot,0.0,0.5,false,false,false)
end
-----------------------------------------------------------------------------------
------------------------------------------------------
-- COMMANDS
-----------------------------------------------------------------------------------
------------------------------------------------------
RegisterCommand("hud",function()
TriggerEvent("hud:Active",not hudVisibility)
end)
Wait(200)
end
end)