Jump to content
Ex3B

Add action to any vehicle in cargo

Recommended Posts

How would I write a script, to be placed in the init of a VIV transport vehicle (such as the blackfish vehicle transport) that will add a possible action (to the action menu) of any vehicle inside it - and of course remove that action once the vehicle is no longer in the cargo of the VIV transport?

Share this post


Link to post
Share on other sites
blackfish addAction ["Action",{
	hint "bruh"
},nil,1.5,false,true,"","isVehicleCargo vehicle _this == _target"] ;

 

Share this post


Link to post
Share on other sites

Ok, so I'm looking at the documentation for addAction:

https://community.bistudio.com/wiki/addAction

 

So documentation - what you have:

object - blackfish addAction [title - "Action", script - { hint "bruh" }, arguments - nil, priority - 1.5 , showWindow - false, hideOnUse - true, shortcut - "", condition - "isVehicleCargo vehicle _this == _target", radius, unconscious, selection, memoryPoint]

Looks good to me mostly, but I thought the action is always added to the "object" (the blackfish) specified before the addaction command. I tested, and it works though, so thanks.

 

Phase 2 of my scripting question deals with the action.

My problem is that when I unload a vehicle from a blackfish onto an offshore platform (either made with vanilla static objects, or an Arma 2 LHD port), the vehicle spawns off to the side, over the water... a big problem when trying to return Zamaks, Rhinos, etc to an offshore base (Marshals aren't so bad, they are amphibious).

I want to make an action that unloads the vehicle, and sets its position directly behind the blackfish, since the VIV unload system seems unreliable.

 

So I'm guessing I need to make a 2nd script, in the mission folder, (to replace the "bruh" hint). This script will need to identify the blackfish (If I want to use multiple) to get its position, unload the vehicle, and set its position.

So I'm thinking something like a script containing this:

_transportingVehicle = isVehicleCargo _this;

_unload = objNull setVehicleCargo _this;

_reposition =  _this setPosASL [(getPosASL _transportingVehicle select 0) + (cos (getDir _transportingVehicle)*2)) , (getPosASL _transportingVehicle select 1) + (sin (getDir _transportingVehicle)*2), (getPosASL _transportingVehicle select 2) +1 ];

_reorient = _this setDir (getDir _transportingVehicle)

 

Would this work (offsets and stuff tbd)? I'm worried that the getPos won't work if its unloaded first, and that the setPos won't work if its still in the vehicle cargo.

Also I may have the syntax and stuff completely wrong

Share this post


Link to post
Share on other sites

You could experience some ground collision, using the ASL variant for getPos and setPos, especially due to a gradient for the shore (are you sure +1 is OK?)

You could use the alternate syntax of getPos here :

_reposition = _this setPos (_transportingVehicle getPos [2, - getDir _transportingVehicle]);

 

I'd rather use the bis_fnc_findSafePos here.

Share this post


Link to post
Share on other sites
18 minutes ago, pierremgi said:

You could experience some ground collision, using the ASL variant for getPos and setPos, especially due to a gradient for the shore (are you sure +1 is OK?)

I intend for this to be an alternate unload action, for use when landing on offshore platforms - so nothing to do with shore gradients and such. The normal unload option would still be present.

As for +1.. as I said "offsets and stuff tbd" - First I just want to get the script operation working right, then I can play with the values.

If I can get this working for unloading from a blackfish onto an LHD, I think I'll also use it for my VIV insert for the LHD (to be used like the boat rack for the destroyer, but capable of holding much larger items)

 

 

Share this post


Link to post
Share on other sites

So after testing this further, it seems that the script provided is still adding the action to the transporting vehicle,  and not to the transported cargo vehicle.

What I have is:

init.sqf

Spoiler

_VIVLHD = _this select 0;
    sleep 0.1;
_LoadedVehicle = 
_VIVLHD addAction ["Action",{hint "bruh"},nil,1.5,false,true,"","isVehicleCargo vehicle _this == _target"];
_VIVLHD addAction ["Spot on Deck",'ATLAS_Water\LHD\scripts\UnloadScript.sqf',nil,1.5,false,true,"","isVehicleCargo vehicle _this == _target"];

 

UnloadScript.sqf:

Spoiler

_LoadedVehicle = (_this select 0);
_UnloadVehicle = objNull setVehicleCargo _LoadedVehicle;
    sleep 0.1;
_LoadedVehicle setPosASL   
[ (getPos (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) select 0)   
+ (-22*(cos (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0))))   
+ (90*(sin (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0)))),
(getPos (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) select 1)   
+ (90*(cos (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0))))   
+ (22*(sin (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0)))),
(getPosASL (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) select 2) +17  
]; _LoadedVehicle setDir (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) +90);

_LoadedVehicle removeAction 0;

