Is there any way to stop OneSync from migrating entites?

I’m working on a script that spawns in a ped and then the player has a menu that can tell it to do actions. It works fine in a server by myself but when put into the main servers, it breaks. It seems that OneSync (from what I can tell) is switching control of the entity from one player to another. Is there anyway to stop this?

I’ve tried using the native SetNetworkIdCanMigrate and repeating the natives NetworkRequestControlOfEntity and NetworkRequestControlOfNetworkId. None of these have solved the problem and OneSync still migrates the entity to another player. Is there some unknown native I’m not seeing to disable this? Thanks in advance.

1 Like

… how about instead of trying to ‘stop migration’, you make your script aware of this happening and reassign the task?

1 Like

The problem that I have with this is that sometimes when the client loses control of the ped, the ped just does whatever it wants to (like steals cars and stuff). Then, when control is requested back to the client, the server doesn’t give it.

what

how does that have anything to do with making your script migration-aware?

Ok, let me rephrase the problem that I’m having:

I have a ped spawned in and am doing tasks with that ped. When in a OneSync server with other people, the control of that ped will be transfered over to other players, and their tasks will either stop completely or they will be reassigned different tasks (like stealing cars or wandering around). I’m trying to stop the transfer of control to other players. Sometimes, when the control is transfered to other players, the client is unable to gain control again, after running a loop checking if it has control over the ped and requesting control every tick that it doesn’t, like so:

	local timer = GetGameTimer()
	while not NetworkHasControlOfNetworkId(net) do
		NetworkRequestControlOfNetworkId(net)
		Citizen.Wait(0)
		if GetGameTimer() - timer > 5000 then
			showNotification('~r~Control request unsucessful')
			break
		end
	end

which isn’t the right way to solve that issue.

make your script migration-aware instead of trying to stop migration.

basically, send affected network IDs to all clients and use GET_SCRIPT_TASK_STATUS to know if a task vanished.

you should NEVER have to disable migration or manually request control, any cases where you do so are literally bad design.

I’m curious about this as I’ve been doing quite a bit of work with tasking network entities. Is the idea to run the GET_SCRIPT_TASK_STATUS in a a loop and reassign the task if it’s lost?

Correct, though one should do this on all clients.

I realized some info on this would be helpful so might post some helper methods and general guidelines to either cookbook or the formal docs in the coming week.

2 Likes

That would be awesome! Sadly, I to am using the NetworkRequestControl... before tasking peds or even on vehicles before doing things like SetVehicleFixed

The typical case I’m trying to get around with vehicles is say player A drives the vehicle, player A gets out, player B without getting in the vehicle attempts to perform SetVehicleFixed, it seems to work for player B, but when player A gets in again, this is undone/not reflected. Requesting control of the vehicle seems to make this not happen, but if this is not a good way to do this, I’m all ears.

Hello, I have some issues with your point of view, I will try to make constructive arguments.
I use a lots of task sequences for my script, these parts of script are probably thousand lines.

  • Tracking this from all clients are not possible because tasks are generated from ONE player specific actions
  • Complex script will cause many server event, and imply syncing SCRIPT_TASK_STATUS, our “own task status”, and other data (eg: the goto task, is it the goto point B ? point C ? and what is the point C vector3 ? My local timer elapsed, go back to point A…)
  • If the current tracker disconnect ? So yes, every client shoud track the network ID, having the same state of the script. Every clients has to execute complex code that doesn’t concern them directly (see my example below)
  • Synchronized scenes* are not working for other players (only for the owner) (I want, at least, my player** see it and not an other) (*with non player entities, ** see my two example to understand)

2 examples of my use case:
A player can rob a shop by aiming the ped, it start handsup animation, facials anims, voices lines and start the synchronized scene when he is closer. The synchronized scene contains the animation for the ped, creation of a bag, the till animation, etc…
The synchronized scene can speed up (if the player shoot) or slow down if the player is not aiming.
The synchronized scene can stop and the ped can shoot the player (if the player stop looking at the ped)
Once the synchronized scene is finished, the player can aim another till, in this case, the ped will walk in front of this till, and starting back the synchronized scene, etc…
There is a UI that show the global progression based on the synchronized scene progression and remaining tills (using progress bar), the amount of tills remaining, and the current money robbed (based on pickups collected).
Once the robbery is finished, the ped flee away and from now, this is sync with the server because I have to send back the ped in the shop, track the death, resuscitation from players (again, CPR synchronized scene, and task sequence to send back the ped in the shop).
I have 60 stores that use this system, shopkeepers are created when a player enter in the shop, and removed when he goes far away (and the ped is not dead and not playing the flee task)
This system use only 2, 3 client/server event, no while true for ever, …
Based on this use case, tracking all ped tasks whould be very complex.
My second use case:
When a player die, 1 ambulance, 1 driver and 1 passenger peds are created (at the nearest hospital based on player position), if the hospital is too far away, this is an medic helicoper (which imply different tasks, as flying and landing).
The driver drives, the passenger wait for the vehicle stop and near the player, and the player spec the vehicle to track the progression visually (the driver drive faster if the dead player had wait for a long time).
The player track the driver progression and start other tasks based on that. When the driver is near the player, the passenger leave the car, go to the player, start the CPR synchronized scene.
It looks simple but implies a lot of check and tasks.

These two examples looks great, and are deliberately “serverless” because it concern only one client I would love to keep it simple as it is (because it is already complex to manager it from one client)
(They have been designed in 2018 (before OneSync), and my server is still in dev btw…)

So, why don’t I use local entities ? For my second example, I could but I want the other players to see the ambulance and the CPR (and not a player magically wakes up). For the first, I can’t because I have juste detailed my “serverless” part (tasks, animations,…) but there is a real non “serverless” part.

Please consider devs that doesn’t use ESX and doesn’t do basic stuff :slight_smile:
Maybe a OneSync CFX native to disable migration ? Migrate it only when the owner disconnect, making the “migration-aware” process much more simple. In my two example, if a client disconnect, I would juste remove these entities (2nd example) or clearing the task (1st example)

You have probably noticed that English is not my main language, but I hope you understood everything

2 Likes