Jump to content
Sign in to follow this  
Big_Daddy

Help with MP UAV Script

Recommended Posts

Yes, yes, i've searched, and found many wonderful posts from the likes of Xeno, cobra, etc.. but I've found something that's throwing me for a loop.

Background. I'm trying to add UAV to Xeno's Domination map (wonderful work btw) And I'm working around the fact that when you die, or when the UAV dies that's it, no more UAV fun. Now, I've been able to do this, and it works great. Twice. The third time I try to respawn the UAV it doesn't have a crew. It just crashes into the ground.

Here's the code:

Addaction on init of Mobile Spawn 1

nul = this addAction ["Launch UAV", "uav.sqf",["xvec1",100,"BIS_UAV","xvec2,xvec1","MQ9PredatorB","west"],0,false]

The arguments I haven't quite got working yet (that will be the next question :))

uav.sqf:

/*  
=========================================================

 1: spawn location
 2: spawn height
 3: Name of UAV Module - BIS_UAV 
 4: units to be syncronized with Names, xvec2, xvec1, (_vec_array select 0)
 5: Version of UAV - MQ9PredatorB
 6: side/group

_myarray = _this select 3;
_spawloc = _myarray select 0;
_spawhei = if (count _myarray > 1) then {_myarray select 1} else {100};
_uavMod = if (count _myarray > 2) then {_myarray select 2} else "BIS_UAV";
_units = if (count _myarray > 3) then {_myarray select 3} else "xvec1, xvec2";
_uavType = if (count _myarray > 4) then {_myarray select 4} else "MQ9PredatorB";
_grp = if (count _myarray > 5) then {_myarray select 5} else "west";

=========================================================
*/
_vec_array = [[getPos xvec1 select 0, getPos xvec1 select 1, (getPos xvec1 select 2) +100], random 360, "MQ9PredatorB", west] call BIS_fnc_spawnVehicle;
BIS_UAV synchronizeObjectsAdd [xvec2, xvec1, (_vec_array select 0)]; 
_vec_array disableAI "AUTOTARGET"; 
_vec_array disableAI "TARGET" ; 
_vec_array setCombatMode "BLUE";
_vec_array setBehaviour "careless";
UAV = _vec_array select 0;
hint format ["%1", _vec_array];

//_vec_array = [[getPos _spacloc select 0, getPos _spawloc select 1, (getPos _spawloc select 2) + _spawhei], random 360, _uavType, _grp] call BIS_fnc_spawnVehicle;
//_uavMod synchronizeObjectsAdd [_units,(_vec_array select 0)];
hint "UAV has been Launched";

exit

Now, again, this works flawlessly twice. the third time, it just crashes into the ground. (but you CAN watch it crash from the UAV terminal) Also, the

_vec_array disableAI "AUTOTARGET";

_vec_array disableAI "TARGET" ;

_vec_array setCombatMode "BLUE";

_vec_array setBehaviour "careless";

isn't working. maybe I need to add

private ["_vec_array"];

Thanks in advance...

Edited by Big_Daddy

Share this post


Link to post
Share on other sites

Ok, it seems the spawn only twice bug may have been just local. I moved testing to the server, and bingo.. works every time.. Ok.. now, Can somebody help me get the UAV to stop playing dive bomber? Here's my updated code..

_grp = createGroup west; 
_vec_array = [[getPos xvec1 select 0, getPos xvec1 select 1, (getPos xvec1 select 2) +100], random 360, "MQ9PredatorB", _grp] call BIS_fnc_spawnVehicle;
BIS_UAV synchronizeObjectsAdd [xvec2, xvec1, (_vec_array select 0)]; 
_grp disableAI "AUTOTARGET"; 
_grp disableAI "TARGET" ; 
_grp setCombatMode "BLUE";
_grp setBehaviour "careless";

//_vec_array = [[getPos _spacloc select 0, getPos _spawloc select 1, (getPos _spawloc select 2) + _spawhei], random 360, _uavType, _grp] call BIS_fnc_spawnVehicle;
//_uavMod synchronizeObjectsAdd [_units,(_vec_array select 0)];
hint "UAV has been Launched";

exit

I've tried setting the behaviour of the vehicle, the group, etc.. nothing works. With BIS_fnc_spawnVehicle is there a way to set the vehicle's init? I've tried setvehicleinit, but when I do that, the synchronizeObjectsAdd does not work.

Share this post


Link to post
Share on other sites

Well I've done more reading, more searching, took apart the UAV module built into the game. Found out a few things...

Here's what how I add the UAV to a map.

