Jump to content
Sign in to follow this  
acat0970

is there a universal vehicle variable?

Recommended Posts

i am trying to make a towing script for my missions and i want to make it so a certain vehicle cant tow any vehicle.

here is what I've got:

car1 distance _vehicle < 5;

_vehicle attachTo car1 [0,-1,2];

removeAction 11;

the vehicle i want to attach things to is car1.

_vehicle is meant to be any vehicle but i know i am wrong.

if any on could help i would appreciate it.

Thanks!!! :)

Share this post


Link to post
Share on other sites

If you want it to only tow cars:

while {alive car1} do
{
if ((car1 distance _vehicle) < 5) then {
	if (_vehicle isKindOf "Car") then {
		_vehicle attachTo [car1,[0,-1,2]];
		removeAction 11;
		hint "car attached";
	};
};
};

Share this post


Link to post
Share on other sites

Well obviously you will need to tell the script what _vehicle is. It can't read your mind and decide which vehicle you want to tow. How to decide which vehicle to attach is up to you. There are many scripting commands that can help you and the ones you should use depend on what you actually want to happen in the mission...

For example you could use an addAction to add an action menu entry that will run the script and nearObjects to filter for cars within a certain radius of the towing vehicle. But that's just 1 way to do it out of many.

Share this post


Link to post
Share on other sites

Put this in Vehicle init - this addaction["Tow Vehicle","TowScript.sqf"];

Create a script called TowScript.sqf to execute

Put the below script in it

_Towtruck= _this select 0;

_vehicle = nearestObjects [_Towtruck, ["Car"], 5];//Returns an array of all vehicles in "Car" within 5m

_vehicle = _vehicle select 0;//Selects the first car (Closest one)

if ((_Towtruck distance _vehicle) < 5) then {//Double check the distance

if (_vehicle isKindOf "Car") then {//Double check that it's in "Car" array

_vehicle attachTo [_Towtruck,[0,-1,2]];//Attach it

hint "car attached";

};

};

I haven't tested it but it should work. Let me know if it doesn't

Edited by nick103

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  

×