Jump to content
Sign in to follow this  
EnvakeoLugaria

Helo AttachTo Script without names, adding action to helo

Recommended Posts

Hey guys, I've been playing a bit of the OPTRE mod, and I've talked with one of their devs about a way to attach a vehicle to a helicopter.

I have a bit of experience in the 3D editor, and I'm familiar with everything up to more advanced scripting.

The way it works is it attaches the MRAP vehicle to the underside of the helicopter, no ropes or anything.

 

The line looks like this, with ___Name being the vehicle names:   mrapName attachTo [heloName, ([(typeOf mrapName)] call OPTRE_fnc_PelicanAttachToPoints)]

 

This works if you name the two vehicles, and activate the function, I've done a trigger and addAction, BUT, I want to find out how to run this WITHOUT having to name the vehicles before hand.

I am guessing it would be some "find the ID of the MRAP, attachTo, find ID of helo" kinda thing.

I would have to think normal sling loading has to do this to an extent, right? Find the closest vehicle, and attach the ropes...I just thought I'd ask if anyone knows where I could start looking for a way to do this.

 

Thanks for any help

-Envak

Share this post


Link to post
Share on other sites

You don't find a global ID of an object you didn't create manually, you create a hitbox under your chopper with code.  Any "kindof" type truck, or specific object class that is within a certain distance from the position under your helicopter is true, then executes your code.  I believe items like beanie caps and what not can also be attached to a helo and made invisible with hideObject.  hideObject should allow the item to clip, but I only have experience with people in this regard.  Any item that is kindof "truck" that is within a certain x and y difference of the beanie can be your hit box, if you don't feel like casting a math equation under your chopper, that is.  Hat is also attachTo and set it to a relative position under your helo.

 

edit: you can also attach triggers with boundaries under your chopper.  any kindof type truck in that boundary can execute code.

 

start here:

triggername attachTo [vehiclename,[_x,_y,_z]];

 

don't do the item trick, that's just a dumb thought.

Share this post


Link to post
Share on other sites

I'll give it a try, thanks.

 

The whole point of this is a sort of stop-gap measure until the devs for the OPTRE mod actually put this in.

I want to be able have a persistant ALiVE campaign and spawn vehicles in Zeus.  I could just make 20 pairs and have an action on each set, but I'd rather not.

So that's why I'm looking for a way to do this without any set-up on the vehicles before hand.  I don't know if this is really even possible, but normal sling loading is similar, right?

I'm going to take a look at other sling loading scripts/whats actually in the game right now.

Share this post


Link to post
Share on other sites

_allmrap = nearestObjects [player, ["O_MRAP_02_hmg_F","O_MRAP_02_gmg_F","O_MRAP_02_hmg_F" ], 999999]; // https://community.bistudio.com/wiki/Arma_3_CfgVehicles_EAST // for exemple class east
{
 _trg = createTrigger["EmptyDetector",getPosATL _x];
 _trg setTriggerArea[150,150,0,false];
 _trg setTriggerActivation["any","PRESENT",false];
 _trg setTriggerStatements["this", "null =[] execVM 'yourscript.sqf',hint 'my trigger actived debug' ;", ""]; // "1st condition" , 2nd "on activate"  change "this" by>> "this && vehicle player isKindOf ""air"""   ---for the condition if is the player in fly
 
}forEach _allmrap;

Share this post


Link to post
Share on other sites
1 hour ago, Nach said:

_allmrap = nearestObjects [player, ["O_MRAP_02_hmg_F","O_MRAP_02_gmg_F","O_MRAP_02_hmg_F" ], 999999]; // https://community.bistudio.com/wiki/Arma_3_CfgVehicles_EAST // for exemple class east
{
 _trg = createTrigger["EmptyDetector",getPosATL _x];
 _trg setTriggerArea[150,150,0,false];
 _trg setTriggerActivation["any","PRESENT",false];
 _trg setTriggerStatements["this", "null =[] execVM 'yourscript.sqf',hint 'my trigger actived debug' ;", ""]; // "1st condition" , 2nd "on activate"  change "this" by>> "this && vehicle player isKindOf ""air"""   ---for the condition if is the player in fly
 
}forEach _allmrap;

 

 