In editor, drag the UAV module onto the map

Name it BIS_uav_1(or whatever, and change accordingly)

in the init of the UAV module:BIS_uav_1 setvariable ["name","RQ-1 Predator"];BIS_uav_1 setvariable ["rules",[west]]

add any unmanned vehicle/buildings and sync them to the UAV module, don't do any UAV's

Add an action to each vehicle you want to be able to "Launch" a UAV from, Doesn't have to be one that you've synced. or even one that you want to control the UAV from

nul = this addAction ["Launch UAV", "uav.sqf",[xvec1,100,BIS_uav_1,"xvec2,xvec1",MQ9PredatorB,west],0,false]

Take note of the use of quotes. string/object/side through me for a loop.

xvec1 - The name of the Launch vehicle

100 - height you want the UAV to start from above launch vehicle

BIS_uav_1 - name of the UAV module

"xvec1,xvec2" - list of objects you want UAV to be synced to notice the quotes/commas

MQ9PredatorB - Name of the UAV you want to use. Other is Pchela1T but init would have to be changed to remove added weapons. :)

west - side you want the UAV to spawn on.

uav.sqf:

/*  
=========================================================
  Default values of all settings are:
nul = this addAction ["Launch UAV", "uav.sqf",[xvec1,100,BIS_uav_1,"xvec2,xvec1",MQ9PredatorB,west],0,false]

 1: spawn location
 2: spawn height
 3: Name of UAV Module added to map - BIS_UAV 
 4: units to be syncronized with: "xvec2, xvec1, unit, etc"
 5: Version of UAV - MQ9PredatorB
 6: side - east/west. Group should work, but UAV crashes after launch.

=========================================================
*/
private ["_vec_array","_myarray"];
_myarray = _this select 3;
_spawloc = _myarray select 0;
_spawhei = if (count _myarray > 1) then {_myarray select 1} else {100};
uavMod = if (count _myarray > 2) then {_myarray select 2} else {BIS_UAV_1};
_units = if (count _myarray > 3) then {_myarray select 3} else {xvec1, xvec2};
_uavType = if (count _myarray > 4) then {_myarray select 4} else {MQ9PredatorB};
_grp = if (count _myarray > 5) then {_myarray select 5} else {"west"};

_vec_array = [[getPos _spawloc select 0, getPos _spawloc select 1, (getPos _spawloc select 2) +_spawhei], random 360, _uavType, _grp] call BIS_fnc_spawnVehicle;

MyUAV = _vec_array select 0;

MyUAV setVehicleInit "this addWeapon ""SidewinderLaucher""; this addMagazine ""4Rnd_Sidewinder_AV8B"";this disableAI ""AUTOTARGET"" ; this disableAI ""TARGET"" ; this setCombatMode ""BLUE"";this setBehaviour ""careless"";uavMod synchronizeObjectsAdd [xvec2, xvec1, MyUAV]";
publicVariable "MyUAV";  
processInitCommands;
//[assignedGunner MyUAV] join player; //still seems to crash after 2 launches..

//hint format ["%1",assignedGunner _myuav];
hint "UAV has been Launched";

exit

Now, some guru's please take a look.. I'm feeling a little lonely here. any suggestions on cleaning up the script, help in MP play? anything.. thanks.

Edited by Big_Daddy

Share this post


Link to post
Share on other sites

Been waiting for this for a while, i'll upload it to a dedi server and give it a whirl....thanks big daddy :yay:

Share this post


Link to post
Share on other sites

Does anyone have any ideas of how to make the UAV have a constant respawn rate?

Instead of just 2?

Share this post


Link to post
Share on other sites

It has something to do with running it local. When I put it on a dedicated server, there isn't a respawn limit. I dunno...

Share this post


Link to post
Share on other sites

I tried the same code except I used hellfire missiles, and it keeps saying...

"UAV DESTROYED"

Does it if I play on local or on the internet, any ideas??

Edited by Solarghost

Share this post


Link to post
Share on other sites
It has something to do with running it local. When I put it on a dedicated server, there isn't a respawn limit. I dunno...

Hey man, can you please check the code to make sure there are no errors???

It's not wroking,

Cheers bro

Share this post


Link to post
Share on other sites

Testing now... will let you know

---------- Post added at 07:30 PM ---------- Previous post was at 07:19 PM ----------

You need to fix it haha, =P

(talking to you on TS), raaawrrrrrrrrrr do it now! lol :yay: :yay:

---------- Post added at 08:14 PM ---------- Previous post was at 07:30 PM ----------