This script moves the entire VIV object for the LHD, and does not detach the cargo from inside it. That means that the _this of the action is not the cargo, but infact the thing holding the cargo.

 

How can I modify this script to so that a player inside the loaded vehicle can have the vehicle ejected from the cargo, and placed on the deck?

I've tested these commands using named vehicles and inits... the setPosASL, getPos, getDir, commands etc all work great.

 

Share this post


Link to post
Share on other sites

Just to be sure:

- addAction is for player's menu. But there are load/unload vanilla Arma addAction for that (on blackfish at least, but supposed to work on all VIV vehicle).

- for AIs driver, you have the vehicle get in/out waypoints.

 

For sure, there is no cinematic for that. Only teleportation.

I'm not sure to understand why you want some addAction more, when you could detect, then script about  the change of status in/out of VIV for all vehicles you want.
For example, you could teleport farer after first teleport, without adding an action.

 

 

Share this post


Link to post
Share on other sites

so I got it working, the init.sqf for the VIV component of the LHD has this:

 

Quote

_VIVLHD = _this select 0;
    sleep 0.1;
    _vehicleCargos = getVehicleCargo _VIVLHD;
    {
        _x addAction ["Action",{hint "bruh"},nil,1.5,false,true,"",""];
        _x addAction ["To Starboard elevator",'ATLAS_Water\LHD\scripts\UnloadScript.sqf',nil,1.5,false,true,"",""];
    } forEach _vehicleCargos;

 

and the modified unload action is:

Quote

_LoadedVehicle = (_this select 0);
_UnloadVehicle = objNull setVehicleCargo _LoadedVehicle;
    sleep 0.1;
_LoadedVehicle setPosASL   
[  
(getPos (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) select 0)   
+ (-22*(cos (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0))))   
+ (90*(sin (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0)))),
   
(getPos (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) select 1)   
+ (90*(cos (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0))))   
+ (22*(sin (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0)))),
   
(getPosASL (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) select 2) +17  
]; Whatevs setDir (getDir (nearestObjects [_LoadedVehicle, ["ATLAS_B_LHD_helper"], 300] select 0) +90);

_LoadedVehicle removeAction 0;

 

Now I just need to add an action for the port elevator, and link the VIV component to the standard LHD, and I'll have it working so that one cant just taxi to the elevators, and load (via VIV) into the cargohold, and one can just walk down to the cargohold, get in a vehicle, and unload onto an elevator (so helos can be stored down there finally.

 

I'll need to do similar things for the player, they spawn in weird locations when getting out of a vehicle in the cargo.

Share this post


Link to post
Share on other sites

Well if you keep addAction on mind, for all vehicles able to embark on any VIV, here is a generic code (based upon what you want).

Here you place the code in init field of any VIV. But you can add a loop in case of spawned VIV (for future readers)

 

Anyway, in my code, you have a loop scouting for embarked vehicles in VIV, in order to manage the addAction (think about load/unload/load again sequence).

 

Note: The hint code stays local in MP. If you want to broadcast it , you need to remoteExec it inside the addAction. (see BIKI example 3)

Same for all commands/functions with local effects. On the other hand, you don't have to remoteExec thus with global effects (like setpos)

 

So, in your VIV(s)

0 = this spawn {
  params ["_VIV","_cargoVehs","_embarkedIn","_unloadVehs","_disembarked"];
  _embarkedIn = "inside" + str (_VIV);
  while {alive _VIV} do {
      waitUntil {sleep 1; _cargoVehs = getVehicleCargo _VIV; count _cargoVehs >0 && {_cargoVehs findIf {isNil {_x getVariable _embarkedIn}} >-1}};
      {
        _x setVariable [_embarkedIn, _x addaction ["action (why not)", {
          params ["_target","","_id","_cargoVehs"];
          hint format ["one %1 has been loaded at position nbr %2 of %3",typeOf _target,(_cargoVehs findIf {_x == _target})+1,name isVehicleCargo _target];
          _target removeAction _id
          },
          _cargoVehs,
          1.5,
          false,
          true,
          "",
          "!isNull isVehicleCargo _target",
          15
        ]];
      } forEach (_cargoVehs select {isNil {_x getVariable _embarkedIn}});
      waitUntil {sleep 1; _unloadVehs = getVehicleCargo _VIV; !(_unloadVehs isEqualTo _cargoVehs)};
      _disembarked = _cargoVehs - _unloadVehs;
      { _x removeAction (_x getVariable [_embarkedIn,-1]);
        _x setVariable [_embarkedIn,nil,true]
      } forEach _disembarked;
  };
};

 

  • Like 1

Share this post


Link to post
Share on other sites

So actually, for now, I am focusing on the viv for an LHD, and since a mod is already needed, the init.sqf script is executed via event handlers in the viv lhd part config.

