Hi, is it possible to add 2 events one when entity with owner -1 (server) gets player owner and one when entity gets owner -1 (server)?
That events will help me and another developers alot.
Hi, is it possible to add 2 events one when entity with owner -1 (server) gets player owner and one when entity gets owner -1 (server)?
That events will help me and another developers alot.
Any example use cases?
if i created a vehicle in server side and i want to change the vehicle (position, livery, or anything), i have wait to any owner
so i want to know when the entity gets owner to know when change the position/livery or something else
You donāt, though?
Just tested again, and its not changing until someone is getting close to the vehicle (become owner), but I still think this event should be implemented because there still things that need an owner to achive, like livery, extras and natives that exists only in client side.
Sorry for bumping this 22 month old topic, but I wanted to know if any similar event has been introduced? An event that gets triggered once the owner of an entity/networkId changesā¦
I went through FiveM docs and a lot of google searches, but I couldnāt really find anything related; thatās why I had to write my question in this old(but related) topic.
No such changes have been added, you can use state bags for this kind of feature though
State bags can certainly provide a solution for tracking of entity ownerships, however, it requires an active loop on the server to continuously monitor for any changes in an entity owner and update the state bags accordingly. Thatās why I believe a more efficient and performant approach would be to implement an [internal] event that gets triggered whenever the owner of an entity or networkID changes.
Thanks for the response @AvarianKnight
You can do the ownership check on the client was the idea.
I assume your idea is to update the state bags for all clients and then on the client-side, check whether the entity owner matches with the client or not. Well in this case all clients should do the NetworkGetEntityOwner
or at least check whether the entity is within the client scope of 400 units or not, which is still less efficient than having a server-side event that gets triggered once the owner changes so we can only request the new owner to perform certain checks and tasks without having any loops or extra checks.
Iām trying to achieve TaskWanderInArea
for some spawned networked peds, but wandering stops once the owner of the ped changes. With the current lack of some [internal] events that should get triggered once the ownership of an entity changes, I have 2 solutions now:
(1) Have a loop on client(s) to monitor the ownership and update the state bags(which would be updated on all clients and every client needs to check whether the new owner matches with them to apply TaskWander again or not)
(2) Monitor the ownership changes on the server through a loop that checks for entities owner and directly ask/request the new owner to apply TaskWander again on any change in the ownership(so other clients donāt even need to check whether the new owner matches with them or not).
Thatās why I still think having an internal server-side event such as āentityOwnerChangedā would be more performant. Furthermore, I think having such an event would help reducing client-workload for a lot of server-side vehicle creations that require the owner to apply properties for the vehicles on client-side. (e.g. how ESX creates a vehicle on the server and replicates the vehicle properties state bags to all clients and on every client it checks whether the spawned vehicleās owner matches with the client to apply vehicle properties or not. While by having such an event, we can only directly request the owner client to apply vehicle data without invoking all clients to check for the vehicle ownership)
Feel free to tell me if you believe Iām wrong, or even if you have a better approach for what Iām trying to achieve.
Do what Rockstar does and check GET_SCRIPT_TASK_STATUS return value. This has nothing to do with āownership changesā and using those as a proxy for such will still be inaccurate.
Alternately, state bag values that are server/owner-only, which still would not need āsuch an eventā and do the same thing without risking race conditions or spammy event handlers.
Do what Rockstar does and check GET_SCRIPT_TASK_STATUS return value
Alright Iāll look into decompiled Rockstar codes to see how they do it properlyš
spammy event handlers
I agree with that. But what if some implementation of entity filter could be applied to such event to prevent/reduce spamming? something like the AddStateBagChangeHandler
that has a built-in bag/entity filtering method?
state bag values that are server/owner-only, which still would not need āsuch an eventā
You are correct, however, it is necessary to wait(I can only think of implementing a loop) until the entity owner changes from the default value of -1, which is the server, to a valid player ID; then we can send the desired data to a āstate bag values that are server/owner-onlyā or a ānet event for the specific client we wantā.
One of the reasons Iām requesting this feature(āentityOwnerChangedā) is to basically get rid of any manual waiting/looping that has to be done until the ownership changes from its default value of -1.
If thatās not possible, I understand that, and Iāll try to come up with a workaround with things you & Avarian mentioned.
Thanks for your answer @nta
Huh? Thereās no current implementation of server/owner-only state bags, so Iām not sure how youāre coming to that conclusion.
Player(source).state is a type of a state bag that only communicates with the server and player owner? WRONG
Alternately, state bag values that are server/owner-only, which still would not need āsuch an eventā
Although I rather use net events for this type of actions but, you mentioned it above
EDIT: wait I just noticed Iām wrong & I misunderstood what you said. Nevermind =)
Close your eyes on the part where I said āstate bag values that are server/owner-only"