diff --git a/client/main.lua b/client/main.lua index 4d51a8aa..4bc699af 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,4 +1,4 @@ -local isLoadoutLoaded, isPaused, isDead, pickups = false, false, false, {} +local isPaused, isDead, pickups = false, false, {} Citizen.CreateThread(function() while true do @@ -22,7 +22,7 @@ AddEventHandler('esx:playerLoaded', function(playerData) RequestModel(defaultModel) while not HasModelLoaded(defaultModel) do - Citizen.Wait(100) + Citizen.Wait(10) end SetPlayerModel(PlayerId(), defaultModel) @@ -36,10 +36,13 @@ AddEventHandler('esx:playerLoaded', function(playerData) local playerPed = PlayerPedId() - if Config.EnablePvP then - SetCanAttackFriendly(playerPed, true, false) - NetworkSetFriendlyFireOption(true) - end + -- enable PVP + SetCanAttackFriendly(playerPed, true, false) + NetworkSetFriendlyFireOption(true) + + -- disable wanted level + ClearPlayerWantedLevel(PlayerId()) + SetMaxWantedLevel(0) if Config.EnableHud then for k,v in ipairs(playerData.accounts) do @@ -65,7 +68,6 @@ AddEventHandler('esx:playerLoaded', function(playerData) z = playerData.coords.z + 0.5, heading = playerData.coords.heading }, function() - isLoadoutLoaded = true TriggerServerEvent('esx:onPlayerSpawn') TriggerEvent('esx:onPlayerSpawn') TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon @@ -74,6 +76,7 @@ AddEventHandler('esx:playerLoaded', function(playerData) Citizen.Wait(3000) ShutdownLoadingScreen() DoScreenFadeIn(10000) + StartServerSyncLoops() end) end) @@ -82,7 +85,6 @@ AddEventHandler('esx:setMaxWeight', function(newMaxWeight) ESX.PlayerData.maxWei AddEventHandler('esx:onPlayerSpawn', function() isDead = false end) AddEventHandler('esx:onPlayerDeath', function() isDead = true end) -AddEventHandler('skinchanger:loadDefaultModel', function() isLoadoutLoaded = false end) AddEventHandler('skinchanger:modelLoaded', function() while not ESX.PlayerLoaded do @@ -118,8 +120,6 @@ AddEventHandler('esx:restoreLoadout', function() ammoTypes[ammoType] = true end end - - isLoadoutLoaded = true end) RegisterNetEvent('esx:setAccountMoney') @@ -248,7 +248,7 @@ RegisterNetEvent('esx:setJob') AddEventHandler('esx:setJob', function(job) if Config.EnableHud then ESX.UI.HUD.UpdateElement('job', { - job_label = job.label, + job_label = job.label, grade_label = job.grade_label }) end @@ -421,28 +421,52 @@ if Config.EnableHud then end) end --- Keep track of ammo usage -Citizen.CreateThread(function() - while true do - Citizen.Wait(0) +function StartServerSyncLoops() + -- keep track of ammo + Citizen.CreateThread(function() + while true do + Citizen.Wait(0) - if isDead then - Citizen.Wait(500) - else - local playerPed = PlayerPedId() + if isDead then + Citizen.Wait(500) + else + local playerPed = PlayerPedId() - if IsPedShooting(playerPed) then - local _,weaponHash = GetCurrentPedWeapon(playerPed, true) - local weapon = ESX.GetWeaponFromHash(weaponHash) + if IsPedShooting(playerPed) then + local _,weaponHash = GetCurrentPedWeapon(playerPed, true) + local weapon = ESX.GetWeaponFromHash(weaponHash) - if weapon then - local ammoCount = GetAmmoInPedWeapon(playerPed, weaponHash) - TriggerServerEvent('esx:updateWeaponAmmo', weapon.name, ammoCount) + if weapon then + local ammoCount = GetAmmoInPedWeapon(playerPed, weaponHash) + TriggerServerEvent('esx:updateWeaponAmmo', weapon.name, ammoCount) + end end end end - end -end) + end) + + -- sync current player coords with server + Citizen.CreateThread(function() + local previousCoords = vector3(ESX.PlayerData.coords.x, ESX.PlayerData.coords.y, ESX.PlayerData.coords.z) + + while true do + Citizen.Wait(1000) + local playerPed = PlayerPedId() + + if DoesEntityExist(playerPed) then + local playerCoords = GetEntityCoords(playerPed) + local distance = #(playerCoords - previousCoords) + + if distance > 1 then + previousCoords = playerCoords + local playerHeading = ESX.Math.Round(GetEntityHeading(playerPed), 1) + local formattedCoords = {x = ESX.Math.Round(playerCoords.x, 1), y = ESX.Math.Round(playerCoords.y, 1), z = ESX.Math.Round(playerCoords.z, 1), heading = playerHeading} + TriggerServerEvent('esx:updateCoords', formattedCoords) + end + end + end + end) +end Citizen.CreateThread(function() while true do @@ -456,21 +480,6 @@ Citizen.CreateThread(function() end end) --- Disable wanted level -if Config.DisableWantedLevel then - Citizen.CreateThread(function() - while true do - Citizen.Wait(0) - local playerId = PlayerId() - - if GetPlayerWantedLevel(playerId) ~= 0 then - SetPlayerWantedLevel(playerId, 0, false) - SetPlayerWantedLevelNow(playerId, false) - end - end - end) -end - -- Pickups Citizen.CreateThread(function() while true do @@ -519,30 +528,3 @@ Citizen.CreateThread(function() end end end) - --- Update current player coords -Citizen.CreateThread(function() - -- wait for player to restore coords - while not isLoadoutLoaded do - Citizen.Wait(1000) - end - - local previousCoords = vector3(ESX.PlayerData.coords.x, ESX.PlayerData.coords.y, ESX.PlayerData.coords.z) - - while true do - Citizen.Wait(1000) - local playerPed = PlayerPedId() - - if DoesEntityExist(playerPed) then - local playerCoords = GetEntityCoords(playerPed) - local distance = #(playerCoords - previousCoords) - - if distance > 1 then - previousCoords = playerCoords - local playerHeading = ESX.Math.Round(GetEntityHeading(playerPed), 1) - local formattedCoords = {x = ESX.Math.Round(playerCoords.x, 1), y = ESX.Math.Round(playerCoords.y, 1), z = ESX.Math.Round(playerCoords.z, 1), heading = playerHeading} - TriggerServerEvent('esx:updateCoords', formattedCoords) - end - end - end -end) diff --git a/config.lua b/config.lua index 97217502..8f6134ff 100644 --- a/config.lua +++ b/config.lua @@ -10,13 +10,9 @@ Config.Accounts = { Config.StartingAccountMoney = {bank = 50000} Config.EnableSocietyPayouts = false -- pay from the society account that the player is employed at? Requirement: esx_society -Config.DisableWantedLevel = true Config.EnableHud = true -- enable the default hud? Display current job and accounts (black, bank & cash) -Config.EnablePvP = true -- enable pvp? Config.MaxWeight = 24 -- the max inventory weight without backpack - Config.PaycheckInterval = 7 * 60000 -- how often to recieve pay checks in milliseconds - Config.EnableDebug = false Config.IncompatibleResourcesToStop = {