Jump to content
jakkob4682

Two questions. Cargo capacity.... And check if group is loaded/unloaded.

Recommended Posts

Not good with config commands so trying to check if vehicle has enough cargo space for a group.  Then check if group is loaded/unloaded.

 

Please and thank you.

Share this post


Link to post
Share on other sites

So trigger condition for a group.

{vehicle _x == _x}forEach units _grp? And vice versa?

Share this post


Link to post
Share on other sites

For the first question. You can use what gc8 suggested and try something along with the examples of the docs. Something like

// Get the number of free positions in the cargo space of the vehicle
private _numOfFreePos = _veh emptyPositions "cargo";

Here  _veh is supposed to be the vehicle of interest. This way you can see if there are empty positions in the cargo space of the vehicle of interest.

 

For the second question. The way gc8 suggests is most often enough. If you want to go "safe" and "more generic" you should use objectParent command. This is faster and will return the vehicle even if the unit is dead (which is not the case for the command vehicle). So, to check if all units are inside a vehicle you could do

// Create a flag variable to check for loaded group
private _isLoaded = true; // Set to true

{
	// Check if return of objectParent is null which means that the unit is on foot
	if(isNull objectParent _x) exitWith {
		_isLoaded = false; // Make the variable false (not the whole group loaded) and stop iterations
	};
} forEach _grp;

Here _grp is the group you want to check for being loaded.

  • Like 1

Share this post


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

So trigger condition for a group.

{vehicle _x == _x}forEach units _grp? And vice versa?

 

To check if all units of group yourGroup are in some vehicle:

 

{vehicle _x != _x} count (units yourGroup) == (count (units yourGroup))

 

  • Like 1

Share this post


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

For the first question. You can use what gc8 suggested and try something along with the examples of the docs. Something like


// Get the number of free positions in the cargo space of the vehicle
private _numOfFreePos = _veh emptyPositions "cargo";

Here  _veh is supposed to be the vehicle of interest. This way you can see if there are empty positions in the cargo space of the vehicle of interest.

 

For the second question. The way gc8 suggests is most often enough. If you want to go "safe" and "more generic" you should use objectParent command. This is faster and will return the vehicle even if the unit is dead (which is not the case for the command vehicle). So, to check if all units are inside a vehicle you could do


// Create a flag variable to check for loaded group
private _isLoaded = true; // Set to true

{
	// Check if return of objectParent is null which means that the unit is on foot
	if(isNull objectParent _x) exitWith {
		_isLoaded = false; // Make the variable false (not the whole group loaded) and stop iterations
	};
} forEach _grp;

Here _grp is the group you want to check for being loaded.

the forEach should be forEach units _grp though right?

  • Like 1

Share this post


Link to post
Share on other sites
params ["_grp","_veh","_wpPos"];

{
	_x assignAsCargo _veh;
	_x orderGetIn _veh;
}forEach units _grp;

