Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Bacomania

Making towing tractors usefull (for heli/plane moving, including multiplayer support)

Recommended Posts

Making towing tractors usefull (for heli/plane moving, including multiplayer support and even on deck of a carrier :yay:)

The towingtractors for moving heli's and planes are made usefull, by placing one trigger in your mission to activate my scripts on all in mission used towingtractors. No need to assign code to individual tractors. The scripts will detect if a player jumps in a towingtractor as driver and will be notified about the option how to tow a heli or plane.

Download URL: http://www.megaupload.com/?d=I23Y2OV0

The scripts can of course freely be used and modified by anyone. Make good use of it :bounce3:

Here are the plain scripts (if the download isn't working for some reason):

They need to be placed in a sub-folder called "AttachToTractor" in your mission.

AttachToTractor.sqf

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AttachToTractor scripts made by Baco
//
// What does it do? 	Make towingtractors operational to move planes and heli's anywere on a map, as long as they are present.
// How does it work? 	Jump in towingtractor and position in front of a plane or heli and 
// 			head nose to the plane or heli nose within 5 degrees, to get the towing option.
//
// To make these scripts work, place a trigger in the mission and:
// 1) let it trigger repeatable and by anyone
// 2) put in the "bedingung" field:		vehicle player != player and local player;
// 3) put in the "on act." field: 		myvec = vehicle player; temp = [myvec] execVM "AttachToTractor\AttachToTractor.sqf";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if not (local player) exitWith {};
_Tractor = _this select 0;
_vectype = typeof _Tractor;
_doexit = 1;
if(_vectype == "TowingTractor") then { _doexit = 0; };
if(_vectype == "tractor") then { _doexit = 0; };
if(_doexit == 1) exitWith {};
Tractorcargo = 0;
_actionadded = 0;
_cargo = nil;
hint format ["Welcome to %1. Position in front of a plane or heli and head the %1 nose to the plane or heli nose within 5 degrees, to get the towing option.", typeOf _Tractor];
while{ (alive _Tractor) && ((driver _Tractor) == player) } do 
{
if (Tractorcargo == 0) then 
{
	_nObject = nearestObject [_Tractor, "Air"];
	if not (isNull _nObject) then 
	{
		if ((_nObject distance _Tractor) > 12) then 
		{
			_Tractor removeAction actioncargo;
			_actionadded = 0;

			_TractorPos = getPosASL _Tractor;
			//hint format ["Position: x= %1, y= %2, z= %3.", (_TractorPos select 0), (_TractorPos select 1), (_TractorPos select 2)];
			//sleep 2;
		}
		else
		{
			if((_nObject != _cargo) && (_actionadded == 1)) then
			{
				_Tractor removeAction actioncargo;
				_actionadded = 0;
			};
			_TractorPos = getPosASL _Tractor;
			_TractorDir = getDir _Tractor;
			_CargoPos = getPosASL _nObject;
			_CargoDir = getDir _nObject;
			_TractorHeading = (((_TractorPos select 0) - (_CargoPos select 0)) atan2 ((_TractorPos select 1) - (_CargoPos select 1)));
			_TractorBearing = _TractorHeading - _CargoDir;
			if(_TractorBearing  > 180) then
			{
				_TractorBearing  = _TractorBearing  - 360;
			}else{
				if(_TractorBearing  < -180) then
				{
					_TractorBearing  = _TractorBearing  + 360;
				}
			};
			_CargoHeading = (((_CargoPos select 0) - (_TractorPos select 0)) atan2 ((_CargoPos select 1) - (_TractorPos select 1)));
			_CargoBearing = _CargoHeading - _TractorDir;
			if(_CargoBearing > 180) then
			{
				_CargoBearing = _CargoBearing - 360;
			}else{
				if(_CargoBearing < -180) then
				{
					_CargoBearing = _CargoBearing + 360;
				}
			};
			if( ((_TractorBearing  > -5) && (_TractorBearing  < 5)) && ((_CargoBearing  > -5) && (_CargoBearing  < 5)) && (_actionadded == 0) ) then
			{
				_actionadded = 1;
				_cargo = _nObject;
				actioncargo = _Tractor addAction [format ["Tow %1", typeOf _cargo], "AttachToTractor\AttachToTractor_start.sqf", _cargo];
			};
		};
	};
}
else
{
	_Tractor removeAction actioncargo;
	_actionadded = 0;
};
sleep 0.1;
};
_Tractor removeAction actioncargo;
_Tractor removeAction actiondrop;
exit;

AttachToTractor_start.sqf

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AttachToTractor scripts made by Baco
//
// What does it do? 	Make towingtractors operational to move planes and heli's anywere on a map, as long as they are present.
// How does it work? 	Jump in towingtractor and position in front of a plane or heli and 
// 			head nose to the plane or heli nose within 5 degrees, to get the towing option.
//
// To make these scripts work, place a trigger in the mission and:
// 1) let it trigger repeatable and by anyone
// 2) put in the "bedingung" field:		vehicle player != player and local player;
// 3) put in the "on act." field: 		myvec = vehicle player; temp = [myvec] execVM "AttachToTractor\AttachToTractor.sqf";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if not (local player) exitWith {};
_Tractor = _this select 0;
_cargo = _this select 3;
_Tractor removeAction actioncargo;
if( (isNull _cargo) || ((_cargo distance _Tractor) > 12) ) then {
Tractorcargo = 0;
exit;
};
hint format ["Coupling the %1 for towing...", typeOf _cargo];
sleep 1; 
Tractorcargo = 1;
actiondrop = _Tractor addAction [format ["Detach %1", typeOf _cargo], "AttachToTractor\AttachToTractor_stop.sqf", _cargo];
_cargo engineOn false;
hint format ["Towing the %1", typeOf _cargo];
_CargoDis = _cargo distance _Tractor;
_CargoDamage = GetDammage _cargo;
while{ (Tractorcargo == 1) && (alive _Tractor) && (vehicle player == _Tractor)} do
{
_TractorPos = getPosASL _Tractor;
_TractorDir = getDir _Tractor;
_cargo setPosASL [(_TractorPos select 0) + (_CargoDis * sin _TractorDir), (_TractorPos select 1) + (_CargoDis * cos _TractorDir), (_TractorPos select 2)];
_cargo setDir (_TractorDir + 180);
_cargo SetDammage _CargoDamage;
sleep 0.01;
};
_Tractor removeAction actiondrop;
_TractorPos = getPosASL _Tractor;
_TractorDir = getDir _Tractor;
_cargo setPosASL [(_TractorPos select 0) + (_CargoDis * sin _TractorDir), (_TractorPos select 1) + (_CargoDis * cos _TractorDir), (_TractorPos select 2)];
_cargo setDir (_TractorDir + 180);
_cargo SetDammage _cargoDamage;
hint format ["Towing stopped and decoupled the %1", typeOf _cargo];
exit;

AttachToTractor_stop.sqf

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AttachToTractor scripts made by Baco
//
// What does it do? 	Make towingtractors operational to move planes and heli's anywere on a map, as long as they are present.
// How does it work? 	Jump in towingtractor and position in front of a plane or heli and 
// 			head nose to the plane or heli nose within 5 degrees, to get the towing option.
//
// To make these scripts work, place a trigger in the mission and:
// 1) let it trigger repeatable and by anyone
// 2) put in the "bedingung" field:		vehicle player != player and local player;
// 3) put in the "on act." field: 		myvec = vehicle player; temp = [myvec] execVM "AttachToTractor\AttachToTractor.sqf";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if not (local player) exitWith {};
_Tractor = _this select 0;
_cargo = _this select 3;
Tractorcargo = 0;
exit;

[note for scripters: the ATTACH TO command could not be used in multiplayer, since the tractor and heli/plane are 180 degrees turned (nose to nose) while towing. The ATTACH TO command does not (yet) support this feature and gave strange results during multiplayer testing :\ How i solved this "problem" check the scripts ;) ]

Share this post


Link to post
Share on other sites

It is an interesting script, fun it :)

I think that it wants it to move like the chain. It seems to lift with the lifttruck under the present situation.

Share this post


Link to post
Share on other sites

Wrong section.

i'll try it out anyway,, need someting like this for the c130j

Share this post


Link to post
Share on other sites

To the moderators: plz feel free to move this entry to the correct section if it's wrong placed. I was in a real hurry to get some sleep while posting it.

Gr.

Baco

Share this post


Link to post
Share on other sites

Nevermind! I got it!

Replace "Air" with "Static"

Edited by Genesis92x

Share this post


Link to post
Share on other sites
Sign in to follow this  

×