From a325f96c643f5294f0aaa4ee26185b40938f2550 Mon Sep 17 00:00:00 2001
From: Linden <65407488+thelindat@users.noreply.github.com>
Date: Wed, 2 Jun 2021 11:56:22 +1000
Subject: [PATCH] tweak(client/main): Set PVP and hud after the player has
spawned
---
client/main.lua | 53 ++++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 27 deletions(-)
diff --git a/client/main.lua b/client/main.lua
index 45151796..1182cd2b 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -9,38 +9,12 @@ Citizen.CreateThread(function()
end
end)
-fix(client/main): Set PlayerData.ped correctly
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerData, isNew)
ESX.PlayerLoaded = true
ESX.PlayerData = playerData
- ESX.PlayerData.ped = PlayerPedId()
- FreezeEntityPosition(ESX.PlayerData.ped, true)
-
- -- enable PVP
- if Config.EnablePVP then
- SetCanAttackFriendly(ESX.PlayerData.ped, true, false)
- NetworkSetFriendlyFireOption(true)
- end
-
- if Config.EnableHud then
- for k,v in ipairs(playerData.accounts) do
- local accountTpl = '

{{money}}
'
- ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)})
- end
-
- local jobTpl = '{{job_label}} - {{grade_label}}
'
-
- if playerData.job.grade_label == '' or playerData.job.grade_label == playerData.job.label then
- jobTpl = '{{job_label}}
'
- end
-
- ESX.UI.HUD.RegisterElement('job', #playerData.accounts, 0, jobTpl, {
- job_label = playerData.job.label,
- grade_label = playerData.job.grade_label
- })
- end
+ FreezeEntityPosition(PlayerPedId(), true)
if Config.Multichar then
TriggerEvent('esx_multicharacter:SpawnCharacter', playerData.coords, isNew)
@@ -71,6 +45,31 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew)
FreezeEntityPosition(ESX.PlayerData.ped, false)
end)
end
+
+ while ESX.PlayerData.ped == nil do Citizen.Wait(20) end
+ -- enable PVP
+ if Config.EnablePVP then
+ SetCanAttackFriendly(ESX.PlayerData.ped, true, false)
+ NetworkSetFriendlyFireOption(true)
+ end
+
+ if Config.EnableHud then
+ for k,v in ipairs(playerData.accounts) do
+ local accountTpl = '
{{money}}
'
+ ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)})
+ end
+
+ local jobTpl = '{{job_label}} - {{grade_label}}
'
+
+ if playerData.job.grade_label == '' or playerData.job.grade_label == playerData.job.label then
+ jobTpl = '{{job_label}}
'
+ end
+
+ ESX.UI.HUD.RegisterElement('job', #playerData.accounts, 0, jobTpl, {
+ job_label = playerData.job.label,
+ grade_label = playerData.job.grade_label
+ })
+ end
StartServerSyncLoops()
end)