tweak(client/main): Set PVP and hud after the player has spawned

This commit is contained in:
Linden
2021-06-02 11:56:22 +10:00
committed by GitHub
parent ee711ff9a8
commit a325f96c64
+26 -27
View File
@@ -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 = '<div><img src="img/accounts/' .. v.name .. '.png"/>&nbsp;{{money}}</div>'
ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)})
end
local jobTpl = '<div>{{job_label}} - {{grade_label}}</div>'
if playerData.job.grade_label == '' or playerData.job.grade_label == playerData.job.label then
jobTpl = '<div>{{job_label}}</div>'
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 = '<div><img src="img/accounts/' .. v.name .. '.png"/>&nbsp;{{money}}</div>'
ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)})
end
local jobTpl = '<div>{{job_label}} - {{grade_label}}</div>'
if playerData.job.grade_label == '' or playerData.job.grade_label == playerData.job.label then
jobTpl = '<div>{{job_label}}</div>'
end
ESX.UI.HUD.RegisterElement('job', #playerData.accounts, 0, jobTpl, {
job_label = playerData.job.label,
grade_label = playerData.job.grade_label
})
end
StartServerSyncLoops()
end)