Jump to content
XallZall-39dbbb756b7e13ec

Apply setPylonLoadout to a Helicopter within a Trigger without giving the Helicopter/s a variable name.

Recommended Posts

Hello BI community, I am as green as it gets with these forums, with that said I did search for relevant topics, without success so apologies in advance if I overseen a similar topic in advance, but honestly I don't even know how to query best what I am searching for.

I will describe what I am hoping to achieve:

I have an object, it can be anything, but in this case its a Crate.
I also have a Trigger and a helicopter.

The concept is as follows:
The Helicopter is parked on and in the trigger.
Any player can go to the box and use an addAction menu to select a Pylon Loadout for said helicopter.
The addAction menu then activates the trigger to execute a code to first wipe any existing pylons and then give them the new pylons.

The problem:
I managed to get pretty much everything to work, expect that I don't know how to apply the code without giving the Helicopter a Variable Name or using "vehicle player".
I would like to trigger to simply apply the commands to the helicopter without me specifying a Variable name, as I wish to make this trigger universal to every helicopter that lands on it, and dynamically, so if new helicopters happens to be created/purchased, that they can also use and take advantage of the feature.

The code (Without a Trigger and Wipe in this case)
ChangeTime = 5;
this addAction ["Plyon (X)",
{
    Delayer =[] spawn
    {
        hint format ["Changing Plyons... ETA: %1" , ChangeTime];
        sleep ChangeTime;
        vehicle player setPylonLoadout [1, "rhs_mag_b8v20a_s8kom"];
        vehicle player setPylonLoadout [2, "rhs_mag_b8v20a_s8kom"];
        vehicle player setPylonLoadout [3, "rhs_mag_b8v20a_s8df"];
        vehicle player setPylonLoadout [4, "rhs_mag_b8v20a_s8df"];
        vehicle player setPylonLoadout [5, "rhs_mag_9M120M_Mi24_2x"];
        vehicle player setPylonLoadout [6, "rhs_mag_9M120M_Mi24_2x"];
        vehicle player setPylonLoadout [7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4"];
        hint "Plyon reconfiguration completed.";
    },
}];

 

This code will work but only if its activated and then the player goes into the helicopter, and while I am not certain, I believe it would probably also change the pylons for other helicopters that happen to be piloted by a human.

Stuff that I tried:
I tried using this, thislist and various other means inside the trigger but of course those target the trigger itself or create an array and setPylonLoadout needs a Object not an array.

Question and TL/DR:
Is there a way to apply the pylons within the trigger without given the helicopters any Variable Names?

Thanks in advance and apologies if this was already answered somewhere before.

Share this post


Link to post
Share on other sites

Your trigger has an area inside which a helicopter (or more) is.

Your addAction is on the box. Btw, the code triggered by addAction is already scheduled. That means you can suspend it, spawning it is useless. But I'm not sure of what you intend to do, somewhere else with delayer variable.

I can't test your code for RHS, but, as far as these pylons exist and are OK (you should double-check the pylons' numbers), you just have to name your trigger (like yourTriggerName), and write the action code like this:

 

ChangeTime = 5;
this addAction ["Pylon (X)",{
  for "_i" from changeTime to 1 step -1 do {
    hint format ["Changing Plyons... ETA: %1" , ChangeTime];
    changeTime = changeTime -1;
    sleep 1;
  };
  {
    private _veh = _x;
    { _veh setPylonLoadout _x} forEach [[1, "rhs_mag_b8v20a_s8kom",TRUE], [2, "rhs_mag_b8v20a_s8kom",TRUE],[3, "rhs_mag_b8v20a_s8df",TRUE],[4, "rhs_mag_b8v20a_s8df",TRUE],[5, "rhs_mag_9M120M_Mi24_2x",TRUE],[6, "rhs_mag_9M120M_Mi24_2x",TRUE],[7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]];
  } forEach (vehicles select {_x isKindOf "helicopter" && _x inArea yourTriggerName});
  hint "Pylon reconfiguration completed."
}];

 

