Jump to content
Sign in to follow this  
cobra4v320

Need assistance with Close Air Support Script

Recommended Posts

The script below randomly spawns in a West aircraft and it is set to do a BIS_Fnc_taskpatrol, if the vehicle is damaged or destroyed it is supposed to delete the vehicle and crew and start the script over by radio command.

The problem Ive been having with the script is the if then command it gives me the "type array expected object" error.

Here is the script:

waituntil {!isnil "bis_fnc_init"};

_westAircraft = ["AH64D_EP1","AH1Z","UH60M_EP1"];

_man		= player;
_pos 		= [(getmarkerpos "aircraftspawn" select 0), (getmarkerpos "aircraftspawn" select 1), 50];
_spwndir	= random 360;
_WestHQ 	= createCenter West;
_Grp		= createGroup West;

if (casActive) exitWith {hint "Close Air Support is unavailable!"};

casActive = true;

_veh = [_pos, _spwndir, _westAircraft select floor (random count _westAircraft), _Grp] call BIS_fnc_spawnVehicle;
_type = _veh select 0;

[_Grp, (getpos _man), 1000] call BIS_fnc_taskPatrol;

hint format ["There is a %1 enrounte to your location, over.", typeof _type];

_checkcas = 0;
while {(_checkcas == 0)} do {
if (!alive _veh) then {_checkcas = 1};
if ((fuel _veh) < 0.2) then {_checkcas = 1};
if !(isengineon _veh) then {_checkcas = 1};
};

_veh setdammage 1;

[_veh] call BIS_GC_trashItFunc;
{[_x] call BIS_GC_trashItFunc} foreach units _veh;

sleep 30;
casActive = false;
hint "Close Air Support is available!";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

File: spawnVehicle.sqf

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

You are trying to give all that to the garbage collector, when it only wants the object.

Share this post


Link to post
Share on other sites

The script below works perfectly but it does not use the "BIS_fnc_spawnVehicle" like I want it to. Could that be the problem?

waituntil {!isnil "bis_fnc_init"};

_westAircraft = ["AH64D_EP1","AH1Z"];

_man = player;
_pos = getmarkerpos "aircraftspawn";
_spwndir = random 360;
_WestHQ = createCenter West;
_Grp = CreateGroup West;

if (casActive) exitWith {hint "Close Air Support is unavailable!"};

casActive = true;

_veh =  createVehicle [_westAircraft select floor (random count _westAircraft), _pos, [], 0, "FLY"];

_Pilot1 = _Grp createUnit ["US_Soldier_Pilot_EP1", getpos _veh, [], 0, "FORM"];
_pilot1 moveInDriver _veh;
_Pilot1G = _Grp createUnit ["US_Soldier_Pilot_EP1", getpos _veh, [], 0, "FORM"];
_pilot1G moveInGunner _veh;
_veh setdir _spwndir;

[_Grp, (getpos _man), 1000] call BIS_fnc_taskPatrol;

hint format ["There is a %1 enrounte to your location, over.", typeof _veh];

[color="Red"]_checkcas = 0;

while{(_checkcas == 0)} do {
if (!alive _veh) then {_checkcas = 1};
if ((getDammage _veh > 0.8) and ({alive _x} count crew _veh == 0)) then {_checkcas = 1};
};[/color]

_veh setdammage 1;

sleep (30 + random 10);

deleteVehicle _veh;

casActive = false;
publicVariable "casActive";

hint "Close Air Support is available!";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Like I said, you were trying to pass an array when the script wanted an object.

You do:

_veh = [...] call BIS_fnc_spawnVehicle;

Then you do:

[_veh] call BIS_GC_trashItFunc;

_veh at that point contains: [object,crew,group]

So, instead of doing:

[_veh] call BIS_GC_trashItFunc;

do:

[(_veh select 0)] call BIS_GC_trashItFunc;

PS. You are also checking for alive/engine/fuel of an array instead of the actual plane.

Edited by Shuko

Share this post


Link to post
Share on other sites

Thank you shk you are correct with the array instead of object, Im going to use the excuse that I was tired! ;)

It looks like if I change whats in red to _type then it works fine.

waituntil {!isnil "bis_fnc_init"};

_westAircraft = ["AH64D_EP1","AH1Z","UH60M_EP1","A10_US_EP1","AV8B2","F35B","UH1Y"];

_man		= player;
_pos 		= [(getmarkerpos "aircraftspawn" select 0), (getmarkerpos "aircraftspawn" select 1), 50];
_spwndir	= random 360;
_WestHQ 	= createCenter West;
_Grp		= createGroup West;