Nice work man, it works, but now you just need to add the lazertargeter with a battery and hellfires

And for the gunner to be able to click on the map so he can set the flight path, like you can as if the USMC NPC was flying in that Youtube vid...

Share this post


Link to post
Share on other sites

Any update on this? I would love to get this working properly but would hate to reinvent the wheel.

Share this post


Link to post
Share on other sites
Anyupdate? It works flawlessly..

Can you tell me what works flawlessly? Is it your script Big_Daddy, or the script within the example provided by Rommel? Rommels script doesn't allow camera manipulation, and your script simply doesn't work.

As posted by SolarGhost and never replied to, when running your scripts it says "UAV Destroyed" after choosing Launch UAV and attempting to control it. I noticed that "uavMod = if" should be "_uavMod = if" at the very least. Could you compare your finished work against your post? It's not working flawlessly.

---------- Post added at 10:24 PM ---------- Previous post was at 09:24 PM ----------

Is anyone able to correct this code.. or does someone know a better solution?

/*  
=========================================================
  Default values of all settings are:
nul = this addAction ["Launch UAV", "uav.sqf",[xvec1,100,BIS_uav_1,"xvec2,xvec1",MQ9PredatorB,west],0,false]

 1: spawn location
 2: spawn height
 3: Name of UAV Module added to map - BIS_UAV 
 4: units to be syncronized with: "xvec2, xvec1, unit, etc"
 5: Version of UAV - MQ9PredatorB
 6: side - east/west. Group should work, but UAV crashes after launch.

=========================================================
*/
private ["_vec_array","_myarray"];
_myarray = _this select 3;
_spawloc = _myarray select 0;
_spawhei = if (count _myarray > 1) then {_myarray select 1} else {100};
uavMod = if (count _myarray > 2) then {_myarray select 2} else {BIS_UAV_1};
_units = if (count _myarray > 3) then {_myarray select 3} else {xvec1, xvec2};
_uavType = if (count _myarray > 4) then {_myarray select 4} else {MQ9PredatorB};
_grp = if (count _myarray > 5) then {_myarray select 5} else {"west"};

_vec_array = [[getPos _spawloc select 0, getPos _spawloc select 1, (getPos _spawloc select 2) +_spawhei], random 360, _uavType, _grp] call BIS_fnc_spawnVehicle;

MyUAV = _vec_array select 0;

MyUAV setVehicleInit "this addWeapon ""SidewinderLaucher""; this addMagazine ""4Rnd_Sidewinder_AV8B"";this disableAI ""AUTOTARGET"" ; this disableAI ""TARGET"" ; this setCombatMode ""BLUE"";this setBehaviour ""careless"";uavMod synchronizeObjectsAdd [xvec2, xvec1, MyUAV]";
publicVariable "MyUAV";  
processInitCommands;
//[assignedGunner MyUAV] join player; //still seems to crash after 2 launches..

//hint format ["%1",assignedGunner _myuav];
hint "UAV has been Launched";

exit

Edited by StrongHarm
put in code tags rather than quote

Share this post


Link to post
Share on other sites

Latest version of UAV script.

/*  
=========================================================
  Default values of all settings are:
nul = this addAction ["Launch UAV", "uav.sqf",[xvec1,100,BIS_uav_1,"xvec2,xvec1",MQ9PredatorB,west],0,false]

 1: spawn vehicle/building
 2: spawn height
 3: Name of UAV Module - ie BIS_UAV 
 4: units to be syncronized with Names, "xvec2, xvec1"
 5: Version of UAV - MQ9PredatorB
 6: side/group

=========================================================
*/


private ["_vec_array","_myarray"];
_myarray = _this select 3;
_spawloc = _myarray select 0;
_spawhei = if (count _myarray > 1) then {_myarray select 1} else {100};
_uavMod = if (count _myarray > 2) then {_myarray select 2} else {BIS_UAV_1};
_units = if (count _myarray > 3) then {_myarray select 3} else {xvec1, xvec2};
_uavType = if (count _myarray > 4) then {_myarray select 4} else {MQ9PredatorB};
_grp = if (count _myarray > 5) then {_myarray select 5} else {"west"};

_vclname="MyUAV";