So I gave the script a try, after a little messing around, the script runs, however, nothing happens...

This is how I have it set up:

 

_allWarthogs = nearestObjects [player, ["OPTRE_M12_FAV"], 999999];
{
 _trg = createTrigger ["EmptyDetector",getPosATL _x];
 _trg setTriggerArea [150,150,0,false];
 _trg setTriggerActivation ["any","PRESENT",false];
 _trg setTriggerStatements ["this", "null =[] execVM 'MagLocks.sqf',hint 'Maglocks Activated' ;", ""];

}forEach _allWarthogs;

 

So, this is in an sqf. called "WarthogAttach.sqf", which I activate by an addAction on the helo.

 

"Maglocks.sqf" is another .sqf, and contains: call  OPTRE_fnc_PelicanAttachToPoints;

 

The hint appears, so I'm thinking the "Maglocks.sqf" didn't work correctly.

 

Thank you guys for your answers so far!

 

 

  • Like 1

Share this post


Link to post
Share on other sites
58 minutes ago, EnvakeoLugaria said:

 

"Maglocks.sqf" is another .sqf, and contains: call  OPTRE_fnc_PelicanAttachToPoints;

The hint appears, so I'm thinking the "Maglocks.sqf" didn't work correctly.

 

 

 

 

 

 

Can you post this script I can help you if you want by ;) 

Share this post


Link to post
Share on other sites
Just now, Nach said:

Can you post this script I can help you if you want by ;) 

 

Awesome!

 

So, all that "Maglocks.sqf" contains is:      call OPTRE_fnc_PelicanAttachToPoints

The function "OPTRE_fnc_PelicanAttachToPoints" has a .sqf elsewhere from the mod, it contains:

 

_return = switch (_this select 0) do {

    // Supply Vehicles
    case "OPTRE_m1087_stallion_unsc":      { [0,-6,0.4] };
    case "OPTRE_m1015_mule_unsc":           { [0,-4.9,0.4] };
    case "OPTRE_M12_FAV_APC":              { [0,-3.2,0.4] };
    
    // Warthog
    case "OPTRE_M12_FAV":                  { [0,-4.9,0.1] };
    case "OPTRE_M12_FAV_black":          { [0,-4.9,0.1] };
    case "OPTRE_M12_FAV_Marine":          { [0,-4.9,0.1] };
    case "OPTRE_M12_FAV_snow":               { [0,-4.9,0.1] };
    case "OPTRE_M12_FAV_tan":               { [0,-4.9,0.1] };
                    
    case "OPTRE_M12_LRV":                   { [0,-4.9,0.1] };
    case "OPTRE_M12_LRV_black":          { [0,-4.9,0.1] };
    case "OPTRE_M12_LRV_Marine":          { [0,-4.9,0.1] };
    case "OPTRE_M12_LRV_snow":               { [0,-4.9,0.1] };
    case "OPTRE_M12_LRV_tan":               { [0,-4.9,0.1] };
                    
    case "OPTRE_M12A1_LRV":               { [0,-4.9,0.1] };
    case "OPTRE_M12A1_LRV_black":          { [0,-4.9,0.1] };
    case "OPTRE_M12A1_LRV_Marine":          { [0,-4.9,0.1] };        
    case "OPTRE_M12A1_LRV_snow":          { [0,-4.9,0.1] };
    case "OPTRE_M12A1_LRV_tan":          { [0,-4.9,0.1] };
                    
    case "OPTRE_M12G1_LRV":               { [0,-4.9,0.1] };            
    case "OPTRE_M12G1_LRV_black":          { [0,-4.9,0.1] };
    case "OPTRE_M12G1_LRV_Marine":          { [0,-4.9,0.1] };
    case "OPTRE_M12G1_LRV_snow":          { [0,-4.9,0.1] };        
    case "OPTRE_M12G1_LRV_tan":          { [0,-4.9,0.1] };
                    
    case "OPTRE_M12R_AA":                  { [0,-4.9,0.1] };
    case "OPTRE_M12R_AA_black":          { [0,-4.9,0.1] };    
    case "OPTRE_M12R_AA_Marine":          { [0,-4.9,0.1] };
    case "OPTRE_M12R_AA_snow":              { [0,-4.9,0.1] };
    case "OPTRE_M12R_AA_tan":              { [0,-4.9,0.1] };        
                    
    case "OPTRE_M813_TT":                   { [0,-4.9,0.1] };
    case "OPTRE_M813_TT_black":          { [0,-4.9,0.1] };
    case "OPTRE_M813_TT_Marine":          { [0,-4.9,0.1] };        
    case "OPTRE_M813_TT_snow":              { [0,-4.9,0.1] };
    case "OPTRE_M813_TT_tan":              { [0,-4.9,0.1] };        

    case "OPTRE_UNSC_falcon_black":      { [0,-6,-0.1] };
    case "OPTRE_UNSC_falcon_green":         { [0,-6,-0.1] };
    case "OPTRE_UNSC_falcon_snow":          { [0,-6,-0.1] };
    case "OPTRE_UNSC_falcon_tan":          { [0,-6,-0.1] };
                    
    default                               { [0,-4.9,0.1] }; 
};
    

 