if (casActive) exitWith {hint "Close Air Support is unavailable!"};

casActive = true;

_veh = [_pos, _spwndir, _westAircraft select floor (random count _westAircraft), _Grp] call BIS_fnc_spawnVehicle;
_type = _veh select 0;

[_Grp, (getpos _man), 1000] call BIS_fnc_taskPatrol;

hint format ["There is a %1 enrounte to your location, over.", typeof _type];


_checkcas = 0;

while{(_checkcas == 0)} do {
if (!alive [color="Red"]_type[/color]) then {_checkcas = 1};
if ((getDammage [color="red"]_type [/color]> 0.8) and ({alive _x} count crew[color="red"] _type [/color]== 0)) then {_checkcas = 1};
};


[color="red"]_type[/color] setdammage 1;

hint "Close air support has been destroyed!";

sleep (120 + random 60);

deleteVehicle [color="red"]_type[/color];

casActive = false;
publicVariable "casActive";

hint "Close Air Support is available!";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

The only other problem that Im having is deleting the crew. I tried

{deleteVehicle _X} forEach (crew _type)+[_type]

which deletes the vehicle but not the crew, Im guessing because the spawn is done dynamically or because the crew isnt a variable? During testing when I shoot the heli down the crew gets out and continues the BIS_fnc_taskpatrol. Also if anyone has any other ideas on how to make the script better let me know. I know there are probably a 100 other CAS scripts out there which I have seen but I wont learn how to script if I just use everyone elses hard work. :p

Edited by cobra4v320

Share this post


Link to post
Share on other sites
{deleteVehicle _x} forEach crew _type; deleteVehicle _type;

has always worked for me.

Share this post


Link to post
Share on other sites

Cant u put in a (_veh select 1) to delete the crew ???

Share this post


Link to post
Share on other sites

{deleteVehicle _x} forEach crew _type; deleteVehicle _type;

That does work just make sure you don't have an extra

deleteVehicle _type

before that line of code or it won't work.

Share this post


Link to post
Share on other sites

Sorry boss, it still does not work heli explodes, bodies fly, heli deletes, crew stays. There is no other deletevehicle besides the one at the bottom of the script. I also tried the Garbage collector method and it too only deletes the vehicle and not the crew. Possibly a bug?

Share this post


Link to post
Share on other sites

I think I see what your doing, you need to delete the crew before the aircraft gets destroyed.

{deleteVehicle _x} forEach crew _type;
_type setdammage 1;
deleteVehicle _type;

That's if you need to destroy it.

update.

Kind of odd but I only had the crew fail to delete once and thought doing it the above way fixed that, however I've repeated it the previous way many times now and never had the crew fail to delete again.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Nope tested several times and it still doesnt work :D Really strange. Perhaps when the crew gets out they are unassigned from the vehicle which breaks the link between _type and crew?

Edited by cobra4v320

Share this post


Link to post
Share on other sites

I have the same problem deleting units with the BIS_fnc_spawnGroup. So on this script only the unit leader gets deleted all of the rest of the units stay in place.

waituntil {!isnil "bis_fnc_init"};

_group1 	= CreateGroup West;
_pos		= getmarkerpos "SpawnPoint";
_man		= player;
_WestSquad	= ["US_DeltaForceTeam","US_WeaponsSquad","US_RifleSquad","US_Team"];
_getpos		= getpos player;	

_group1 = [_pos, side _man, (configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> _westSquad select (random count _westSquad))] call BIS_fnc_spawnGroup; 

[_group1, _getpos, 300] call BIS_fnc_taskpatrol;


_checkinf = 0;

while {(_checkinf == 0)} do {

if ({alive _x} count units _group1 == 0) then {_checkinf = 1};
};

sleep 30;

{deletevehicle _x} foreach units _group1; deleteGroup _group1;

infActive = false;

publicVariable "infActive";

hint "Infantry support is available!";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Okay here is my WORKING Close Air Support script and I added some visual touches to it and I finally figured out how to delete the vehicle and the crew. Not sure if this is MP compatible and if anyone has any ideas let me know. Moving on to my airborne support script.

You need to place a Functions Module on the map.

null = [] execVM "air_support.sqf"

waituntil {!isnil "bis_fnc_init"};

_pos 		= [(getmarkerpos "SpawnPoint" select 0), (getmarkerpos "SpawnPoint" select 1), 50];
_dir 		= random 360;
_westAircraft 	= ["AH64D_EP1","AH1Z","UH60M_EP1","A10_US_EP1","AV8B2","F35B","UH1Y"];
_unit		= player;
_group		= createGroup West;

