qb-core icon indicating copy to clipboard operation
qb-core copied to clipboard

Framework Optimization

Open KamuiKody opened this issue 1 year ago • 6 comments

for optimization of other resources.

Description

This is to further optimize other resources that commonly use loops to check if in vehicle. This also gathers common variables so all these resources wont have to call for the same variables.

RegisterNetEvent('QBCore:Client:EnteringVehicle') triggers once when you try to enter a vehicle to break a loop triggered by this you would add this line to it: if GetVehiclePedIsTryingToEnter(PlayerPedId()) == 0 then break end

RegisterNetEvent('QBCore:Client:AbortVehicleEntering') triggers once when you abort entering a vehicle or the door is locked. it passes no variables since typically it would be used to kill a loop

RegisterNetEvent('QBCore:Client:EnteredVehicle') triggers once when you enter a vehicle or when you spawn inside of a vehicle if IsPedInAnyVehicle(PlayerPedId()) == 0 then break end

RegisterNetEvent('QBCore:Client:LeaveVehicle') triggers once when you leave a vehicle

Checklist

  • [x] I have personally loaded this code into an updated qbcore project and checked all of its functionality.
  • [x] My code fits the style guidelines.
  • [x] My PR fits the contribution guidelines.

KamuiKody avatar Sep 05 '22 03:09 KamuiKody

works

r0adra93 avatar Sep 08 '22 05:09 r0adra93

Not to be combatative but id like to know where you saw this because i actually got these events front the cfx docs and upon search couldnt find anything on the forums about them except for the fact that they are used as a tool for developement.

KamuiKody avatar Sep 08 '22 22:09 KamuiKody

https://github.com/citizenfx/cfx-server-data

On Thu., Sep. 8, 2022, 4:16 p.m. KamuiKody, @.***> wrote:

Not to be combatative but id like to know where you saw this because i actually got these events front the cfx docs and upon search couldnt find anything on the forums about them except for the fact that they are used as a tool for developement.

— Reply to this email directly, view it on GitHub https://github.com/qbcore-framework/qb-core/pull/828#issuecomment-1241291724, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYCPZCSHSHIO5FHDHX3TWKLV5JQU5ANCNFSM6AAAAAAQETBZ2A . You are receiving this because you commented.Message ID: @.***>

ghost avatar Sep 08 '22 23:09 ghost

I see. They said in the reafme that it would be moved they didnt say when though and if they were going to fully remove it. Which they should i guess the way i saw it was these events come on a loop in a base server anyway theres no reason for us to call a loop in 75% of our resources to look for a vehicle. If you do have a better suggestion im all ears for it ill test it out a bit

KamuiKody avatar Sep 08 '22 23:09 KamuiKody

If you do have a better suggestion im all ears for it ill test it out a bit

In order to avoid relying on baseevents which runs every frame, you could create a loop with a wait of 200ms and trigger an event on vehicle change. then you don't even need to run baseevents on server start

mahanmoulaei avatar Sep 14 '22 12:09 mahanmoulaei

but then you are asking people who may or may not be developers to remove something for server performance where as this update utilizes a loop that already exists. im going to be looking into low level game events. also making something call every 200ms vs every frame does not give u substancial performance gain. The low level game events however should remove the loop completely. So whenever they do depricate baseevents completely there should be better options.

KamuiKody avatar Sep 14 '22 12:09 KamuiKody