Thus any placed lhd part will run the script.

Would this work in multiplayer for all players?

Share this post


Link to post
Share on other sites
2 hours ago, Ex3B said:

the init.sqf script is executed via event handlers in the viv lhd part config.

Thus any placed lhd part will run the script.

Would this work in multiplayer for all players?

 

Not sure to understand what you're writing. The init.sqf is a specific event script.

 

If you placed a code in an init field of an edited object, yes, the code will run at each player's start. So, your getVehicleCargo will grab the vehicles already inside the VIV at start. Without refreshing (loop or else), you'll never run the code for embarking vehicle while in game.

As already said, in MP, you need to remoteExec some commands from addAction to make them global (like hint example).

 

Share this post


Link to post
Share on other sites

Sorry, I wasn't clear. Since I'm trying to get stuff working with the LHD from @j0nes , and I have all the files for that and have put up a standalone version of it (with his permission), I figured it would be best to have the script executed from the config.cpp - so nothing needs to be done in the mission editor.

Since every player would have the addon in a multiplayer scenario using it, every player would have a config.cpp calling for the script, it should be fine, no? The hint is just for testing, the script would be repositioning the vehicle (that the local player is in) when its unloaded (by the local player using the action), so that needs no remoteExec, right?

 

However, you are right about it needing to loop.

I had hoped to not have a script contantly running, but it doesn't seem that there's an event handler for that.

Share this post


Link to post
Share on other sites

config.cpp is for mods. If you want to modify the @j0nes   you need to contact the author. For a mission, you can define (and pre/postInit to make them start) them in the description.ext cfgFunctions  . You can also run them from init.sqf. Not sure you will see a great difference for performance, especially if you compile them in init.sqf. If you don't want to write the code in init field of the LHD, just name it and put your code in init.sqf replacing this by its name.

As said, repositioning the vehicle (setPos) is argument global/effect global, so no need to remoteExec this command.

 

Share this post


Link to post
Share on other sites

I have already contacted j0nes, and uploaded an updated standalone of his LHD modified to use the system the bi static carrier and destroyer use, instead of his scripts, which had some issues with enabling simulation in the editor, and helos/planes that were placed on the deck started flying, also its weapon systems overwrote the magazine defs for vanilla weapons, and for example, broke dynamic asraam loadouts. Also it didn't show up in the editor... 

 

Anyway, doing it from config.cpp causes no problems in multiplayer, and I need to add a loop (I really wish they had an event handler for viv loading/unloading)

Share this post


Link to post
Share on other sites

I downloaded the ATLAS LHD plus remastered. I guess it's the addon you mention. My question is: how do you refer to the "VIV" part of the LHD. It seems there is no room for vehicle at LHD (global objet) itself. So, for further help, and for other readers, that could be fine if you give some info about the use of this mod.

So far, I can act elevators, not the rear door, and I don't have any clue how to call the VIV.

Share this post


Link to post
Share on other sites

The Viv isn't present yet, I am trying to make one work

Share this post


Link to post
Share on other sites
On 11/25/2019 at 10:11 PM, Ex3B said:

The Viv isn't present yet, I am trying to make one work

I see your change on Steam workshop. Did you manage the class carrier like in BIKI (see also) or else?

The question is:    can getVehicleCargo apply?

Share this post


Link to post
Share on other sites

Yes, the class carrier is set up, and it works.

The issue was that unloading vehicles from the insert (like the boat rack for the destroyer, but much more capacity) would have them offload off the side of the ship, not on the deck, and thus it didn't work as an aircraft hangar, because unloading non amphibious vehicles sent them irrecoverably into the water. So while the VIV storage worked, it had no practical purpose with the unloading scripts.