Notes:

- I force the pylons by TRUE as 3rd argument of setPylonLoadout

 

- in MP, as this command is local (and the action code too), you need to remote Exec it :

{[_veh,_x] remoteExecCall ["setPylonLoadout",0,_veh] } forEach [[1, "rhs_mag_b8v20a_s8kom",TRUE], [2, "rhs_mag_b8v20a_s8kom",TRUE],[3, "rhs_mag_b8v20a_s8df",TRUE],[4, "rhs_mag_b8v20a_s8df",TRUE],[5, "rhs_mag_9M120M_Mi24_2x",TRUE],[6, "rhs_mag_9M120M_Mi24_2x",TRUE],[7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]];

 

- your code seems to work for RHS_AH64D (helo with 7 pylons). The other kind of helos are probably not working, or at least not totally, depending possible pylons. You can sort helicopters by their class and do a workable rearming like:

if (_veh isKindOf "RHS_AH64D") then {{ _veh setPylonLoadout _x} forEach...};

 

 

 

 

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@pierremgi you are my hero.

This is working perfectly exactly how I imaged it.
All I had to do was give the Trigger the name and set ChangeTime back to 5 in this case to reset the timer.

What was giving me the most issue is not knowing how to tell the trigger to get the object that is inside of it...

So I will break down my understanding, please feel free to correct me if I am mistaken at any point...

private _veh = _x;
(I looked into the private command here but honestly I dont really get it just yet, but you set it to be _x)

forEach (vehicles select {_x isKindOf "helicopter" && _x inArea yourTriggerName});
(Here I believe you are using forEach to check everything in the trigger, that is a vehicle with the vehicle command, then the isKindOf "helicopter" to check if its a helo or a subclass of it, using inArea to declare to look into the Trigger of yourTriggerName)


And also thank you for the advice on the possible issues that may arise with this code since its using 7 pylons.
I just tested this as well, and while it works, I can see it being abused as I managed to arm a little bird with 4 s8Kom Rockets, carrying 80 rockets this way.

So your suggestion of making separate classes, perhaps something like light medium heavy helicopters and then filtering them out that way.

Share this post


Link to post
Share on other sites

yes, private is a good habit for keeping your local variables not overridden by data coming from other scopes with same variable names. There are so much scripts running from mods, scenario or even FSMs. The point here is I'd declare it prior to the loop, not inside:   private "_veh"; { _veh = _x; ...} foreach... is better. I scripted a little bit quickly.

 

