From 6514da2f0c4566b22899b1c023fcca5a1a372848 Mon Sep 17 00:00:00 2001 From: goncalobsccosta <65927483+goncalobsccosta@users.noreply.github.com> Date: Tue, 8 Dec 2020 21:00:59 +0000 Subject: [PATCH 1/3] Fixed other players blinking when instanced and fixed the collision problem Since now the invisibility is updated every frame, the collision is only removed in the same frame. I also noticed that the ped order was wrong, because players were colliding when they were in diferent instances. --- client/main.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/main.lua b/client/main.lua index c8336ea8..72359b10 100644 --- a/client/main.lua +++ b/client/main.lua @@ -193,7 +193,7 @@ end) Citizen.CreateThread(function() while true do - Citizen.Wait(10) + Citizen.Wait(0) local playerPed = PlayerPedId() -- Hide all these players @@ -203,7 +203,7 @@ Citizen.CreateThread(function() if NetworkIsPlayerActive(player) then local otherPlayerPed = GetPlayerPed(player) SetEntityVisible(otherPlayerPed, false, false) - SetEntityNoCollisionEntity(playerPed, otherPlayerPed, false) + SetEntityNoCollisionEntity(otherPlayerPed, playerPed, true) end end end @@ -228,4 +228,4 @@ Citizen.CreateThread(function() Citizen.Wait(500) end end -end) \ No newline at end of file +end) From 6f485d1e0820c0cd3e02d2acb6bbc71daa169188 Mon Sep 17 00:00:00 2001 From: goncalobsccosta <65927483+goncalobsccosta@users.noreply.github.com> Date: Sat, 12 Dec 2020 20:32:25 +0000 Subject: [PATCH 2/3] general client optimization --- client/main.lua | 70 ++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/client/main.lua b/client/main.lua index 72359b10..3c4c778f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -2,6 +2,7 @@ local instance, instancedPlayers, registeredInstanceTypes, playersToHide = {}, { local instanceInvite, insideInstance ESX = nil + Citizen.CreateThread(function() while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) @@ -25,6 +26,18 @@ end function EnterInstance(instance) insideInstance = true + -- Fix vehicles randomly spawning nearby the player inside an instance + Citizen.CreateThread(function() + while insideInstance do + Citizen.Wait(0) -- must be run every frame + + SetVehicleDensityMultiplierThisFrame(0.0) + SetParkedVehicleDensityMultiplierThisFrame(0.0) + + local pos = GetEntityCoords(PlayerPedId()) + RemoveVehiclesFromGeneratorsInArea(pos.x - 900.0, pos.y - 900.0, pos.z - 900.0, pos.x + 900.0, pos.y + 900.0, pos.z + 900.0) + end + end) TriggerServerEvent('instance:enter', instance.host) if registeredInstanceTypes[instance.type].enter then @@ -137,6 +150,20 @@ AddEventHandler('instance:onInvite', function(_instance, type, data) } Citizen.CreateThread(function() + -- Controls for invite + Citizen.CreateThread(function() + while instanceInvite do + Citizen.Wait(0) + + ESX.ShowHelpNotification(_U('press_to_enter')) + + if IsControlJustReleased(0, 38) then + EnterInstance(instanceInvite) + ESX.ShowNotification(_U('entered_instance')) + instanceInvite = nil + end + end + end) Citizen.Wait(10000) if instanceInvite then @@ -148,25 +175,6 @@ end) RegisterInstanceType('default') --- Controls for invite -Citizen.CreateThread(function() - while true do - Citizen.Wait(0) - - if instanceInvite then - ESX.ShowHelpNotification(_U('press_to_enter')) - - if IsControlJustReleased(0, 38) then - EnterInstance(instanceInvite) - ESX.ShowNotification(_U('entered_instance')) - instanceInvite = nil - end - else - Citizen.Wait(500) - end - end -end) - -- Instance players Citizen.CreateThread(function() while true do @@ -191,10 +199,13 @@ Citizen.CreateThread(function() end end) +local letSleep = true + Citizen.CreateThread(function() while true do Citizen.Wait(0) local playerPed = PlayerPedId() + letSleep = true -- Hide all these players for serverId,_ in pairs(playersToHide) do @@ -204,8 +215,13 @@ Citizen.CreateThread(function() local otherPlayerPed = GetPlayerPed(player) SetEntityVisible(otherPlayerPed, false, false) SetEntityNoCollisionEntity(otherPlayerPed, playerPed, true) + letSleep = false end end + + if letSleep then + Citizen.Wait(1000) + end end end) @@ -213,19 +229,3 @@ Citizen.CreateThread(function() TriggerEvent('instance:loaded') end) --- Fix vehicles randomly spawning nearby the player inside an instance -Citizen.CreateThread(function() - while true do - Citizen.Wait(0) -- must be run every frame - - if insideInstance then - SetVehicleDensityMultiplierThisFrame(0.0) - SetParkedVehicleDensityMultiplierThisFrame(0.0) - - local pos = GetEntityCoords(PlayerPedId()) - RemoveVehiclesFromGeneratorsInArea(pos.x - 900.0, pos.y - 900.0, pos.z - 900.0, pos.x + 900.0, pos.y + 900.0, pos.z + 900.0) - else - Citizen.Wait(500) - end - end -end) From 79e4abc832e20d75aefcd988c3a62d8f3beed879 Mon Sep 17 00:00:00 2001 From: goncalobsccosta <65927483+goncalobsccosta@users.noreply.github.com> Date: Sat, 6 Feb 2021 04:49:33 +0000 Subject: [PATCH 3/3] Remove nested thread --- client/main.lua | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/client/main.lua b/client/main.lua index 3c4c778f..94f0404b 100644 --- a/client/main.lua +++ b/client/main.lua @@ -148,22 +148,22 @@ AddEventHandler('instance:onInvite', function(_instance, type, data) host = _instance, data = data } + Citizen.CreateThread(function() + while instanceInvite do + Citizen.Wait(0) + ESX.ShowHelpNotification(_U('press_to_enter')) + + if IsControlJustReleased(0, 38) then + EnterInstance(instanceInvite) + ESX.ShowNotification(_U('entered_instance')) + instanceInvite = nil + end + end + end) + Citizen.CreateThread(function() -- Controls for invite - Citizen.CreateThread(function() - while instanceInvite do - Citizen.Wait(0) - - ESX.ShowHelpNotification(_U('press_to_enter')) - - if IsControlJustReleased(0, 38) then - EnterInstance(instanceInvite) - ESX.ShowNotification(_U('entered_instance')) - instanceInvite = nil - end - end - end) Citizen.Wait(10000) if instanceInvite then @@ -171,6 +171,7 @@ AddEventHandler('instance:onInvite', function(_instance, type, data) instanceInvite = nil end end) + end) RegisterInstanceType('default')