Add vehicle status player events#1205
Add vehicle status player events#1205Cocodrulo wants to merge 10 commits intoqbcore-framework:mainfrom
Conversation
Implements client-side detection and server event triggers for entering, aborting, entering, and leaving vehicles when the 'baseevents' resource is not started. This ensures vehicle-related events are still handled even if the baseevents resource is unavailable.
Why not? Why make a full event of QBCore relly on the existance of a script or not in the server and don't have a fallback? |
|
I haven't tested this event personally, but could we benefit from using the CEventNetworkPlayerEnteredVehicle game event instead of the thread? |
|
I don't think that event will detect the seat change |
|
Do you mean when someone shuffles seat without leaving the vehicle? |
|
exactly |
|
And also when entering is aborted |
|
From what I see, the current logic is: |
True, Do you know if that event triggers every time someone tries to get into vehicle? I mean, is it like the shooting one that triggers once for each ped near the shooting or is it only one by the player trying to get into a vehicl |
|
I dont really think we should be forcing our users to use baseevents, which this is pretty much doing. It isnt performant at all, and it is very well possible that servers choose intentionally not to use baseevents - which this would circumvent. |
|
I agree we shouldn't force users to use The way I see it is people should instead be using To me, that just leaves the main question of:
Also, was my first comment ever looked into further for entering vehicles? If not I can try to fit some time in to look at it: CEventNetworkPlayerEnteredVehicle If we can't find something more event based for everything, I believe our best course of action is:
|
|
I'll look into this |
|
If've check and we cannot replicate the events in baseevents just with CEvents. There is just one event useful here that is the one you mentioned "CEventNetworkPlayerEnteredVehicle". The problem is that baseevents provides (and therefore QBCore uses) four events:
With the provided event we can detect the enteredVehicle and kind of the leftVehicle if we make a loop when entered a vehicle and check if it is still inside or not. But the enteringVehicle and the enteringAborted cannot be detected (at least in any way I found). So we have really to options, continue with the baseevents fallback and make those event reliable and works under any circumstances or just do two out of four events. What do you think? @Qwerty1Verified |
I mean, there are 10000+ servers using qb-core, https://5metrics.dev/resource/qb-core
It is very apparent that baseevents, and the functionality it provides, is something people (excuse my language) couldnt care less about. And something that 99% of qbcore servers live without daily. As you mention though, we do use baseevents in some of our default qb-core logic. More specifically, for the
(The All of the abortion logic of the entering vehicle is handled in the respective script(s) mentioned above. So, we could in theory 100% make due with the "CEventNetworkPlayerEnteredVehicle" event. In my opinion, we should rather just rework the above mentioned scripts to use the "CEventNetworkPlayerEnteredVehicle" event, as that should in theory perform better(?). |
|
@Z3rio I know that baseevents it's used by anoyne, I don't use it either. But I think that if QBCore had an event to check enetering and leaving vehicles, scripts will be more optimized (each scripts has a loop to check for entering a vehicle). So I could use the CEventNetworkPlayerEnteredVehicle to check when entered and left the vehicle and the entering just be the same that when you enter. Do you agree? |
|
I agree that would be an optimal solution, yeah. But is the So the real work here would rather be actually refactoring all applicable qb-core resources to not use baseevents in its entirety (and not include in txadmin recipe), in favor of the |
|
Yeah I'd rather run a thread when needed than 24/7, so if we can avoid running a thread 24/7 by doing what I mentioned in an earlier comment we should be able to both remove any baseevents dependence, and improve performance overall. For example, if a player is not in a vehicle, we don't need to know whether they left or switched seats. We do need to know if a player is in a vehicle though so we can then look for those other changes, which the game event gives us |
|
I think that making a QBCore wrapper is the best option @Z3rio beacuse that event only provides the "player entered" functionality, but player left still needs a thread, so having it only in QBCore is better than in every single resource, right? I propose this:
Do you @Z3rio and @Qwerty1Verified agree with this? |
|
Yeah sounds in line with what I mentioned. It only runs when necessary in that case, still facilitates our required use case, and since the timing for those other events are less critical also allows us to reduce the loop frequency for massive performance gains. I also agree having a centralised and optimised thread that fires events is better than having repeated logic and threads running across several first and third party resources. We can control the conditions, and reduce repeated computation doing this. |
|
@Qwerty1Verified if you could check out the code and tell me what do you think. It was added:
|
|
Did you take a look? @Qwerty1Verified I tried in my server and it worked |
|
The changes look good, but this breaks the table structure passed by the |
|
yes, but there isn't lots of people that uses the current system, since it relies on baseevents and there isn't lots of servers that use it. https://5metrics.dev/resource/baseevents |
|
I think we could make it work with VehicleInfo with minimal modifications (I'm currently testing this out don't worry). Upon testing, I do notice a check that seems to be causing the thread to not begin. When the game event is triggered, you setup |
|
I remembered trying it and working. But reviewing my code now, it doesn't make sense. So I removed the vehicle manual declaration. About the VehicleInfo. I think it is better to separated it in different and self named events so it is clear what I'm cheking and so if I'm only checking for vehicle entering that function don't be triggered more times that necessary. |
|
Ah ok thank you, I'll take another look with those changes and compare with mine. As for VehicleInfo, that event actually does fire off specific events, it's just an internal event we use to consistently build data, but after that the specific events are fired off based on the In theory you could listen to the entire VehicleInfo event itself if you wanted all events, and then run your own checks against the event field, which I do kinda like. |
|
So what do you want to do? |
|
I just need to check out that new change, and ensure that we tackle the key points whilst keeping developer usability as is. I pretty much finished the changes on my end and they were very minor. |
|
perfect!! |
Description
This pull request adds a fallback implementation for vehicle-related player events in
server/events.luato ensure core vehicle event handling works even if thebaseeventsresource is not running. The new code tracks when a player enters, aborts entering, enters, or leaves a vehicle, and triggers the appropriate server events.Baseevents fallback implementation:
baseevents:enteringVehicle,baseevents:enteringAborted,baseevents:enteredVehicle,baseevents:leftVehicle) when thebaseeventsresource is not started. This ensures consistent vehicle event handling regardless of resource state.GetPedVehicleSeatto determine the seat index the player occupies in a vehicle.Checklist