_vec_array = [[getPos _spawloc select 0, getPos _spawloc select 1, (getPos _spawloc select 2) +_spawhei], random 360, _uavType, _grp] call BIS_fnc_spawnVehicle;
_vcl = _vec_array select 0;
_vcl SetVehicleVarName _vclname;
_vcl Call Compile Format ["%1=_vcl;PublicVariable ""%1"";",_vclname];
_initCmd=format["this addMagazine ""4Rnd_Sidewinder_AV8B"";this addWeapon ""SidewinderLaucher""; this disableAI ""AUTOTARGET"" ; this disableAI ""TARGET"" ; this setCombatMode ""BLUE"";this setBehaviour ""careless"";%1 synchronizeObjectsAdd [%2,%3];",_uavmod,_vcl,_units];
_vcl setVehicleInit _initCmd;


processInitCommands;
clearVehicleInit _vcl;


Player sideChat "UAV has been Launched";

Share this post


Link to post
Share on other sites

Big_Daddy.. would you mind providing a mission with this script working? I've had no joy under any circumstance. The idea is a very good one.. it just doesn't seem to work.

Share this post


Link to post
Share on other sites

Okay, I used a previous version of the script and got the UAV to spawn correctly. Now for a question. Has anyone managed to get the UAV to take the disableai commands that follow. My pilot still wants to go Top Gun on everything and I can't get it to stay in an orbit. He still calls out targets and then puts his nose to the ground and starts doing fly-by's. Tried several different ways and haven't been able to the UAV to take them.

Share this post


Link to post
Share on other sites

That worked! Here's the updated code for anyone who needs it. Big_Daddy.. I took the liberty of adding the deletevehicle line to delete the old uav (so you don't have someone spam the sky with UAVs) and the line to show who spawned it and where. It would be really nice if it locked the UAV out and told the person who was currently using it. As it stands, if I'm using the uav, you can walk up and spawn a new one and cut me off... but it does say in chat who did it.

/*  
=========================================================
  Default values of all settings are:
nul = this addAction ["Launch UAV", "UAV\launchuav.sqf",[uavstation,200,UAVmod,"hmmwv1,uavstation","MQ9PredatorB",west],0,false];

 1: spawn location
 2: spawn height
 3: Name of UAV Module - BIS_UAV 
 4: units to be syncronized with Names, xvec2, xvec1, (_vec_array select 0)
 5: Version of UAV - MQ9PredatorB
 6: side/group

=========================================================
*/
{ deleteVehicle _x } forEach (crew MyUAV); deleteVehicle MyUAV;


private ["_vec_array","_myarray"];
_myarray = _this select 3;
_spawloc = _myarray select 0;
_spawhei = if (count _myarray > 1) then {_myarray select 1} else {100};
_uavMod = if (count _myarray > 2) then {_myarray select 2} else {BIS_UAV_1};
_units = if (count _myarray > 3) then {_myarray select 3} else {xvec1, xvec2};
_uavType = if (count _myarray > 4) then {_myarray select 4} else {MQ9PredatorB};
_grp = if (count _myarray > 5) then {_myarray select 5} else {"west"};

_vclname="MyUAV";

_vec_array = [[getPos _spawloc select 0, getPos _spawloc select 1, (getPos _spawloc select 2) +_spawhei], random 360, _uavType, _grp] call BIS_fnc_spawnVehicle;
_vcl = _vec_array select 0;
_vcl SetVehicleVarName _vclname;
_vcl Call Compile Format ["%1=_vcl;PublicVariable ""%1"";",_vclname];
_initCmd=format["this addMagazine ""4Rnd_Sidewinder_AV8B"";this addWeapon ""SidewinderLaucher""; this disableAI ""AUTOTARGET"" ; this disableAI ""TARGET"" ; this setCombatMode ""BLUE"";this setBehaviour ""careless"";%1 synchronizeObjectsAdd [%2,%3];",_uavmod,_vcl,_units];
_vcl setVehicleInit _initCmd;

processInitCommands;
clearVehicleInit _vcl;

Player sideChat format ["UAV launched from %1 by %2", _spawloc, player];

Share this post


Link to post
Share on other sites

Worked for me as well.

One issue, it doesn't seem to work on a dedicated server. I does work fine for me in a user created MP game if I host, but not from a dedicated box with clients connecting. I tried messing around a little with it, but it won't seem to sync up with the player. Launches fine..then does it's own thing until it runs out of gas or gets shot down.

Share this post


Link to post
Share on other sites

See, that's weird. Cause thats all we play on is a dedicated server. And we've never had issues with the UAV. Now understand that if someone comes in after you've launched the UAV, they cannot control that UAV. But they should be able to control the next one that is launched.

Did you notice the init of the UAV module? that's important as well. Everyone on west has access. If you don't have that, then yes, you'd not be able to control the UAV. (UAV has been destroyed)

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  

×