Skip to content

Commit

Permalink
tweak(client): use state bags for playerloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
renzuzu committed Oct 30, 2021
1 parent d4367f9 commit 6fd64c9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 44 deletions.
59 changes: 36 additions & 23 deletions renzu_hud/client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ESX = nil
local getdata = false
CreateThread(function()
LocalPlayer.state:set('playerloaded', false,true)
if config.framework == 'ESX' then
while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Wait(0) end
while ESX.GetPlayerData().job == nil do Wait(0) end
Expand Down Expand Up @@ -38,7 +39,7 @@ CreateThread(function()
DecorRegister("INERTIA", 1);DecorRegister("DRIVEFORCE", 1);DecorRegister("TOPSPEED", 1);DecorRegister("STEERINGLOCK", 1);DecorRegister("MAXGEAR", 1);DecorRegister("TRACTION", 1);DecorRegister("TRACTION2", 1);DecorRegister("TRACTION3", 1);DecorRegister("TRACTION4", 1);DecorRegister("TRACTION5", 1)
if not DecorIsRegisteredAsType("MANUAL", 1) then DecorRegister("MANUAL", 1) end
DecorRegister("PLAYERLOADED", 1);DecorRegister("CHARSLOT", 1)
while not Hud.playerloaded do Wait(1000) end
while not LocalPlayer.state.playerloaded do Wait(1000) end
while not Hud.receive do Wait(1000) end
for type,val in pairs(config.buto) do if Hud.bodystatus then Hud.bonecategory[type] = Hud.bodystatus[type] else Hud.bonecategory[type] = 0.0 or 0.0 end if not other then Hud.parts[type] = {} for bone,val in pairs(val) do Hud.parts[type][bone] = 0.0 end end end
SendNUIMessage({type = "setUpdateBodyStatus",content = Hud.bonecategory})
Expand Down Expand Up @@ -160,7 +161,7 @@ end)
RegisterNetEvent('renzu_hud:charslot')
AddEventHandler('renzu_hud:charslot', function(charid)
Hud.charslot = charid
while not Hud.playerloaded do
while not LocalPlayer.state.playerloaded do
Wait(100)
end
Wait(2000)
Expand All @@ -174,7 +175,9 @@ CreateThread(function()
-- loaded events
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
Hud.playerloaded = true
Wait(1000)
LocalPlayer.state:set('playerloaded', true,true)
LocalPlayer.state.playerloaded = true
Wait(2000)
print("ESX")
Hud.lastped = PlayerPedId()
Expand All @@ -190,7 +193,9 @@ CreateThread(function()

RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
Hud.playerloaded = true
Wait(1000)
LocalPlayer.state:set('playerloaded', true,true)
LocalPlayer.state.playerloaded = true
Wait(2000)
print("QB")
Hud.lastped = PlayerPedId()
Expand All @@ -207,7 +212,9 @@ CreateThread(function()
RegisterNetEvent('playerSpawned')
AddEventHandler('playerSpawned', function(spawn)
if config.framework ~= 'ESX' and config.framework ~= 'QBCORE' then
Hud.playerloaded = true
Wait(1000)
LocalPlayer.state:set('playerloaded', true,true)
LocalPlayer.state.playerloaded = true
print("PLAYERLOADED")
Wait(2000)
Hud.lastped = PlayerPedId()
Expand All @@ -234,7 +241,7 @@ CreateThread(function()
TriggerServerEvent("renzu_hud:getdata",Hud.charslot)
getdata = true
end
Hud.playerloaded = true
LocalPlayer.state.playerloaded = true
SendNUIMessage({content = true, type = 'playerloaded'})
end
Wait(500)
Expand All @@ -245,12 +252,12 @@ CreateThread(function()
getdata = true
end
DecorSetBool(PlayerPedId(), "PLAYERLOADED", true)
Hud.playerloaded = true
LocalPlayer.state.playerloaded = true
SendNUIMessage({content = true, type = 'pedface'})
SendNUIMessage({content = true, type = 'playerloaded'})
elseif Hud:isplayer() and config.forceplayerload then
Wait(10000)
Hud.playerloaded = true
LocalPlayer.state.playerloaded = true
print("isplayer f")
Wait(2000)
Hud.lastped = PlayerPedId()
Expand All @@ -269,15 +276,15 @@ CreateThread(function()
getdata = true
end
DecorSetBool(PlayerPedId(), "PLAYERLOADED", true)
Hud.playerloaded = true
LocalPlayer.state.playerloaded = true
SendNUIMessage({content = true, type = 'pedface'})
SendNUIMessage({content = true, type = 'playerloaded'})
end
while not Hud.playerloaded do
while not LocalPlayer.state.playerloaded do
Wait(1000)
end

while Hud.playerloaded do -- dev purpose when restarting script, either you uncomment this or Hud.left it , it doesnt matter.
while LocalPlayer.state.playerloaded do -- dev purpose when restarting script, either you uncomment this or Hud.left it , it doesnt matter.
Wait(20000)
if not DecorExistOn(PlayerPedId(), "PLAYERLOADED") then
DecorRemove(Hud.lastped,"PLAYERLOADED")
Expand All @@ -294,7 +301,7 @@ end)

--- NEW HUD FUNC
RegisterNUICallback('requestface', function(data, cb)
while not Hud.playerloaded do
while not LocalPlayer.state.playerloaded do
Wait(1000)
end
Wait(5000)
Expand All @@ -311,6 +318,7 @@ RegisterNUICallback('requestface', function(data, cb)
end)

CreateThread(function()
while not LocalPlayer.state.playerloaded do Wait(100) end
Wait(1000)
for k,v in pairs(config.statusordering) do
if v.enable then
Expand Down Expand Up @@ -406,6 +414,7 @@ CreateThread(function()
end)

CreateThread(function()
while not LocalPlayer.state.playerloaded do Wait(100) end
Wait(2000)
SetPlayerUnderwaterTimeRemaining(Hud.pid,9999)
SetPedMaxTimeUnderwater(Hud.ped,99999)
Expand Down Expand Up @@ -481,7 +490,7 @@ CreateThread(function()
end)
end
if config.enablestatus or not config.enablestatus and config.statusui == 'normal' then
while not Hud.playerloaded do Wait(100) end
while not LocalPlayer.state.playerloaded do Wait(100) end
Hud:updateplayer(true)
end
end)
Expand Down Expand Up @@ -516,6 +525,7 @@ RegisterNUICallback('getoutvehicle', function(data, cb)
end)

CreateThread(function()
while not LocalPlayer.state.playerloaded do Wait(100) end
local enable_status = config.enablestatus
local ordering = config.statusordering
local placing = config.statusplace
Expand All @@ -533,12 +543,12 @@ CreateThread(function()
SendNUIMessage({type = "setStatusType",content = status_type})
Wait(500)
print(placing,ordering)
SendNUIMessage({type = "SetStatusOrder",content = {['table'] = ordering, ['float'] = placing}})
SendNUIMessage({type = "SetStatusOrder",content = {['data'] = ordering, ['float'] = placing}})
Wait(1000)
Hud.reorder = true
while not Hud.playerloaded do Citizen.Wait(100) print("loading") end
while not LocalPlayer.state.playerloaded do Citizen.Wait(100) print("loading") end
Wait(100)
local tbl = {['table'] = ordering, ['float'] = placing}
local tbl = {['data'] = ordering, ['float'] = placing}
if config.enable_carui then
SendNUIMessage({type = 'setCarui', content = config.carui})
end
Expand Down Expand Up @@ -933,7 +943,7 @@ end)
--ETC
CreateThread(function()
local count = 0
while not Hud.playerloaded or count < 5 do -- REAL WAY TO REMOVE HEALTHBAR AND ARMOR WITHOUT USING THE LOOP ( LOAP minimap.gfx first ) then on spawn load the circlemap
while not LocalPlayer.state.playerloaded or count < 5 do -- REAL WAY TO REMOVE HEALTHBAR AND ARMOR WITHOUT USING THE LOOP ( LOAP minimap.gfx first ) then on spawn load the circlemap
count = count + 1
Wait(1000)
end
Expand Down Expand Up @@ -1110,6 +1120,7 @@ CreateThread(function()
end)

CreateThread(function()
while not LocalPlayer.state.playerloaded do Wait(100) end
Wait(1000)
local enable_w = false
if config.enablestatus then
Expand Down Expand Up @@ -1147,7 +1158,7 @@ RegisterNetEvent('renzu_hud:bodystatus')
AddEventHandler('renzu_hud:bodystatus', function(status,other)
checkingpatient = other
local status = status
while not Hud.playerloaded do Wait(100) end
while not LocalPlayer.state.playerloaded do Wait(100) end
SendNUIMessage({type = "setBodyParts",content = config.healtype})
local status = status
Hud.receive = true
Expand Down Expand Up @@ -1198,14 +1209,14 @@ AddEventHandler('renzu_hud:bodystatus', function(status,other)
end)

CreateThread(function()
while not Hud.playerloaded do
while not LocalPlayer.state.playerloaded do
Wait(100)
end
if config.bodystatus then
Citizen.Wait(1000)
while DecorGetBool(PlayerPedId(), "PLAYERLOADED") ~= 1 do
Citizen.Wait(500)
if Hud.playerloaded then
if LocalPlayer.state.playerloaded then
DecorSetBool(PlayerPedId(), "PLAYERLOADED", true)
break
end
Expand Down Expand Up @@ -1544,6 +1555,7 @@ end)
temp_advstat = {}
CreateThread(function()
Wait(1000)
while not LocalPlayer.state.playerloaded do Wait(100) end
if config.wheelstancer then
while Hud.veh_stats == nil do
Wait(100)
Expand Down Expand Up @@ -2104,7 +2116,7 @@ RegisterNUICallback('hidecarlock', function(data, cb)
})
Hud.keyless = true
SendNUIMessage({
type = "settingui",
type = "SettingHud",
content = {config = config.userconfig, bool = false}
})
settingbool = false
Expand Down Expand Up @@ -2178,13 +2190,14 @@ end)

--clothes
CreateThread(function()
while not LocalPlayer.state.playerloaded do Wait(100) end
Wait(500)
--print("CLOTHING")
if config.clothing then
while DecorGetBool(PlayerPedId(), "PLAYERLOADED") ~= 1 do
Citizen.Wait(100)
--print(DecorGetBool(PlayerPedId(), "PLAYERLOADED"))
if Hud.playerloaded then
if LocalPlayer.state.playerloaded then
DecorSetBool(PlayerPedId(), "PLAYERLOADED", true)
break
end
Expand Down Expand Up @@ -2505,7 +2518,7 @@ end)
RegisterCommand(config.settingcommand, function(source, args, raw)
settingbool = not settingbool
SendNUIMessage({
type = "settingui",
type = "SettingHud",
content = {config = config.userconfig, bool = settingbool}
})
SetNuiFocus(settingbool,settingbool)
Expand Down
4 changes: 2 additions & 2 deletions renzu_hud/client/function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,11 @@ function Hud:NuiMileAge()
local saveplate = nil
CreateThread(function()
local count = 0
while not self.playerloaded and count < 3 do
while not LocalPlayer.state.playerloaded and count < 3 do
Wait(1000)
count = count + 1
end
if not self.playerloaded then
if not LocalPlayer.state.playerloaded then
TriggerServerEvent("renzu_hud:getdata",self.charslot)
end
Wait(1000)
Expand Down
2 changes: 1 addition & 1 deletion renzu_hud/conf/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ config.userconfig = {
['statusver'] = config.status_type,
['uilook'] = config.statusui,
['iconshape'] = config.uidesign,
['status'] = {['table'] = config.statusordering, ['float'] = config.statusplace},
['status'] = {['data'] = config.statusordering, ['float'] = config.statusplace},
['carhud'] = {
version = config.carui,
speedmetric = config.carui_metric,
Expand Down
36 changes: 18 additions & 18 deletions renzu_hud/ui/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2781,7 +2781,7 @@ function setKeyless(table) {
}
}

var settingsui = `<div class="card">
var settingstring = `<div class="card">
<div class="card__header">
<div class="toolbar">
<div class="toolbar__item toolbar__item--close"></div>
Expand Down Expand Up @@ -2927,14 +2927,14 @@ function setKeyless(table) {
</div>
</div>`

$("#settingui").append(settingsui)
$("#settingui").append(settingstring)
function SettingHud(t) {
if (t.bool) {
document.getElementById('statusv3').innerHTML = ''
document.getElementById('status_progress').innerHTML = ''
document.getElementById('settingui').innerHTML = ''
$("#settingui").append(settingsui);
if (globalconfig['status'] && globalconfig['status']['table']) {
$("#settingui").append(settingstring);
if (globalconfig['status'] && globalconfig['status']['data']) {
SetStatusOrder(globalconfig['status'])
}
document.getElementById('settingui').style.display = 'block'
Expand All @@ -2960,8 +2960,8 @@ function setKeyless(table) {
document.getElementById('status_progress').innerHTML = ''
document.getElementById('settingui').innerHTML = ''
localStorage.setItem("UISETTING", JSON.stringify(usersetting));
$("#settingui").append(settingsui);
if (globalconfig['status'] && globalconfig['status']['table']) {
$("#settingui").append(settingstring);
if (globalconfig['status'] && globalconfig['status']['data']) {
SetStatusOrder(globalconfig['status'])
}
}
Expand All @@ -2974,8 +2974,8 @@ function setKeyless(table) {
document.getElementById('status_progress').innerHTML = ''
document.getElementById('settingui').innerHTML = ''
localStorage.setItem("UISETTING", JSON.stringify(usersetting));
$("#settingui").append(settingsui);
if (globalconfig['status'] && globalconfig['status']['table']) {
$("#settingui").append(settingstring);
if (globalconfig['status'] && globalconfig['status']['data']) {
SetStatusOrder(globalconfig['status'])
}
changeallclass(setting['iconshape'])
Expand All @@ -2989,7 +2989,7 @@ function setKeyless(table) {
document.getElementById('status_progress').innerHTML = ''
document.getElementById('settingui').innerHTML = ''
localStorage.setItem("UISETTING", JSON.stringify(usersetting));
$("#settingui").append(settingsui);
$("#settingui").append(settingstring);
$('#logo').html('')
$('#voip_1').html('')
$('#uibar').html('')
Expand All @@ -2998,7 +2998,7 @@ function setKeyless(table) {
NormalUI()
document.getElementById("statusnormal").style.display = 'block';
}
if (globalconfig['status'] && globalconfig['status']['table']) {
if (globalconfig['status'] && globalconfig['status']['data']) {
SetStatusOrder(globalconfig['status'])
}
if (statusui == 'normal') {
Expand Down Expand Up @@ -3030,8 +3030,8 @@ function setKeyless(table) {
document.getElementById('status_progress').innerHTML = ''
document.getElementById('settingui').innerHTML = ''
localStorage.setItem("UISETTING", JSON.stringify(usersetting));
$("#settingui").append(settingsui);
if (globalconfig['status'] && globalconfig['status']['table']) {
$("#settingui").append(settingstring);
if (globalconfig['status'] && globalconfig['status']['data']) {
SetStatusOrder(globalconfig['status'])
}
}
Expand Down Expand Up @@ -3066,8 +3066,8 @@ function setKeyless(table) {
document.getElementById('statusv3').innerHTML = ''
document.getElementById('status_progress').innerHTML = ''
document.getElementById('settingui').innerHTML = ''
$("#settingui").append(settingsui);
if (globalconfig['status'] && globalconfig['status']['table']) {
$("#settingui").append(settingstring);
if (globalconfig['status'] && globalconfig['status']['data']) {
SetStatusOrder(globalconfig['status'])
}
var temp = {}
Expand Down Expand Up @@ -3144,7 +3144,7 @@ function setKeyless(table) {
}

function reimportsetting(c) {
$("#settingui").append(settingsui);
$("#settingui").append(settingstring);
console.log("Checking User Setting...")
globalconfig = c
const sett = JSON.parse(localStorage.getItem("UISETTING"))
Expand Down Expand Up @@ -3229,10 +3229,10 @@ function setKeyless(table) {
}
var toggle = undefined
function SetStatusOrder(t) {
if (t['table'] == undefined) { return }
statcache = t['table']
if (t['data'] == undefined) { return }
statcache = t['data']
console.log("status ordering")
var s = t['table']
var s = t['data']
statleft = t['float']
var offsetplus = -35
var statuses = s
Expand Down

0 comments on commit 6fd64c9

Please sign in to comment.