if (casActive) exitWith {hint "Close Air Support is unavailable!"};

casActive = true;


_veh = [_pos, _dir, _westAircraft select (random count _westAircraft), _group] call BIS_fnc_spawnVehicle;

_veh = _veh select 0;

_picture = getText (configFile >> "cfgVehicles" >> typeOf _veh >> "picture");

hint parseText format["There is a %1<br/>close air support <br/>enroute to your location.<br/><img size='4' image='%2'/>",typeof _veh, _picture];


[_group, (getpos _unit), 800] call BIS_fnc_taskPatrol;


_checkcas = 0;

while{(_checkcas == 0)} do {
if (!alive _veh) then {_checkcas = 1};
if (getDammage _veh > 0.8) then {_checkcas = 1};
if ((fuel _veh) < 0.2 ) then {_checkcas = 1};
	if !(isengineon _veh) then {_checkcas = 1};
};


hint format ["The %1 has been destroyed!", typeof _veh];

sleep (60 + random 60);

_unitsInGroupAdd = [];
_unitsInGroup = units _group;
{deleteVehicle _x} forEach _unitsInGroup;

deletevehicle _veh;

casActive = false;

publicVariable "casActive";

hint "Close Air Support is available.";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

You may want to swap this:

while{(_checkcas == 0)} do {
if (!alive _veh) then {_checkcas = 1};
if (getDammage _veh > 0.8) then {_checkcas = 1};
if ((fuel _veh) < 0.2 ) then {_checkcas = 1};
	if !(isengineon _veh) then {_checkcas = 1};
};

With this:

waitUntil
{
	_checkcas=0;
if (!alive _veh) then {_checkcas = 1};
if (getDammage _veh > 0.8) then {_checkcas = 1};
if ((fuel _veh) < 0.2 ) then {_checkcas = 1};
	if !(isengineon _veh) then {_checkcas = 1};
	_checkcas
};

For MP compatibility, make sure the script runs on the server, and only on the server. That means that whatever is running on the client that should make this script execute should not directly execute the script, but rather publicVariable something that the server will then use to initiate the script.

Another thing is I'm not sure if the group stays well-defined when group members start dying. If you want to be 100% sure you are reliably deleting the crew, you may want to do _units = units _group; at an earlier phase (right after spawning them), and then delete _units instead of units _group. That way even if dead units are no longer considered to be a part of the group, they will still be in the _units array (as that was defined before they were removed from group) which means they will get deleted safely with no chance of glitches.

Edited by galzohar

Share this post


Link to post
Share on other sites

galzohar

I get an: error type, number expected bool when using

waitUntil
{
	_checkcas=0;
if (!alive _veh) then {_checkcas = 1};
if (getDammage _veh > 0.8) then {_checkcas = 1};
if ((fuel _veh) < 0.2 ) then {_checkcas = 1};
	if !(isengineon _veh) then {_checkcas = 1};
	_checkcas
};

You are also correct, it will delete the vehicle and any alive group members but dead bodies stay. What you posted above does not work, I have not tested it enough yet though.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Replace 0 with false and replace 1 with true, then, should work.

Share this post


Link to post
Share on other sites

Thanks both of your tips worked galzohar. I also added a distance check to delete the vehicle and group only when the player is 200 meters away.

Here is the updated script again for anyone interested.

waituntil {!isnil "bis_fnc_init"};

_pos 		= [(getmarkerpos "SpawnPoint" select 0), (getmarkerpos "SpawnPoint" select 1), 50];
_dir 		= random 360;
_westAircraft 	= ["AH64D_EP1","AH1Z","UH60M_EP1","A10_US_EP1","AV8B2","F35B","UH1Y"];
_unit		= player;
_group		= createGroup West;

if (casActive) exitWith {hint "Close Air Support is unavailable!"};

casActive = true;


_veh = [_pos, _dir, _westAircraft select (random count _westAircraft), _group] call BIS_fnc_spawnVehicle;

_veh = _veh select 0;

_units = units _group;

_picture = getText (configFile >> "cfgVehicles" >> typeOf _veh >> "picture");

hint parseText format["There is a %1<br/>close air support <br/>enroute to your location.<br/><img size='4' image='%2'/>",typeof _veh, _picture];


[_group, (getpos _unit), 800] call BIS_fnc_taskPatrol;

waitUntil
{
	_checkcas = FALSE;
if (!alive _veh) then {_checkcas = TRUE};
if (getDammage _veh > 0.8) then {_checkcas = TRUE};
if ((fuel _veh) < 0.2 ) then {_checkcas = TRUE};
	if !(isengineon _veh) then {_checkcas = TRUE};
	_checkcas
};


hint format ["The %1 has been destroyed!", typeof _veh];

sleep (60 + random 60);

waitUntil
{
_checkcas = FALSE;
if ((_unit distance _veh) >= 200) then {_checkcas = TRUE};
_checkcas
};



{deleteVehicle _x} forEach (_units)+[_veh];

casActive = false;

publicVariable "casActive";

hint "Close Air Support is available."

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Thank you Galzohar, also the publicvariable does it matter where it is at in the script?

Share this post


Link to post
Share on other sites

You call pubvar when you have changed value of a variable and want to tell about that change to everyone else.

Share this post


Link to post
Share on other sites

So if I put casActive true in the init.sqf and then put publicvariable at the beginning of the support script it should work?

Share this post


Link to post
Share on other sites

If you want to be sure that a certain variable is the same on all machines, publicVariable it every time you change it, and to avoid trouble/confusion, only change/update it on the server. You don't want any client JIPing resetting it to true, but rather get the value from the server.

Share this post


Link to post
Share on other sites

I have another issue with deletevehicle, the script below spawns in a random transport vehicle and random airborne groups, drops them off at the players location, the airborne units do a bis_fnc_taskpatrol and the transport flys to its last waypoint. However the transport at the last waypoint does not delete, I have tried a bunch of different ways to delete it and its driving me crazy. Im using a setwaypointstatement marked in red and it is not working.

nul = [] execVM "inf_support.sqf"

waituntil {!isnil "bis_fnc_init"};

if (infActive) exitWith {hint "Airborne Infantry Support is unavailable!"};
infActive = true;


_unit		= player;
_pos 		= [(getmarkerpos "SpawnPoint" select 0), (getmarkerpos "SpawnPoint" select 1), 350];
_spwndir	= getdir _unit;

_WestSquad	= ["US_DeltaForceTeam","US_WeaponsSquad","US_RifleSquad","US_Team"];
_squadType 	= _westSquad select (random count _westSquad);
_westVehicle	= ["C130J_US_EP1","MV22","UH60M_EP1","CH_47F_EP1"];
_airgrp 	= CreateGroup West;
_infgrp		= CreateGroup West;


_veh = createVehicle [_westvehicle select (random count _westvehicle), _pos, [], 0, "FLY"];
_Pilot = _airgrp createUnit ["US_Soldier_Pilot_EP1", (getpos _veh), [], 0, "NONE"];
_pilot moveInDriver _veh;
_veh flyinheight 350;


_wp1 = _airgrp addwaypoint [position _unit, 0];
_wp1 setwaypointtype "MOVE";
_wp1 setWaypointSpeed "NORMAL";
_wp1 setWaypointBehaviour "CARELESS";
_wp1 setWaypointCombatMode "BLUE";


_infgrp = [(getpos _veh), side _unit, (configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> _westSquad select (random count _westSquad))] call BIS_fnc_spawnGroup;
{_x moveincargo _veh} foreach units _infgrp;
_units = units _infgrp;

hint format ["There is a %1 enroute with an Airborne %2!", typeof _veh, _squadtype];


waitUntil
{
_unit distance _veh <= 420
};

{unassignVehicle (_x);(_x) action ["EJECT", vehicle _x];sleep 0.4} foreach units _infgrp;
{_x spawn {_this allowdamage false; waituntil {(getpos _this) select 2 < 3};_this allowdamage true}} foreach units _infgrp;
[_infgrp, (getpos _unit), 300] call BIS_fnc_taskPatrol;


_wp2 = _airgrp addwaypoint [getmarkerpos "spawnpoint", 0];
_wp2 setwaypointtype "MOVE";
_wp2 setWaypointSpeed "FULL";
_wp2 setWaypointBehaviour "CARELESS";
[color="Red"]_wp2 setWaypointStatements ["TRUE", "{deleteVehicle _x} foreach (crew _veh)+[_veh]"];[/color]


waitUntil
{
{alive _x} count _units == 0

};

hint format ["All the %1 units have been killed!",_squadtype];

sleep (60 + random 60);

{deletevehicle _x} foreach _units;

infActive = false;

publicVariable "infActive";

hint "Airborne Infantry support is available!"

Edited by cobra4v320

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  

×