Jump to content
Sign in to follow this  
Muzzleflash

Working Multiplayer UAV

Recommended Posts

Hi All

I see there are some threads on how to make UAV work in multiplayer on dedicated server that didn't seem to offer the wanted result. I had a similar problem for a mission I was working on. My solution is not perfect and might cause problems if multiple person are trying to use multiple UAVs at the same time. And the update is not instant. I tried this on a dedicated server I hosted and it worked fine, whereas before my solution did not, so I see no reason it should not work for you guys that need it.

Create the module, the terminal(s) and the UAV. Sync them together. Any units you want to be able to use this; sync them too. I prefer just adding the entire side to the rules like this in the init of the module: this setvariable ["rules",[west]];.

It will still work if you don't sync the UAV due the below trigger, however if you don't sync the uav you only get one waypoint and not the standard 4.

Create a trigger with the following:

Condition: local player

On Act: bis_uav_0 synchronizeObjectsAdd [uav]

Where the uav has name=uav. Every uav module created get's it's own number starting from 0. If you need more then you can check the last index created with bis_uav_lastId.

The following script is what makes other people able to control it:


MP_UAV_Handler_CurrentUAV = objNull;
MP_UAV_Handler_Height = 500;
MP_UAV_Handler_Speed = 250;
if (isServer) then
{
   if (isNil "MP_UAV_Handler_INIT") then {
       "MP_UAV_Handler_Height" addPublicVariableEventHandler
           {_h = _this select 1; MP_UAV_Handler_CurrentUAV flyInHeight _h; };
       "MP_UAV_Handler_Speed" addPublicVariableEventHandler
           {_s = _this select 1; driver MP_UAV_Handler_CurrentUAV forceSpeed (_s / 3.6); };
       MP_UAV_Handler_INIT = true;
   };
}
else
{
   waitUntil {sleep 3.0; local player};
   [] spawn {
       private ["_uav", "_newHeight", "_newSpeed"];
       while {true} do {
           if (!(isNil "BIS_UAV_PLANE")) then {
               _uav = BIS_UAV_PLANE;
               if (_uav != MP_UAV_Handler_CurrentUAV) then {
                   MP_UAV_Handler_CurrentUAV = _uav;
                   publicVariable "MP_UAV_Handler_CurrentUAV";
                   sleep 2.0;
               };
               _newHeight = _uav getVariable "BIS_UAV_height";
               _newSpeed = _uav getVariable "BIS_UAV_speed";
               if (_newHeight != MP_UAV_Handler_Height) then {
                   MP_UAV_Handler_Height = _newHeight;
                   publicVariable "MP_UAV_Handler_Height";
               };
               sleep 0.2;
               if (_newSpeed != MP_UAV_Handler_Speed) then {
                   MP_UAV_Handler_Speed = _newSpeed;
                   publicVariable "MP_UAV_Handler_Speed";
               };
           };
           sleep 5.0;
       };
   };
};

What about listen server host? No need to check; already works by standard. What about setting waypoints with map clicking? Works fine already since they use commands which don't care about locality. It's only the height and speed that only can be changed on the server.

Put this script somewhere so it get run on the players and the servers. Personally I just put nul = [] execVM "mpUavHandler.sqf"; in the init of the uav.

No arguments to the script needed. However as I said previously, and which someone can determine from reading the script, it might not work very good when multiple person are using UAV's at the same time.

Edited by Muzzleflash
Error in original

Share this post


Link to post
Share on other sites

looks very good!

but could you perhaps set up a test mission? so the newbies(me including) can copy paste it?

Share this post


Link to post
Share on other sites

What if the UAV is destroyed and you want it to respawn? Would you run into the sync problem again or can you just re-execute the script off the new unit?

Share this post


Link to post
Share on other sites

Hello,

issue with UAV not working correctly on dedicated server was fixed 1.07 base on this lovely bugreport ;)

Share this post


Link to post
Share on other sites

That's "kind" of a bummer..

Oh well I see no reason to post link to the sample mission I just spent 10minutes on. Why don't they just make their modules MP-compatible from start. It's not like it's hard to do at all.

Sardaukar17:

The script just has to start. I just put it in the uav because it seems like an appropriate place and I know it will get run on both the server and the clients, so you should have to re-execute the scripts. You can put it in a trigger's on act if it's condition is true for example.

You will almost certainly have to sync the respawned UAV with the module on all clients, assuming the respawn script creates a new unit. I don't think you'll get the diamond patrol pattern if it is created dynamically (I see no reason to even look into this problem now that it has all been fixed with 1.07).

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×