I am struggling with a problem where I should execute a script on some of the player's AI team members. The script works correctly only on objects which are local to the (dedicated) server. It is possible to remove the units from the player group temporarily, but they should be added back later when the script finishes (it is actually BIS's arty module).
Is there a way to directly change locality between clients and the server?
What I tried is to use "join", as the BIS wiki explicitly says that join can change the locality. The wiki also states that AI teams with a server-running AI leader are local to the server. So I tried to
1. create a group on the server,
2. add a "dummy" leader to it which was created on the server,
3. pass the group to the client which executes the join on the members of the team (BIS wiki says join should be executed on the machine where the objects are local),
4. pass the control back to the server which is then executes the script,
5. after finish, issue join to player's group on the server to give them back,
6. cleanup (delete dummy leader and group).
Although it executes without errors, the client's join does not look like to move the team members out of its own group, and they stay remote on the server.
Variations:
- If I issue createGroup on the client, "join" removes units from the player's team. (Shouldn't createGroup's effect be global?) However, the leader is the first added unit, so the group stays remote when I pass it to the server.
- Tried to move out - readd team members (empty vehicles should be local to the server) but did not work.
- Tried to use attachTo to change locality, but it did not work.
Have not gone through all the options I have in mind yet, but maybe somebody can speed up this search... and the answer can be useful for others as well.
///////////////////////////////////////////////
UPDATE: I had a bug in my code, forgot to PV back the group ID to the client. Now it works, so I can confirm that join can be used in this way to directly change the locality. However, if the AI is inside a vehicle, join looks like to have on effect only if issued on the *vehicle* the AI is sitting in, and for some reason even that time it does not transfer the driver, only the gunner. But if I join the driver separately after the vehicle was transferred, it works fine. I dod not tried with vehicles of more crew than 2.