It has pre-set x,y,z parameters for each of the vehicles in the mod.  I can get the MRAP/warthog to attach using names and triggers to run everything just like up top: 

 

mrapName attachTo [heloName, ([(typeOf mrapName)] call OPTRE_fnc_PelicanAttachToPoints)]

 

Thanks.

Share this post


Link to post
Share on other sites
3 hours ago, EnvakeoLugaria said:

So, all that "Maglocks.sqf" contains is:      call OPTRE_fnc_PelicanAttachToPoints

 

ok I return to you later

Share this post


Link to post
Share on other sites
On ‎02‎/‎02‎/‎2017 at 11:12 PM, EnvakeoLugaria said:

 

Thanks.

 

New version  : forget version trigger ;)

 

into init.sqf

---------------

_allmrap = nearestObjects [player, ["OPTRE_M12_FAV" ], 999999];
{
null = [_x] execVM "helpscript.sqf";
}foreach _allmrap

------------------------------------------

helpscript.sqf

---------------------

_mrap = _this select 0;
addac = heloname addAction ["Attachtomrap",{[_this select 0] attachTo [heloName, ([(typeOf mrapName)] call OPTRE_fnc_PelicanAttachToPoints)]},[],1,false,true,"","(_target distance _this) < 150"]; // 150 distance active script on heloname by a mrap to 150m
publicVariable "addac";

 

you must to have a script into the init. addon I think for active adonn exemple >> OPTRE_fnc_PelicanAttachToPoints = compile preprocessfilelinenumbers "Maglocks.sqf"; or an global script who search the init null = [] initmyaddon.sqf; for active the fnc

you must to call or execvm it into the init .sqf  for actived attach to

 

by ;)))))))

 

Share this post


Link to post
Share on other sites

Thanks for your help so far, but it still seems like something is missing, there's a lot of undefined variables...

 

I'm just going to see if I can get the OPTRE_fnc_PelicanAttachToPoints to work, kinda like this:

 

_warthog = nearestObjects [player, ["OPTRE_M12_FAV" ], 999999]; // MRAP name, if you haven't guessed by now, this is a Halo mod, the vehicle is called a "Warthog".
_pelican = nearestObjects [player, ["OPTRE_Pelican_armed_green" ], 999999]; // Helo name, in Halo, the "Pelican" is a VTOL troop/vehicle carrier.
_warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)]; // this is the script from my first post, but instead of any names, would using local variables to define them work?

 

I'll worry about adding the action to the pelican/helo later, I just want to see if I can run the OPTRE_fnc_Pelican..........

 

I put this into the Pelican/Helo's Init. in the editor, I named the vehicle pelican1: pelican1 addAction ["Attach Warthog", "AttachTheWarthog.sqf"]

Inside "AttachTheWarthog.sqf" is:

 

