Jump to content
Sign in to follow this  
mrcurry

Automatic VAS activation script

Recommended Posts

First off, credits to Tonic for making a great load-out script. I tip my virtual hat to you, good sir.

The other week I wrote together a short script for my clan's internal scripting library to make it easier to use VAS in ZGM missions. It turned out to work pretty sweet for all mission types so I thought why keep it to ourselves, might as well share it here.

See description below on how it works. At the bottom you find the entire file. If you got any questions or find any bugs, fire away.

Note: Script does not come with VAS, but VAS is required.

Link: VAS on Armaholic

/[EVO]Curry

Description:

File: fn_autoVAS.sqf

Name: Automatic VAS activation script

Author: [EVO]Curry

Date: 2014-05-31

Your are allowed to use, distribute and modify this script at will on the condition that the original author is given due credit.

Description:

AutoVAS makes the usage of VAS dynamic and require no pre-setup of objects. It scans the player's surroundings for objects that

logically would provide gear (default: ammotrucks and ammoboxes). If a valid source of gear is found it adds an action to the player so he/she/it can use VAS, all on the fly.

If the object is removed or destroyed while the VAS is in use the window is closed and the action is removed.

AutoVAS does not apply any changes to VAS and all ordinary VAS customization is still available.

The script was originally designed with Zeus GM sessions in mind but it can also make the making of other missions easier.

AutoVAS can function in 2 modes, "direct" and "proximity".

In "direct" mode the player must look at the object in question (like the normal action) while in "proximity" mode it is enough that the player is near the object.

Usage:

[] execVM "fn_autoVAS.sqf";

or

[(title, mode, allowed, disallowed, maxdist, leavecloses)] execVM "fn_autoVAS.sqf";

Parameters:

All parameters are optional.

_title - String - Title shown in the action, supports same tags as addAction command. Default:"<t color='#ff5555'>Open VAS</t>"

_mode - String - Scanning mode, can be either "direct" or "proximity". Default: "proximity"

_allowed - Array of strings - Allowed classnames, provide [] for default behaviour, if the first element of this array is "+" the following strings will be used in addition to the default ones. Default: Ammoboxes and ammotrucks

_disallowed - Array of strings - Disallowed classnames, provide [] for default behaviour. Default: None

_maxDist - Scalar - Maximum distance you can be from the an object to get the action. Recommended value: 7 or above. Default: 7 m

_leaveCloses - Boolean - If true closes the VAS window if the object leaves the player's range and/or focus. Default: true

Requirements:

Virtual Ammobox System (VAS) by Tonic.

Other:

You can use setVariable ["EVO_autoVAS_enabled", true/false] on objects to force autoVAS to detect or ignore them. Examples below.

This will enable autoVAS for aCar no matter if its a valid class or not:

aCar setVariable ["EVO_autoVAS_enabled", true];

This will make autoVAS ignore aCar, even if its of a valid class:

aCar setVariable ["EVO_autoVAS_enabled", false];

To default back to standard behaviour for aCar you can use:

aCar setVariable ["EVO_autoVAS_enabled", nil];

Code:

/*
File: fn_autoVAS.sqf
Name: Automatic VAS activation script
Author: [EVO]Curry
Date: 2014-05-31
Your are allowed to use, distribute and modify this script at will on the condition that the original author is given due credit.

Description:
AutoVAS makes the usage of VAS dynamic and require no pre-setup of objects. It scans the player's surroundings for objects that 
logically would provide gear (default: ammotrucks and ammoboxes). If a valid source of gear is found it adds an action to the player so he/she/it can use VAS, all on the fly.
If the object is removed or destroyed while the VAS is in use the window is closed and the action is removed.

AutoVAS does not apply any changes to VAS and all ordinary VAS customization is still available.
The script was originally designed with Zeus GM sessions in mind but it can also make the making of other missions easier.

AutoVAS can function in 2 modes, "direct" and "proximity".
In "direct" mode the player must look at the object in question (like the normal action) while in "proximity" mode it is enough that the player is near the object.

Usage:
[] execVM "fn_autoVAS.sqf";
or
[(title, mode, allowed, disallowed, maxdist, leavecloses)] execVM "fn_autoVAS.sqf";

Parameters:
All parameters are optional.
_title		-	String 				- Title shown in the action, supports same tags as addAction command. Default:"<t color='#ff5555'>Open VAS</t>"
_mode 		-	String 				- Scanning mode, can be either "direct" or "proximity". Default: "proximity"
_allowed	-	Array of strings		- Allowed classnames, provide [] for default behaviour, if the first element of this array is "+" the following strings will be used in addition to the default ones. Default: Ammoboxes and ammotrucks
_disallowed	-	Array of strings		- Disallowed classnames, provide [] for default behaviour. Default: None
_maxDist 	-	Scalar				- Maximum distance you can be from the an object to get the action. Recommended value: 7 or above. Default: 7 m
_leaveCloses	-	Boolean				- If true closes the VAS window if the object leaves the player's range and/or focus. Default: true

Requirements: 
Virtual Ammobox System (VAS) by Tonic.

Other:
You can use setVariable ["EVO_autoVAS_enabled", true/false] on objects to force autoVAS to detect or ignore them. Examples below.

This will enable autoVAS for aCar no matter if its a valid class or not:
aCar setVariable ["EVO_autoVAS_enabled", true]; 

This will make autoVAS ignore aCar, even if its of a valid class:
aCar setVariable ["EVO_autoVAS_enabled", false]; 

To default back to standard behaviour for aCar you can use:
aCar setVariable ["EVO_autoVAS_enabled", nil]; 

Pseudo code:
if VAS enabled and autoVAS not running
define valid types
determine mode function

always do 
	sleep 0.5s
	with selected mode find objects of valid type within max distance
	if any objects found then
		if action not added then
			add action 
			save actionId
	else if no objects found
		if actionId saved then
			remove action
			if close on leave then
				close VAS
*/	