_inVehicle = true;
{
	if(isNull objectParent _x)then
	{
		exitWith
		{
			_inVehicle = false;
		};
	};
forEach units _grp;

waitUntil{_inVehicle};
_dropPos = (group _veh) addWaypoint [_wpPos,1];
_dropPos setWaypointType "TR UNLOAD";
_dropPos setWaypointSpeed "FULL";

waitUntil{{vehicle _x != _x}forEach units _grp};
[_grp,getMarkerPos "patrol",300] call BIS_fnc_taskParent;

 

Share this post


Link to post
Share on other sites
44 minutes ago, jakkob4682 said:

the forEach should be forEach units _grp though right?

Yeah yeah, I am sorry, I missed that one but yes, it should be units _grp.

 

Additionally, you could skip initialisation of the _inVehicle variable as forEach returns the last statement executed. This means you could do something like

// Assign the last executed statement of forEach to the variable
private _inVehicle = {
	if(isNull objectParent _x) exitWith {false}; // The scope will exit and return false
	true; // The scope will exit and return true
} forEach units _grp;

Also, I think that the correct statement is if() exitWith{} instead of the one you have in your code above which is if() then {exitWith{}} (for more info see here).

 

Additionally, your waitUntil will never evaluate to true because the above forEach statement is not executed repeatedly. This means that the value of _inVehicle will never change after the end of the above forEach loop. In order to make this work, you should wrap the forEach loop into the waitUntil. In this way, you could also save the use of a variable like _inVehicle in this way

// waitUntil won't stop until the last statement is true
waitUntil {
	// Wait for a while before checking again to save some CPU cycles
	sleep 2;

	{
		if(isNull objectParent _x) exitWith {false}; // The scope will exit and return false
		true; // The scope will exit and return true
	} forEach units _grp;
};

Just one point to make here. I am not sure whether you can place the sleep command after the forEach loop. In my understanding, the last executed command is what determines whether waitUntil will terminate or not. This means that most probably the sleep command cannot be last in the way the code is written. Please take some time to test that (I cannot test it as I do have access to ArmA at the moment).

 

Please, give some attention to the last code provided by gc8 as this could also be used to see whether everyone is in the vehicle. You can use count command (see the docs) to count how many people are not in the vehicle (you could also check how many there are in the vehicle but in the other way you don't have to know, or find out, the number of people in the group to compare against). You could do something like

waitUntil {
	// Sleep a while to save some CPU
	sleep 2;

	// Count how many are NOT in the vehicle
	({isNull objectParent _x} count (units _grp)) isEqualTo 0;
};

This may be faster than the previous snippets since count is a system command and will most probably execute faster than the forEach loop. I haven't really tested it and this is just speculation though, so you will have to do some benchmarking if you are interested in speed.

 

Another way, which may be faster is with findIf (see also example 2) which will stop searching if its condition returns true. In this way you won't have to search through all the array in case even one of the units is not in the vehicle. An example is

waitUntil {
	// Check whether findIf returns -1 (which means it didn't find something to match the condition)
	((units _grp) findIf {isNull objectParent _x}) isEqualTo -1;
};

Finally, please keep in mind that none of the presented code snippets checks whether the units are inside THE SAME vehicle. All they do is to check if they are on foot! If the need arises to check that they are in a vehicle or even in the same vehicle you should adapt the code.

 

Hope this helps here, but if it doesn't or you have more questions please don't hesitate to ask.

Share this post


Link to post
Share on other sites

yes this has helped a lot thank you.  Trying to incorporate this into a system that sets variables so something like

//setVariable command - _veh setVariable ["cargoSpace",_cargospace] where cargo space is available room in vehicle
//setVariable for groups _grp setVariable ["ready",_inVehicle] 
//setVariable for in-transit _veh setVariable ["moving",true]

how do I set a default value to params?

params ["_height","_speed","_cMode"];
//if(isNil _this select 0)then{_this select 0 = 300}else{_this select 0 = _this}?

 

Share this post


Link to post
Share on other sites
24 minutes ago, jakkob4682 said:

Trying to incorporate this into a system that sets variables so something like

Well, if you get the values you need then it's quite straight forward to incorporate it into your system.

 

25 minutes ago, jakkob4682 said:

how do I set a default value to params?

Setting default values to parameters is quite easy. All you have to do is something like

params[["_paramOne", 0], // Number
       ["_paramTwo", -5.5], // Another number
       ["_paramThree", "A string parameter"], // String
       ["_paramFour", player], // Object (the player)
       ["_paramFive", objNull]]; // Null object

The comments next to the parameters define the type of the default value.

 

Please keep in mind that the parameters may have any type if they are set this way. In order to define the types that each parameter can take you will have to use the following syntax

params[["_paramOne", 0, [0]], // Only numbers are allowed
       ["_paramTwo", -5.5, [0, ""]], // Only numbers and strings are allowed
       ["_paramThree", "A string parameter", [""]], // Only strings allowed
       ["_paramFour", player, []], // Any data type is allowed
       ["_paramFive", objNull, [objNull]]]; // Object data types allowed only

Keep in mind that if the type of the passed parameter does not match the allowed types the default value will be given. For more info on the command look at the docs.

Share this post


Link to post
Share on other sites

Can you explain scheduled vs unscheduled please?  Tried reading the biki on it but it lost me when it started getting into post/pre init.

 

Again thank you 

Share this post


Link to post
Share on other sites
43 minutes ago, jakkob4682 said:

Can you explain scheduled vs unscheduled please?  Tried reading the biki on it but it lost me when it started getting into post/pre init.

 

Again thank you 

I will PM you because this is out of topic here...

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

×