_warthog = nearestObjects [player, ["OPTRE_M12_FAV" ], 999999];
_pelican = nearestObjects [player, ["OPTRE_Pelican_armed_green" ], 999999];
_warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)];

 

When I do this I get an error saying: "...attachTo [_pelican, ([(|#|typeOf _warthog)] call OPTRE_fnc........

                                                                                                 ^

                                                                   "Type Array, expected object"

 

So it seems something in: _warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)]; is not correct.

 

If you had any more input, it would be greatly appreciated!

 

EDIT:

 

I ran:

_warthog = nearestObjects [player, ["OPTRE_M12_FAV" ], 999999];
_pelican = nearestObjects [player, ["OPTRE_Pelican_armed_green" ], 999999];
_warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)];

                                                 

in the de-bug console, it says there is a "generic expression error" right in front of "typeOf"

 

I tried replacing typeOf with _type and put: _type = typeOf _warthog,  above that, but it still reads as "generic expression error".

Edited by EnvakeoLugaria

Share this post


Link to post
Share on other sites

My latest try...

 

_warthog = nearestObject [player, "Car"]; 

_pelican = nearestObject [player, "Helicopter"]; 
_warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)];

 

I changed to "nearestObject" to return a single object, as that was causing a few errors, but the above script still return the error of "generic error in expression"

This is getting kinda funny............

 

 

  • Like 1

Share this post


Link to post
Share on other sites

you must to have a liste with the cfg vehicule of addon for car and heli

 

_warthog = nearestObject [player, "Car"]; <<< it  the cfg of unit ex for   remplace car by "OPTRE_M12_FAV"

_pelican = nearestObject [player, "Helicopter"]; <<again "OPTRE_Pelican_armed_green"

 

_warthog = _this select 0;

_pelican = _this select 1;

 

 

_warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)];

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

If I run it just like that:

 

__warthog = nearestObjects [player, ["OPTRE_M12_FAV"], 10];
_pelican = nearestObjects [player, ["OPTRE_Pelican_armed_green"], 10];

 

_warthog = _this select 0;

_pelican = _this select 1;

 

 

_warthog attachTo [_pelican, ([(typeOf _warthog)] call OPTRE_fnc_PelicanAttachToPoints)];

 

then it gets: error _warthog |#|attachTo [_pelican........

                                             ^

                             generic error in expression

 

I'm tried messing around with running: _warthog attachTo [_pelican, [0,-4.9,0.1]]; instead of the OPTRE_fnc..... line

with 0,-4.9,0.1 from OPTRE_fnc_PelicanAttachToPoints.sqf.  They are the attachTo coordinates, x,y,z for the warthog.

 

still nothing, script activates, I've tried changing things around, right now, I'm running: 

 

_warthog = nearestObjects [player, ["OPTRE_M12_FAV"], 10];
_pelican = nearestObjects [player, ["OPTRE_Pelican_armed_green"], 10];

_warthog = _this select 0;
_pelican = _this select 0;

_warthog attachTo [_pelican, [0,-4.9,0.1]];

 

but nothing happens with this one...

Share this post


Link to post
Share on other sites

I got it working, for one type of pelican and one type of warthog!

 

Nach, thank you so much for your help so far!

 

My Init.sqf checks for the nearest pelican and warthog:

 

_pelican = nearestObject [player, "OPTRE_Pelican_armed_green"];

_pelican addAction ["Attach Warthog", "AttachIt.sqf"];
_pelican addAction ["Detach Warthog", "DetachIt.sqf"];

 

Then I can get in the pelican and attach the warthog with AttachIt.sqf:

 

_warthog = nearestObject [player, "OPTRE_M12_FAV"];
_pelican = nearestObject [player, "OPTRE_Pelican_armed_green"];

_warthog attachTo [_pelican, [0,-4.9,0.1] ];

 

And detach it with DetachIt.sqf:

 

_warthog = nearestObject [player, "OPTRE_M12_FAV"];

detach _warthog;

 

Now I just need to find a way to add the actions to ANY pelicans and Warthogs I get close to...

Is there a way to have the game re-check/update what pelican and warthog are closest to me?

 