#define IS_VALID(var) ([var, _validClasses, _disallowed] call _isValid)
private ["_mode", "_maxDist", "_leaveCloses", "_disallowed"];
_title			= [_this, 0, "<t color='#ff5555'>Open VAS</t>", [""]] call BIS_fnc_param;
_mode 			= [_this, 1, "direct",[""]] call BIS_fnc_param;
_allowed		= [_this, 2, [], [[]]] call BIS_fnc_param;
_disallowed		= [_this, 3, [], [[]]] call BIS_fnc_param;
_maxDist 		= [_this, 4, 7, [0]] call BIS_fnc_param;
_leaveCloses	= [_this, 5, true, [false]] call BIS_fnc_param;

_defaultClasses = [
"ReammoBox_F",
"B_Truck_01_ammo_F",
"O_Truck_02_Ammo_F",
"I_Truck_02_Ammo_F",
"O_Truck_03_Ammo_F",
"B_APC_Tracked_01_CRV_F"
];

if(isClass (missionConfigFile >> "VAS_Diag") && !isDedicated && isNil "EVO_autoVAS_isRunning") then {
EVO_autoVAS_isRunning = true;
diag_log "autoVAS running...";
private ["_validClasses", "_isValid", "_findObjects"];
_validClasses = if(count _allowed > 0) then {
	if ((_allowed select 0) == "+") then {
		private ["_newAllowed"];
		_newAllowed = +_allowed;
		_newAllowed set [0,-1];

		_defaultClasses + (_newAllowed-[-1])
	} else {
		_allowed
	}	
} else { 
	_defaultClasses
};

//Function: check if provided object is valid
_isValid = {
	private ["_o", "_v", "_iv", "_c", "_ov", "_rc", "_inv", "_i", "_iniv"];
	_o		= _this select 0;
	_v 		= _this select 1;
	_iv 	= _this select 2;
	_c		= typeOf _o;

	_ov = _o getVariable "EVO_autoVAS_enabled";


	if(alive _o) then {
		_rc = isNil "_ov";
		if(_rc) then {
			_inv 	= false;
			_i 		= 0;
			while {!_inv && _i < count _v} do {
				_inv = _c isKindOf (_v select _i);
				_i = _i + 1;
			};

			_iniv 	= false;
			_i 		= 0;
			while {!_iniv && _i < count _iv} do {
				_iniv = _c == (_iv select _i);
				_i = _i + 1;
			};

			_ov = (_inv && !_iniv);
		};
	} else {
		_ov = false;
	};

	_ov
};

//Function: find valid objects
_findObjects = switch (toLower _mode) do {
	case "direct": {
		{
			private ["_r"];
			_r = [];
			if(!isNull cursorTarget) then {

				_pPos = [getPos player select 0, getPos player select 1];
				_tPos = [getPos cursorTarget select 0, getPos cursorTarget select 1];
				if((_pPos distance _tPos) < (_this select 1)) then {
					if(IS_VALID(cursorTarget)) then {
						_r set [0, cursorTarget];
					};
				};
			};

			_r
		}
	};
	case "proximity": {
		{
			private ["_n"];
			_n = (getPos (_this select 0)) nearObjects (_this select 1);
			{
				if(!IS_VALID(_x)) then {
					_n set [_forEachIndex, -1];
				};
			} forEach _n;
			_n = _n - [-1];
			_n
		}
	};
	default {
		compile format ["[""autoVAS - Invalid mode parameter: %1"", ""%2""] call BIS_fnc_error; []","%1",_mode]
	};
};

private ["_actionID"];
while {true} do {
	sleep 0.5;
	_objs = [player, _maxDist] call _findObjects;
	if(count _objs > 0) then {
		if(isNil "_actionID") then {
			_actionID = player addAction [_title,"VAS\open.sqf"];
		};
	} else {
		if(!isNil "_actionID") then {
			player removeAction _actionID;
			_actionID = nil;
			if(_leaveCloses) then {
				closeDialog 2500;
			};
		};
	};
};
} else {
hint "autoVAS failed to load...\nVAS not present.";
};

Edited by mrCurry
Formatting and typos

Share this post


Link to post
Share on other sites

exactly what i was looking for !! thx for this useful VAS add-on

Share this post


Link to post
Share on other sites

Awesome add on, thanks!

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  

×