The code forEach returns all helos matching the condition (inside the trigger's area), so yes, you can add extra filters depending on your scenario, if needed. The script fails safe anyway if pylons are not compatible with the helo.

For a better tuning (example):
private "_pylons";

call {

   if (_veh isKindOf "RHS_AH64D") exitWith {

      _pylons = [[1, "rhs_mag_b8v20a_s8kom",TRUE], [2, "rhs_mag_b8v20a_s8kom",TRUE],[3, "rhs_mag_b8v20a_s8df",TRUE],[4, "rhs_mag_b8v20a_s8df",TRUE],[5, "rhs_mag_9M120M_Mi24_2x",TRUE],[6, "rhs_mag_9M120M_Mi24_2x",TRUE],[7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]];

   };
   if (_veh isKindOf anotherClassHere) exitWith { _pylons = [[...],[...],...[...]] };

};  // End of call, so according to helo class the call code returns the _pylons, then

{ _veh setPylonLoadout _x} forEach _pylons;

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@pierremgi

I really hate to ask but, can you show me how to do this with the previous code that includes the trigger?
I was contemplating whether to or not to even post this because I am fairly embarrassed of my inability to take advantage of your better tuning example that you posted.
 

ResetTimer = 5;
TiggerName = HeloHanger_01;
ChangeTime = ResetTimer;

this addAction ["Equip (Bomb) Pylons",
{
    for "_i" from changeTime to 1 step -1 do
    {
        hint format ["Changing Plyons... ETA: %1" , ChangeTime];
        changeTime = changeTime -1;
        sleep 1;
    };

    private "_pylons";
    call
    {
        if (_veh isKindOf "RHS_Mi24V") exitWith
        {
            _pylons =
            [
                [1, "rhs_mag_b8v20a_s8kom",TRUE],
                [2, "rhs_mag_b8v20a_s8kom",TRUE],
                [3, "rhs_mag_b8v20a_s8df",TRUE],
                [4, "rhs_mag_b8v20a_s8df",TRUE],
                [5, "rhs_mag_9M120M_Mi24_2x",TRUE],
                [6, "rhs_mag_9M120M_Mi24_2x",TRUE],
                [7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]
            ];
        };
        
        if (_veh isKindOf "RHS_AH64D") exitWith
        {
            _pylons =
            [
                [1, "rhs_mag_b8v20a_s8kom",TRUE],
                [2, "rhs_mag_b8v20a_s8kom",TRUE],
                [3, "rhs_mag_b8v20a_s8df",TRUE],
                [4, "rhs_mag_b8v20a_s8df",TRUE],
                [5, "rhs_mag_9M120M_Mi24_2x",TRUE],
                [6, "rhs_mag_9M120M_Mi24_2x",TRUE],
                [7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]
            ];
        };
    };
    {_veh setPylonLoadout _x} forEach _pylons;
    forEach (vehicles select  _x inArea TiggerName);
    
    hint "Pylon reconfiguration completed.";
    ChangeTime = ResetTimer;
}];

This is fairly embarrassing for me to post as no doubt it will highlight my limited understanding of coding/scripting.

I noticed that the {_veh setPylonLoadout _x} is below this time around, not sure if I understood correctly because I am not sure if it is meant to be here.
I am also not sure if I got the part with the _inArea TriggerName correct either.

 

Share this post


Link to post
Share on other sites

You don't need to double your variables. TiggerName = HeloHanger_01; ChangeTime = ResetTimer; Is useless.

There are bracket errors with the forEach command. The code should be like:

{_x ....} forEach (vehicles select {condition on _x here} )

 

So, in SP, this code can do the trick:


 

ResetTimer = 5;
this addAction [" Equip (Bomb) Pylons", {
  for "_i" from ResetTimer to 1 step -1 do {
    hint format ["Changing Plyons... ETA: %1" , ResetTimer];
    ResetTimer = ResetTimer -1;
    sleep 1;
  };
  private "_veh";
  private _pylons = [];
  {
    _veh = _x;
    call {
      if (_veh isKindOf "RHS_Mi24V") exitWith {
        _pylons =
          [
            [1, "rhs_mag_b8v20a_s8kom",TRUE],
            [2, "rhs_mag_b8v20a_s8kom",TRUE],
            [3, "rhs_mag_b8v20a_s8df",TRUE],
            [4, "rhs_mag_b8v20a_s8df",TRUE],
            [5, "rhs_mag_9M120M_Mi24_2x",TRUE],
            [6, "rhs_mag_9M120M_Mi24_2x",TRUE],
            [7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]
          ];
      };
        
      if (_veh isKindOf "RHS_AH64D") exitWith {
        _pylons =
          [
            [1, "rhs_mag_b8v20a_s8kom",TRUE],
            [2, "rhs_mag_b8v20a_s8kom",TRUE],
            [3, "rhs_mag_b8v20a_s8df",TRUE],
            [4, "rhs_mag_b8v20a_s8df",TRUE],
            [5, "rhs_mag_9M120M_Mi24_2x",TRUE],
            [6, "rhs_mag_9M120M_Mi24_2x",TRUE],
            [7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]
          ];
      };
    };
    {_veh setPylonLoadout _x} forEach _pylons;
  }forEach (vehicles select  {_x isKindOf "helicopter" && _x inArea HeloHanger_01});
  hint "Pylon reconfiguration completed.";
  resetTimer = 5;
}];

Note: if you want to avoid a repeated action within the 5sec slot (so disabling action menu for player during the pylon setting), you need to add a condition into addAction. See Biki. A solution consists on setting the addAction condition like this: "ResetTimer == 5";

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks @pierremgi
Okay so I gave it a go and I encountered a few issues.
I tried even rewriting the whole code as well just to rule out any copy-paste issues or spaces or anything else.

When I try your code that you written I am getting a error saying
Error Undefined variable in expression: _veh

I assumed that is is because in this code we do not have
private _veh = _x;

being declared.
If I add that to the code, just under private "_pylons";

 

like this:
private _veh = _x;
private "_pylons";

I am getting an error saying:
Error Undefined variable in expression: _x

Here is the current code with some minor changes.

 

ResetTimer = 5;
player addAction ["Equip (Bomb) Pylons",
{
    for "_i" from ResetTimer to 1 step -1 do
    {
        hint format ["Changing Pylons... %1", ResetTimer];
        ResetTimer = ResetTimer -1;
        sleep 1;
    };
    private "_pylons";
    private _veh = _x;
    {
        call
        {
            if (_veh isKindOf "RHS_Mi24V") exitWith
            {
                _pylons =
                [
                    [1, "rhs_mag_b8v20a_s8kom",TRUE],
                    [2, "rhs_mag_b8v20a_s8kom",TRUE],
                    [3, "rhs_mag_b8v20a_s8df",TRUE],
                    [4, "rhs_mag_b8v20a_s8df",TRUE],
                    [5, "rhs_mag_9M120M_Mi24_2x",TRUE],
                    [6, "rhs_mag_9M120M_Mi24_2x",TRUE],
                    [7, "rhs_ASO2_CMFlare_Chaff_Magazine_x4",TRUE]
                ];
            };
            {_veh setPylonLoadout _x} forEach _pylons;
            
        };
    }forEach (vehicles select {_x isKindOf "helicopter" && _x inArea Hanger_01});
    hint "Pylon reconfiguration completed.";
    ResetTimer = 5;
}];

Change log:
Rewriting of the entire code to rule out any copy paste or space or indentation issues as well as "invisible characters"
Changed "this" to "player" in addAction (just to make troubleshooting more easy)
Removed the second if (_veh isKindOf...) to simplify the code for troubleshooting
Added private _veh = _x; just under private "_pylons";
HeloHanger_01 has been renamed to Hanger_01
Fixed a typo in hint "Changing Plyons... to Pylons
renamed resetTimer to ResetTimer with a capital R at the bottom of the code // typo.

I had the double variables before just so that everything could be modified from the top since the code here wont have a 5 second pylon change time and will have different trigger zones, so that was just to make changes easy. But I have kept them removed in the new code here as well just for the sake of simplification.

I also assumed before that we do not need the isKindOf "helicopter" anymore since we are looking for isKindOf "AH64D" so its interesting to see you put that back in.

Share this post


Link to post
Share on other sites

I gave the new code a go,

a new error:
Error Undefined variable in expression: _pylons

Located at the lower section of the code:
{_veh setPylonLoadout _x} forEach |#|_pylons;
}forEach (vehicles select {_...

Not sure why this is happening since _pylons have been declared.

Triple checked everything as well before I wrote this to make sure I made no mistakes.

Share this post


Link to post
Share on other sites

probably because you're in case of no helo class are working. Simple solution private _pylons = []; makes the code fails safe.

  • Like 1

Share this post


Link to post
Share on other sites

I am not able to get the newer one to work but its fine for now since the first code you provided is working as I had intended it.
Thanks again for everything, and I will try to get the newer version to work as well, whenever that may be I will post here again.
Take care and many thanks again, you been a really big help 💪

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

×