At the moment, I think the scripts could be improved, and its a bit finicky to find the right spots on the deck to load a vehicle into the hangar through standard VIV (there's no script for loading, only the viv function)

Share this post


Link to post
Share on other sites

I have a look at your new class ATLAS_ViV_LHD_helper.

Perhaps, you should set configfile >> "CfgVehicles" >> "ATLAS_ViV_LHD_helper" >> "transportVehiclesCount" to 15 instead of 0 ?

 

For any script, you want to add:

In your config.cpp, add (or complete) the cfgFunctions class, for example:

class cfgFunctions {
  class MGI
  {
    class LHD_actions
    {
      class actionsMenu {postinit = 1;};
    };
  };
};

 

In your mod, add a sub-directory functions / sub-directory LHD_actions (i.e. root\functions\LHD_actions)

create an sqf, named:  fn_actionsMenu.sqf  (or else, similar to the function class you defined above), i.e.  <root>\functions\LHD_actions\fn_actionsMenu.sqf

Example: (working on any ViV like Blackfish, once your vehicle is loaded, so not yet on LHDViV)
 

Spoiler

 

fn_actionsMenu:


[] spawn {
    while {true} do {
        _ViVs = vehicles select {isNil {_x getVariable "isVIV"} && vehicleCargoEnabled _x};
        {
            _x setVariable ["isVIV",true];
            _x spawn {
              params ["_ViV","_cargoVehs","_embarkedIn","_unloadVehs","_disembarked"];
              _embarkedIn = "inside" + str (_ViV);
              while {alive _ViV} do {
              waitUntil {sleep 1; _cargoVehs = getVehicleCargo _ViV; count _cargoVehs >0 && {_cargoVehs findIf {isNil {_x getVariable _embarkedIn}} >-1}};
              {
                _x setVariable [_embarkedIn, _x addaction ["action (why not)", {
                     params ["_target","","_id","_cargoVehs"];
              private _ViV = isVehicleCargo _target;
              _displayNameViV = if (vehicleVarName _ViV isEqualTo "") then  [{if (name _ViV == "Error: No unit") then [{getText (configfile >> "CfgVehicles" >> typeOf _ViV >> "displayName")},{name _ViV}]},{vehicleVarName _ViV}];
              _displayNametgt =getText (configfile >> "CfgVehicles" >> typeOf _target >> "displayName");
                     hint format ["one %1 has been loaded at position nbr %2 of %3",_displayNametgt,(_cargoVehs findIf {_x == _target})+1,_displayNameViV];
                     _target removeAction _id
                     },
                     _cargoVehs,
                     1.5,
                     false,
                     true,
                     "",
                     "!isNull isVehicleCargo _target",
                     15
                ]];
              } forEach (_cargoVehs select {isNil {_x getVariable _embarkedIn}});
              waitUntil {sleep 1; _unloadVehs = getVehicleCargo _ViV; !(_unloadVehs isEqualTo _cargoVehs)};
              _disembarked = _cargoVehs - _unloadVehs;
              { _x removeAction (_x getVariable [_embarkedIn,-1]);
                _x setVariable [_embarkedIn,nil,true]
              } forEach _disembarked;
              };
            };
        } forEach _ViVs;
        uisleep 4;
    }
};

 

 

 

 

Share this post


Link to post
Share on other sites
10 hours ago, pierremgi said:

Perhaps, you should set configfile >> "CfgVehicles" >> "ATLAS_ViV_LHD_helper" >> "transportVehiclesCount" to 15 instead of 0 ?

Perhaps... but what does that actually do? It can load vehicles right now, far more than 15 if you stuff it with quadbikes.

I guess you are taking the number 15 from here:

https://community.bistudio.com/wiki/CfgVehicles_Config_Reference#transportVehiclesCount

But I'm of the "if it aint broke, don't fix it" mentality.

 

Quote

For any script, you want to add:

In your config.cpp, add (or complete) the cfgFunctions class, for example:

Why do I want to add this? what is broken that this fixes? It seems the scripts I have right now are working (although maybe I should decrease the sleep time from 10 seconds to something smaller, but I didn't want the script to run frequently and affect performance)

Share this post


Link to post
Share on other sites

I don't have any experience on building ViV like you do. What I'm sure, the transportSoldier is important for any vehicle and you can limit the available seats with that. That doesn't say transportVehiclesCount is mandatory, but... you can't say it's a huge fix. Keep it on mind if you want to play the full ViV engine like for Blackfish.

 

Your topic was: how to add an action in any vehicle in cargo. The "in cargo" suggested a ViV more than a simple location somewhere inside a structure. My bad.

Sorry for having suggesting you a way for adding a script (whatever it does) in your ViV mod. That seemed to me better than in an init field of a structure. I will not disturb you anymore now.

Share this post


Link to post
Share on other sites
On 11/28/2019 at 4:04 PM, pierremgi said:

I don't have any experience on building ViV like you do. What I'm sure, the transportSoldier is important for any vehicle and you can limit the available seats with that. That doesn't say transportVehiclesCount is mandatory, but... you can't say it's a huge fix. Keep it on mind if you want to play the full ViV engine like for Blackfish.

But what does it do? I'm curious.

Quote


Your topic was: how to add an action in any vehicle in cargo. The "in cargo" suggested a ViV more than a simple location somewhere inside a structure. My bad.

Well, I'm interested in that as well, because of issues unloading from a VIV such as the blackfish onto the LHD.

and my goal kind of drifted from the topic as I went further along.

Quote

Sorry for having suggesting you a way for adding a script (whatever it does) in your ViV mod. That seemed to me better than in an init field of a structure. I will not disturb you anymore now.

No need for apologies, I'm sorry if I was a bit rude. I'm just curious as to the thinking behind it. I'm very new to scripting, and want to understand why people do things certain ways.

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

×