Jump to content
Sign in to follow this  
Dominic92x

Nearestobject issues

Recommended Posts

Hey guys, I'm tickering with a towing script and I'm having issues...

I have it setup so cars can tow other cars but I ran into a problem where the script will try to attach the players vehicle to itself and ignore any other vehicles. As in, the nearest "car" the script picks up is the "car" the player is in. Is there a way to make the script ignore the players car?

Script

_carrier = _this select 0;
_pilot = _this select 1;
_action = _this select 2;

_nearest = nearestObject [(vehicle player), "Car"];

if ((typeOf _nearest) == "") exitWith { _carrier vehicleChat "No vehicles nearby" };

_carrier removeAction _action;
_carrier setVariable ["cancelledAttach", false];

_cancelAction = _carrier addAction ["Cancel Tow", "cancelAttach2.sqf", [], 1, false, true, "", "driver _target == player"];

_carrier vehicleChat format ["Ready to attach vehicle --%1--", typeOf _nearest];

waitUntil { ( (_carrier distance _nearest) < 5 ) || _carrier getVariable "cancelledAttach" };

if (_carrier getVariable "cancelledAttach") exitWith { _carrier vehicleChat "Cancelled Vehicle Attach" };

_carrier vehicleChat format ["%1 now attached", typeOf _nearest];

_carrier setVariable ["attached", true];
_carrier removeAction _cancelAction;
_carrier addAction ["Detach Vehicle", "detachVehicle2.sqf", _nearest, 1, false, true, "", "driver _target == player"];
while { _carrier getVariable "attached" } do {
_nearest Attachto [_carrier,[0,-4,-1]];
sleep 0.25;
};

[_carrier, _nearest] execVM "dropVehicle2.sqf";

If anyone has any ideas, I would appreciate it.

Edited by Dominic92x

Share this post


Link to post
Share on other sites

Hi Dominic92x,

Yes, that will happen since that vehicle is the nearest one to that position, what you need is nearestObjects command and filter the result after.

_neo_

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  

×