I tried adding an action to the player that just ran: _pelican = nearestObject [player, "OPTRE_Pelican_armed_green"];

except I changed all the variables to global ones...

No idea if thats kinda how it works or not......

 

EDIT:

 

I'm going to see if I can just edit the mod files and add an action right into the pelican.....

 

 

Share this post


Link to post
Share on other sites

This should work.
Should be MP compatible and even uses User Action 1 as a shortcut if that is desired.

Currently the action is available to the pilot only. If you wish to change that go right ahead.

 

Remember to add the classes into the script before trying it out.
The object selection is based on inheritance so you can either add all specific classes or a common parent.
To find a class's parent classes place the vehicle in editor, right click it and select "Find in config browser". 
Near the bottom it should show all parent classes.

 

Execute it from initPlayerLocal.sqf with:

[] execVM "yourNameHere.sqf";

 

Contents of "yourNameHere.sqf":
 

Spoiler

 


//pelicanWarthogTransport.sqf

//Add all pelican classes to this array.
_pelicans = [];
//Add all warthogs to this array.
_warthogs = [];
//How close the pelican have to be for it to work
_maglockDistance = 25;
//Shortcut, set to "" to disable.
_shortcut = "User1";

sleep 1;
while {true} do {
	{
		_ids = _x getVariable ["PWT_actionIDs", []];
		if(_ids isEqualTo []) then {
			
			_idAttach = _x addAction [
				"Maglock Warthog",
				{
					params ["_target", "_caller", "_id", "_args"];
					_args params ["_classes", "_distance"];
					
					_nearby = nearestObjects [getPos _target, _classes, _radius];
					
					if(count _nearby > 0) then {
						_nearest = _nearby select 0;
						_nearest attachTo [_target, [typeOf _nearest] call OPTRE_fnc_PelicanAttachToPoints];
						_target setVariable ["PWT_carriedObject", _nearest, true];
						
						hint "Maglocks engaged.";
					} else {
						hint format ["Maglocks failed, no warthog within %1 m.", _distance];
					};
				},
				[_warthogs, _maglockDistance],
				666,
				false,
				true,
				_shortcut,
				"_this isEqualTo driver _target && isNull (_target getVariable [""PWT_carriedObject"", objNull])"
			];
			
			_idDetach = _x addAction [
				"Disengage maglocks",
				{
					params ["_target"];
					_object = _target getVariable ["PWT_carriedObject", objNull];
					if(!isNull _object) then {
						detach _object;
					};
				}
				[],
				665,
				false,
				true,
				_shortcut,
				"_this isEqualTo driver _target && !isNull (_target getVariable [""PWT_carriedObject"", objNull])"
			];
			
			_x setVariable ["PWT_actionIDs", [_idAttach, _idDetach]];
		};
	} forEach entities [_pelicans, [], false, true];
	sleep 5;
};

 

 

 

 

Edited by mrcurry
Added info about inheritance

Share this post


Link to post
Share on other sites

This looks good, I'm testing it out, but running into a few errors: 

_nearby = nearestObjects [getPos _target, _classes, _radius];

It says _radius is an undefined variable, I tried changing it to _maglockDistance, but still said "undefined variable"

I changed it to 25, as I'm guessing it is referencing a radius, and that seemed to fix it...

 

As well as:

 

_nearest attachTo [_target, [typeOf _nearest] call OPTRE_fnc_PelicanAttachToPoints];

right in front of: attachTo, it says there's a "generic error is expression".  This is one of the same errors I had messing around with it myself.

I have no idea what's doing it, but out of all the errors I've had so far, this one seems a bit puzzling.

 

If you have any input on these, I would love it!

Share this post


Link to post
Share on other sites

_warthog = nearestObjects [player, ["OPTRE_M12_FAV"], 10];
_pelican = nearestObjects [player, ["OPTRE_Pelican_armed_green"], 10];

_warthog = _this select 0;
_pelican = _this select 1;

pelican = _pelican;

warthog = _warthog;

"pelican" publicvariable;

"warthog" publicvariable;

warthog attachTo [pelican, [0,-4.9,0.1]];

 

with attach to only object function

 

by;)

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  

×