Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(net): Add NetworkSetEntityOwner server native #2312

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ivanzaida
Copy link
Contributor

@ivanzaida ivanzaida commented Dec 22, 2023

Goal of this PR

This pull request introduces the NETWORK_SET_ENTITY_OWNER native to the server side of the application, facilitating the manual migration of the owning player for entities.
This may be extremely useful alongside the sv_filterRequestControl being set to 4.

How is this PR achieving the goal

The created native uses FiveM's inner method that migrates entities owners, I believe the ServerGameState->ReassignEntity handles all the edge cases regarding entity owner migration.

This PR applies to the following area(s)

Server

Successfully tested on

Game builds: 2944
Platforms: Windows, Linux

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

@blattersturm
Copy link
Contributor

FWIW @AvarianKnight had tagged some concerns about this being a somewhat undesirable command here due to the risk of side effects (such as ownership being reassigned) that users of the API would have to manually take into account. Might need more specific use cases beyond 'useful with filtercontrol enabled' be mentioned so a solution can be thought of for those use cases.

@ivanzaida
Copy link
Contributor Author

ivanzaida commented Dec 24, 2023

Thanks for your reply.
The ownership reassignment is indeed a side-effect, but from what I've tested it only happens to population entities.
It seems like the population ownership system is designed in some way that a player owns some kind of a territory around him and the game does not let to reasign an entity to a different player (it actually allows, but after a few seconds the ownership gets reset).
From what I've tested, server-created entities do not get automatically reasigned to the territory-owner, and the assigned user can manipulate the entity's state in more efficient way than doing RPC requests.
Also, I got tired defining custom events for managing an entity state / running some client-specific natives on the owning client's side, who is not the actual target of the script, e.g. :

// client
onNet('PlayPedAmbientSpeechNative', (pedNetId: number, speechName: string, speechParam: string) => {
  const entity = NetworkGetEntityFromNetworkId(pedNetId);
  if (!entity) {
    return;
  }
  PlayPedAmbientSpeechNative(entity, speechName, speechParam);
})

I believe, I'm not the only one who is tired of doing this kind of boilerplate job, and the changes present in this PR would save lots of developer time

@thorium-cfx thorium-cfx added the triage Needs a preliminary assessment to determine the urgency and required action label Feb 12, 2024
@AvarianKnight
Copy link
Contributor

AvarianKnight commented Feb 12, 2024

I don't think this is a proper solution to the problem.

This PR would expect everyone using to have a general understanding on how everything should work and also expect them to not break "rules" (i.e. don't set the owner to someone that it can't be relevant to), and we also shouldn't be spilling internals to the end user.

A proper solution would be to either have server-side setters (which seems like a pipe dream if we're being honest), or fixing the RPC system so instead of sending a RPC once and hoping it gets executed, add RPC calls to a vector/map and send the RPC execution to the client until it gets acked.

Something similar to this could be added internally and not exposed to the end user, so if there are RPCs pending for an entity, the server should refuse to mitigate the entity unless it is no longer relevant to the currently locked owner (to hopefully not have the owner ping-pong around players while trying to sync) , after which it should find another relevant player and try to execute the RPC calls again.

@ivanzaida
Copy link
Contributor Author

would be nice if you guys could take care of the proper solution, but it seems like a pipe dream as well

@FabianTerhorst
Copy link
Contributor

In my opinion there is a missing a way to prevent network owner change after using this setter for this specific entity. Having that possibility would make this setter more useful.

@github-actions github-actions bot added invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Requires changes before it's considered valid and can be (re)triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants