Jump to content
Sign in to follow this  
thebarricade

Yet another airdrop script

Recommended Posts

Yep, I'm throwing my hat into the ring with yet another airdrop script. :cool:

Script and example-mission.

The script (tbr_airdrop.sqf):

/*
Simple airdrop with script-support

Version: 1.1

Thanks to Desrat for fixing "unresponsive" drops.

params: 
	caller,			// calling unit (object)
	vehicle,		// class of airplane doing the drop (string)
	approachFrom,	// approach vector (0-359) (-1 for random approach) (numeric)
	flyHeight,		// aircraft altitude (numeric)
	dropAt,			// starting drop position (multiple packages will be dropped at intervals) (position)
	interval,		// interval in seconds between drops (numeric)
	scripts,		// [ "ingress-script", "approach-script", "egress-script"]						
	items-array		// [
						[ "parachuteclass", "droppeditemclass", "script-to-run-on-item-drop", "script-to-run-on-item-after-touch-down" ], 
						[ "parachuteclass", "droppeditemclass", "script-to-run-on-item-drop", "script-to-run-on-item-after-touch-down" ]
					   ]
						(array)

parachuteclasses:
	ParachuteMediumWest
	ParachuteMediumEast
	ParachuteBigWest
	ParachuteBigEast

ingress-script:
	gets called with two parameters: caller (object), drop-vehicle (object)

approach-script:
	gets called with two parameters: caller (object), drop-vehicle (object)

egress-script:
	gets called with two parameters: caller (object), drop-vehicle (object)

script-to-run-on-item-drop:
	gets called with three parameters: caller (object), drop-vehicle (object), package (object)

script-to-run-on-item-after-touch-down:
	gets called with two parameters: caller (object), package (object)

example:
	_n = [player, "c130j", 270, 200, getMarkerPos "mk_drop", 3, ["tbr_airdrop\ingress.sqf","tbr_airdrop\approach.sqf","tbr_airdrop\egress.sqf"], [["ParachuteMediumWest","USBasicAmmunitionBox_EP1","tbr_airdrop\announce.sqf",""],["ParachuteBigWest","HMMWV_M1035_DES_EP1","tbr_airdrop\announce.sqf","tbr_airdrop\explode.sqf"]]] execVM "tbr_airdrop\tbr_airdrop.sqf";

	uses a c130 to drop a ammo-box and a hmmwv (which blows up on touchdown thanks to a called script), both drops announced by the c130 (via script)
*/

private ["_approachFrom", "_interval", "_calc_point", "_caller", "_vehicleClass", "_dropAt", "_packages", "_flyHeight", "_dir", "_spawn_distance", "_spawn_pos", "_exit_pos", "_side", "_grp", "_vehicle", "_pilot", "_wp_drop", "_wp_exit"];

if( TBR_support_in_progress ) exitWith{ hint "Support already in progress"; };

_calc_point = {
private ["_position", "_direction", "_distance", "_point", "_pos_x", "_pos_y", "_pos_z", "_off_x", "_off_y"];

_position			= _this select 0;
_direction			= _this select 1;
_distance			= _this select 2;

// ------------------------------------------------------

_point				= [0,0,0];

_pos_x 				= _position select 0;
_pos_y 				= _position select 1;
_pos_z				= _position select 2;

_off_x	= sin(_direction) * _distance;
_off_y	= cos(_direction) * _distance;

_point	= [_pos_x + _off_x, _pos_y + _off_y, _pos_z];
_point;
};

_caller			= _this select 0;
_vehicleClass	= _this select 1;
_approachFrom 	= _this select 2;
_flyHeight		= _this select 3;
_dropAt 		= _this select 4;
_interval 		= _this select 5;
_scripts		= _this select 6;
_packages 		= _this select 7;

if( _approachFrom == -1 ) then {
_approachFrom = round(random 360);
} else {
// randomize the approach angle somewhat
_approachFrom	= (_approachFrom + (5 - round(random 10)));
};

// set dropinterval if zero (2-5 seconds)
if( _interval == 0 ) then { _interval = 2 + round(random 3); };

_dir = _approachFrom - 180;

_spawn_distance = viewDistance + 100;
_spawn_pos = [_dropAt, _approachFrom, _spawn_distance] call _calc_point;
_exit_pos = [_dropAt, _dir + (45 - round(random 90)), _spawn_distance] call _calc_point;

_side = side _caller;

_grp = createGroup _side;

TBR_support_in_progress = true;
TBR_drop_here = false;

publicVariable "TBR_support_in_progress";

_vehicle = createVehicle [_vehicleClass, [_spawn_pos select 0, _spawn_pos select 1, (_spawn_pos select 2) + _flyHeight], [], 0, "FLY"];
_vehicle setDir _dir;
_vehicle setVelocity [sin(_dir)*55,cos(_dir)*55,0]; // roughly 200kph

_pilot = _grp createUnit ["USMC_Soldier_Pilot", [0,0,0], [], 0, "FORM"];
_pilot assignAsDriver _vehicle;
_pilot moveInDriver _vehicle;
_vehicle flyInHeight _flyHeight;

// calling ingress-script
if( (_scripts select 0) != "" ) then { [_caller, _vehicle] execVM (_scripts select 0); };

// setup waypoints
_wp_drop = _grp addWaypoint [_dropAt, 50];
_wp_drop setWaypointType "MOVE";
_wp_drop setWaypointSpeed "LIMITED";
_wp_drop setWaypointStatements ["true", "TBR_drop_here = true;"];

_wp_exit = _grp addWaypoint [_exit_pos, 200];
_wp_exit setWaypointType "MOVE";
_wp_exit setWaypointSpeed "FULL";
_wp_exit setWaypointStatements ["true", "TBR_support_in_progress = false;"];

// monitoring approach
if( (_scripts select 1) != "" ) then {
[_caller, _vehicle, _dropAt, (_scripts select 1)] spawn {
	private ["_caller", "_dropper", "_droppt", "_script"];

	_caller = _this select 0;
	_dropper = _this select 1;
	_droppt = _this select 2;
	_script = _this select 3;

	waitUntil{ ((getPos _dropper) distance _droppt) < 700  };

	// running approach-script
	[_caller, _dropper] execVM _script;
};
};

waitUntil{ TBR_drop_here or !(alive _vehicle) };

if( !(alive _vehicle) ) exitWith{ TBR_support_in_progress = false; publicVariable "TBR_support_in_progress"; };

{
[_vehicle, _x select 0, _x select 1, _x select 2, _x select 3, _caller] spawn {
	private ["_chute", "_smoke", "_touchDownPos", "_vel", "_dropper", "_chuteType", "_package", "_scriptAfter", "_scriptBefore", "_chutePos", "_drop", "_caller"];

	_dropper = _this select 0;
	_chuteType = _this select 1;
	_package = _this select 2;
	_scriptBefore = _this select 3;
	_scriptAfter = _this select 4;
	_caller = _this select 5;

	_chutePos = [(getpos _dropper select 0), (getPos _dropper select 1)-10, (getPos _dropper select 2)-10];

	// create the dropped object
	_drop = _package createVehicle _chutePos;
	_touchDownPos = [];

	if( _scriptBefore != "" ) then { [_caller, _dropper, _drop] execVM _scriptBefore; };

	if( _chuteType != "" ) then {
		// using parachute
		_chute = _chuteType createVehicle _chutePos; 
		_chute setPos _chutePos;

		_drop setpos _chutePos;
		_drop attachto [_chute, [0, 0, 0]];

		// add green smoke while dropping
		_smoke = "SmokeShellgreen" createVehicle _chutePos;
		_smoke attachto [_drop, [0, 0, 0]];

		waitUntil {((getPos _drop) select 2) < 1};

		detach _drop;
		detach _smoke;
		deleteVehicle _smoke;

		_touchDownPos = getPos _drop;
	} else {
		// no paracute, so it's freefalling
		_vel = velocity _dropper;

		// create a smokegrenade and use that as the "anchor" since it's affected by gravity
		_smoke = "SmokeShellgreen" createVehicle _chutePos;
		_drop attachto [_smoke, [0, 0, 0]];

		// set velocity vector to that of the plane, so the object falls somewhat realistically...
		_smoke setVelocity _vel;

		waitUntil {((getPos _smoke) select 2) < 1};

		_touchDownPos = getPos _smoke;

		detach _drop;
		deleteVehicle _smoke;
	};

	deleteVehicle _drop;
	_drop = _package createVehicle [(_touchDownPos select 0), (_touchDownPos select 1), 0];		

	// create a new smokesource
	"SmokeShellgreen" createVehicle [(_touchDownPos select 0), (_touchDownPos select 1), 0];			

	if( _scriptAfter != "" ) then { 
		[_caller, _drop] execVM _scriptAfter; 
	};
};

sleep _interval + (random 2);
} forEach _packages;

waitUntil{ !TBR_support_in_progress or !(alive _vehicle) };

if( !(alive _vehicle) ) exitWith{ TBR_support_in_progress = false; publicVariable "TBR_support_in_progress"; };

// running egress-script
if( (_scripts select 2) != "" ) then { [_caller, _vehicle] execVM (_scripts select 2); };

sleep 1;

// cleanup
deleteVehicle _pilot;
deleteVehicle _vehicle;
deleteGroup _grp;

TBR_support_in_progress = false;
publicVariable "TBR_support_in_progress";

Possible MP support, add to init.sqf (completely untested and will probably fail horribly):

if (isNil "TBR_support_in_progress") then {	TBR_support_in_progress = false; };
"TBR_support_in_progress" addPublicVariableEventHandler { TBR_support_in_progress = (_this select 1); };

Comments and critisism are welcome.

Edited by thebarricade

Share this post


Link to post
Share on other sites

A couple of things to check.

Did you select "Perform airdrop" in the "mousewheel"/action-menu?

The plane spawn quite a bit away (to the west, the distance roughly equals your viewdistance), so it can take a little while for the plane to appear.

Share this post


Link to post
Share on other sites

thanks for sharing

You may want to add an user notification if CBA is not loaded.

Most likely the problem of LockJaw. Or in this case better replace the one CBA function /

include a copy in your script suite. Not that meaningful to introduce an addon requirement

just for this.

Share this post


Link to post
Share on other sites

nice script but when ammo creates land i cant open them which is strange as when you go to gear the box is full you just cant take any thing out of the box am i doing anything wrong thanks m8

Share this post


Link to post
Share on other sites
nice script but when ammo creates land i cant open them which is strange as when you go to gear the box is full you just cant take any thing out of the box am i doing anything wrong thanks m8

I had same issue in my FSM support system - ended up having to delete the crate when it landed and replace with a new one - only work around I found..

Share this post


Link to post
Share on other sites

thx m8 i am new to all this not sure how to delete and add create again via script

any help would be grateful thanks again m8

Share this post


Link to post
Share on other sites

you'll either need to edit the code yourself or get the original author to do so - see if he drops in over the next few days..

Share this post


Link to post
Share on other sites

thanks again m8 ill keep checking here hopefully they will fix when they have got time

Share this post


Link to post
Share on other sites

had a quick look at it and think this should work ok - open "tbr_airdrop.sqf"

Line 209

_drop setpos [(_touchDownPos select 0), (_touchDownPos select 1), 0];

add replace with these 2 lines

deleteVehicle _drop;
_drop = _package createVehicle [(_touchDownPos select 0), (_touchDownPos select 1), 0];

Share this post


Link to post
Share on other sites

thanks very much m8 that worked great now i can open the ammo crates and get stuff out thanks again

Share this post


Link to post
Share on other sites
had a quick look at it and think this should work ok - open "tbr_airdrop.sqf"

Line 209

_drop setpos [(_touchDownPos select 0), (_touchDownPos select 1), 0];

add replace with these 2 lines

deleteVehicle _drop;
_drop = _package createVehicle [(_touchDownPos select 0), (_touchDownPos select 1), 0];

Thanks!

I have updated the script with your fix, and removed the CBA dependencies as per PvPScenes' suggestion.

Note that it is possible to use the "script to run on touchdown" to customize the load-out of any ammo/weapons-crate.

Edited by thebarricade

Share this post


Link to post
Share on other sites

"Note that it is possible to use the "script to run on touchdown" to customize the load-out of any ammo/weapons-crate. "

sorry to be a pain again but does that mean just execute a new script after box has landed ie after desrats fix i could just execute a ammo filler script thanks desrat and thebarricade for the help and a great script

Share this post


Link to post
Share on other sites
sorry to be a pain again but does that mean just execute a new script after box has landed ie after desrats fix i could just execute a ammo filler script thanks desrat and thebarricade for the help and a great script

Yes, you could do that. If you check the example mission you can see that the hummer has a script "attached" to it which causes it to blow up on landing.

Oh, and you're welcome :)

Edited by thebarricade

Share this post


Link to post
Share on other sites

thanks m8 ill take a look the current script im using to fill crates with at the moment is the universal crate filler and in my stationary ammo init boxes i got

nul = [this,"west","user",false,20,75,10] execVM "crateFiller.sqf"

would this be possible to pass this statement to the crate filler script like you said above as the above statement needs to pass variables to the crate filler script and in your script it just says

tbr_airdrop\explode.sqf

sorry to be a pain but im new to all this and i have tried all different variations to get it to work so any help again would be much appreciated thanks again m8 and like i said sorry to be a pain

Share this post


Link to post
Share on other sites

I have updated the example mission to use Tophes crate-filler script, so the hummer is replaced by another crate. Se the fillcrate.sqf script to see how it works...

Share this post


Link to post
Share on other sites

thanks worked great after seeing how you called script helped a lot i now know were i went wrong i had the _nul part and had a _caller but did not have the other one _obj i just kept it as it originally said to call with "this" instead of _obj now all i need to find is a script like yours to call in some para troopers instead of ammo lol i seen a few on here so im gonna take a look at them once again thank you very much for your help m8

Edited by starvin

Share this post


Link to post
Share on other sites

When i go to get gear, i can see it in the box but cannot take it? also this would be perfect if you could mouse click on map where you want the drop

Share this post


Link to post
Share on other sites
When i go to get gear, i can see it in the box but cannot take it? also this would be perfect if you could mouse click on map where you want the drop

Honestly I have no idea on why you can't pick up the gear in the box...

This may or may not work for map click (hopefully it gives you some hints on what to do):

onMapSingleClick "_n = [player, 'c130j', 270, 200, _pos, 3, ['tbr_airdrop\ingress.sqf','tbr_airdrop\approach.sqf','tbr_airdrop\egress.sqf'], [['ParachuteMediumWest','USBasicAmmunitionBox_EP1','tbr_airdrop\announce.sqf',''],['ParachuteBigWest','HMMWV_M1035_DES_EP1','tbr_airdrop\announce.sqf','tbr_airdrop\explode.sqf']]] execVM 'tbr_airdrop\tbr_airdrop.sqf'; onMapSingleClick ''; true;"

Share this post


Link to post
Share on other sites

Ok thanks man, I'll try it later

edit*

Ran it (dodrop.sqf) through squint and it gave some errors, and i also removed the exploding option for the jeep, works ok but its quite laggy and for some reason i still cant grab weapons, all good ill check it out sometime when i really want something like this

onMapSingleClick {_n = [player, 'c130j', 270, 200, _pos, 3, ['tbr_airdrop\ingress.sqf','tbr_airdrop\approach.sqf','tbr_airdrop\egress.sqf'], [['ParachuteMediumWest','USBasicAmmunitionBox_EP1','tbr_airdrop\announce.sqf',''],['ParachuteBigWest','HMMWV_M1035_DES_EP1','tbr_airdrop\announce.sqf','']]] execVM 'tbr_airdrop\tbr_airdrop.sqf'; onMapSingleClick ''; true;}_n = [player, 'c130j', 270, 200, _pos, 3, ['tbr_airdrop\ingress.sqf','tbr_airdrop\approach.sqf','tbr_airdrop\egress.sqf'], [['ParachuteMediumWest','USBasicAmmunitionBox_EP1','tbr_airdrop\announce.sqf',''],['ParachuteBigWest','HMMWV_M1035_DES_EP1','tbr_airdrop\announce.sqf','']]] execVM 'tbr_airdrop\tbr_airdrop.sqf'; onMapSingleClick ''; true;

Edited by Katipo66
Squint errors

Share this post


Link to post
Share on other sites
"Note that it is possible to use the "script to run on touchdown" to customize the load-out of any ammo/weapons-crate. "

sorry to be a pain again but does that mean just execute a new script after box has landed ie after desrats fix i could just execute a ammo filler script thanks desrat and thebarricade for the help and a great script

Yes, i did some fixes after some 2 weeks of tries:

// add green smoke while dropping

_smoke = "SmokeShellgreen" createVehicle _chutePos;

_smoke attachto [_drop, [0, 0, 0]];

waitUntil {((getPos _drop) select 2) < 1};

detach _drop;

detach _smoke;

deleteVehicle _smoke;

// EPIC AWESOMENESS!!!! GOT THIS WORKING yeeehaa!!!!!!!

_ammobox = _drop;

nul = [_ammobox ,"ALL","ALL",TRUE,30,75,30] execVM "crateFiller.sqf";

_ammobox addAction ["<t color='#ff0000'>Save Loadout</t>", "saveloadout.sqf",[],-99,false,true,"",""];

Im sure you will have it.

SAVELOADOUT.SQF goes like this:

//////////////////////////////////////////////////////////////////

// SAVE LOADOUT SCRIPT

// Modified by: A. Mayer [24thMEU]

//////////////////////////////////////////////////////////////////

_unit = _this select 1;

_weapons = weapons _unit;

_magazines = magazines _unit;

_backpack = unitBackpack _unit;

_backpackmagazines = getMagazineCargo _backpack;

_backpackweapons = getWeaponCargo _backpack;

savedloadout = [_weapons,_magazines,typeOf _backpack,_backpackmagazines,_backpackweapons];

player GlobalChat "WEAPONS AND MAGAZINES LAYOUT SAVED. YOU WILL RESPAWN WITH THIS LAYOUT, MEANS ALL MAGAZINES THAT YOU CURRENTLY HAVE.";

Cheers!!

Edited by ArtMayer_MX
DIDNT WORK....... :(

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  

×