Jump to content
Sign in to follow this  
JCataclisma

[SOLVED] How to DETACH specific attached object(s) instead of ALL "attachedObjects"?

Recommended Posts

This message was edited and already contain the changed/solved script.

================================
Hellos, guys!

I have a mission setup which involves three different scripts, both called with addAction, and it all works fine whether SP or dedicated MP server.
Its current flow is like this:

1.) player gets nearby a specific named workshop and executes an addAction on it;
2.) such addAction executes the first "searcher.sqf" script, which searches for nearby vehicles and providing the nearby vehicle class, will execute another specific script ("huronWorkshop.sqf", in this scenario);

3.) this new specific script will create and attach some stuff into the nearby vehicle, and also add a new addAction to it, and such action will execute a third one ("huronDoubleTrucks.sqf").
4.) the working goal of this last action is to search the nearby vehicles for some specific classes and, providing the type of vehicle found, attach it to a specific position upon/relative to the Huron chopper, and also adds a new action that, once selected, will release those trucks and remove the action itself from the menu.

Ok, all of that is working fine within the codes bellow, but the problem is that, by using things like " private _attachedTrucks = attachedObjects _currentHeli; ", the last action will detach ALL the attached objects (in this case, two portable lamps and a closed first aid kit), instead of detaching ONLY the trucks - which was my intention.

Could you please point some suggestions/changes to the code so that I could achieve that?
I could bet there is something to do with working upon the variables themselves, whether should they be private, public or global...? But none of my attempts have returned a sactisfactory result - you may notice in the second script, I even created some extra arrays to try and use them together the "_attachedTrucks", but no success at all.
 

Spoiler

//huronWorkshop.sqf - called via execVM by the "searcher.sqf"
private _nearbyVehicles = nearestObjects[player, ["Helicopter"], 25];
{
    private _currentVehicle = _x;
    if (typeName _currentVehicle == "OBJECT" && (typeOf _currentVehicle in ["B_Heli_Transport_03_F"])) then	
	{

	_currentVehicle lockTurret [[0], true];
	_currentVehicle setCollisionLight true;

	_objectFrontRightLamp = "Land_PortableLight_02_single_folded_olive_F" createVehicle [0, 0, 0];
    _objectFrontRightLamp attachTo [_currentVehicle, [2.066, 3, -2]];
	_objectFrontRightLamp setVariable ['QS_attached',true,!is3DEN];
	_objectFrontRightLamp setVectorDirAndUp [[0.33,-1,0.33], [-0.66,0,-1]];
	_objectRearRightLamp = "Land_PortableLight_02_single_folded_olive_F" createVehicle [0, 0, 0];
    _objectRearRightLamp attachTo [_currentVehicle, [1.2, -6, -0.6]];
	_objectRearRightLamp setVariable ['QS_attached',true,!is3DEN];
	_objectRearRightLamp setVectorDirAndUp [[0,0.66,0.33], [-0.33,-0.33,0.66]];

	_object5 = "Land_FirstAidKit_01_closed_F" createVehicle [0, 0, 0];
    _object5 attachTo [_currentVehicle, [1.5, 5.85, -1.5]];
	_object5 setDir 255;
	_object5 setVariable ['QS_attached',true,!is3DEN];

_currentVehicle addAction
	[
		"<t color='#ff7620'>TOW trucks</t>",
		{
		[] execVM "huronDoubleTrucks.sqf";
		},
		nil,
		0,
		false,
		true,
		"",
		"_this == _target turretUnit [-1] && (getPosATL _target) select 2 < 16",
		10,
		false
	];

};
} forEach _nearbyVehicles;

//huronDoubleTrucks.sqf, called byt the "TOW trucks" addAction from the previous script
	_hemttAmmoClasses = ["B_Truck_01_ammo_F", "B_T_Truck_01_ammo_F"];
	_hemttMoverClasses = ["B_Truck_01_mover_F", "B_T_Truck_01_mover_F"];
		
	_ammoClass = _hemttAmmoClasses;
	_moverClass = _hemttMoverClasses;
		
	_nearbyAmmoTrucks = nearestObjects [vehicle player, _ammoClass, 15, false, false];
	_nearbyRespawnTrucks = nearestObjects [vehicle player, _moverClass, 15, false, false];

	{
	_vehicleClass = typeOf _x;
	
	if (_vehicleClass in _hemttAmmoClasses) then {
		_x attachTo [vehicle player, [-4.8, -1.8, -2.5]];
		_x setDir 180;
		_x setVariable ['QS_logistics', true, true];
	};
	} forEach _nearbyAmmoTrucks;

	{
	_vehicleClass1 = typeOf _x;
	
	if (_vehicleClass1 in _hemttMoverClasses) then {
    _x attachTo [vehicle player, [4.8, -1.8, -2.5]];
    _x setDir 180;
    _x setVariable ['QS_logistics', true, true];
	};
	} forEach _nearbyRespawnTrucks;
	
	private _attachedTrucks = (attachedObjects (vehicle player)) select {_x isKindOf "Car"};

                {
                    _x setVariable ["isAttachedTruck", true];
                } forEach _attachedTrucks;

    private _release = (vehicle player) addAction
	[
		"<t color='#ff7620'>RELEASE trucks</t>",
		{
				_release = _this select 2;
				_currentHeli = (vehicle player);
                private _attachedTrucks = attachedObjects _currentHeli;
                {
                    private _object = _x;
                    if (_object getVariable ["isAttachedTruck", false]) then
                    {
                        detach _object;
                    }
                } forEach _attachedTrucks;
				_currentHeli removeAction _release;
		},
		nil,
		0,
		false,
		true,
		"",
		"_this == _target turretUnit [-1] && (getPosATL _target) select 2 < 42",
		10,
		false
	];

 


NOTE: those "setVatiable QS_logistic" stuff are necessary within the Quiksilver's Apex framework, so that such objects could be manually detached by the players. I'd rather keep them on the trucks, but if that could somehow mess with different variables required to the "specific detach" system to work, they could be completed removed from the trucks.

Edited by JCataclisma

Share this post


Link to post
Share on other sites

You can use select to filter the attached objects according to some condition.

 

For example

private _attachedTrucks = attachedObjects (vehicle player);

becomes:

private _attachedTrucks = (attachedObjects (vehicle player)) select {_x isKindOf "Car"};

 

  • Like 2

Share this post


Link to post
Share on other sites

The more I was trying, the further I was going - in the very opposite direction 😂 .
Not only solved, but gave several extra customization possibilities.

Thank you!

Cheers!

 

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  

×