Hello all,
In case anyone was wondering how to use it dynamically I have added some additional info / examples on the Wiki. There is a lot of information which I understood but some newbie scripters may be confused by it or thrown off by the vehicle template section. I was looking for a way to do it without that.
https://community.bistudio.com/wiki/BIS_fnc_initVehicle
See my comment at bottom.
I actually extracted a partial selection out of the BIS function to integrate into one of my own. This is the modified extraction part:
#define ANIM(veh, cfg, source, phase) \
if (getText (cfg >> "source") == "door") then \
{ \
veh animateDoor [source, phase, TRUE]; \
} else \
{ \
if (getNumber (cfg >> "useSource") == 1) then \
{ \
veh animateSource [source, phase, TRUE]; \
} else \
{ \
veh animate [source, phase, TRUE]; \
}; \
}
private _localData = _vehicle getVariable "bis_fnc_initVehicle_customization";
if (!is3DEN && !isNil {_localData}) then
{
_vehicle setVariable ["bis_fnc_initVehicle_customization", nil];
_variant = _localData param [0, _variant, ["STRING", FALSE, 0, []]];
_animations = _localData param [1, _animations, [[], FALSE, "STRING"]];
};
private _vehicleType = typeOf _vehicle;
private _skipRandomization = {_vehicleType isEqualTo _x || _vehicleType isKindOf _x || format ["%1", _vehicle] isEqualTo _x} count getArray (missionConfigfile >> "disableRandomization") > 0;
private _cfgAnimationSources = configFile >> "CfgVehicles" >> _vehicleType >> "AnimationSources";
private _allAnimationSourcesConfigs = "true" configClasses _cfgAnimationSources;
if !(_animations isEqualTo FALSE) then
{
private _animationList = getArray (configFile >> "CfgVehicles" >> _vehicleType >> "animationList");
private _resetAnimationSources = if (_animations isEqualType [] && {count _animations > 0 && {(_animations select 0) isEqualType true}}) then {[_animations] call BIS_fnc_arrayShift} else {true};
_resetAnimationSources = _resetAnimationSources && !is3DEN;
if (_resetAnimationSources) then
{
private _phase = -1;
private _phaseCurrent = -1;
private _source = "";
{
_source = configName _x;
_phaseCurrent = _vehicle animationPhase _source;
_phase = getNumber (_x >> "initPhase");
if (_phase != _phaseCurrent) then
{
ANIM(_vehicle, _x, _source, _phase);
};
}
forEach _allAnimationSourcesConfigs;
};
if (_animations isEqualTo TRUE) exitWith {TRUE};
if (!_skipRandomization && {_animations isEqualType "" || _variant isEqualType ""}) then
{
if (_variant isEqualType "") then
{
private _cfgVariant = configFile >> "CfgVehicles" >> _variant;
if (isClass _cfgVariant && {_animations isEqualTo "" || _animations isEqualTo []}) then
{
_animationList = getArray (_cfgVariant >> "animationList");
};
private _cfgVehicleTemplatesVariant = missionConfigFile >> "CfgVehicleTemplates" >> _variant;
if (isClass _cfgVehicleTemplatesVariant && {_animations isEqualTo "" || _animations isEqualTo []}) then
{
_animationList = getArray (_cfgVehicleTemplatesVariant >> "animationList");
};
};
if (_animations isEqualType "") then
{
private _cfgAnimationList = configFile >> "CfgVehicles" >> _animations >> "animationList";
if (isArray _cfgAnimationList) then
{
_animationList = getArray _cfgAnimationList;
};
private _cfgAnimationList = missionConfigFile >> "CfgVehicleTemplates" >> _animations >> "animationList";
if (isArray _cfgAnimationList) then
{
_animationList = getArray _cfgAnimationList;
};
};
};
if (_animations isEqualType [] && {count _animations > 1 && {count _animations mod 2 == 0 && {(_animations select 1) isEqualType 0}}}) then
{
_animationList = _animations;
};
if (count _animationList > 1) then
{
for "_i" from 0 to (count _animationList - 2) step 2 do
{
private _source = _animationList select _i;
private _forceAnimatePhase = getNumber (_cfgAnimationSources >> _source >> "forceAnimatePhase");
private _forceAnimate = getArray (_cfgAnimationSources >> _source >> "forceAnimate");
private _chance = _animationList select (_i + 1);
private _phase = if (random 1 <= _chance) then {1} else {0};
private _phaseCurrent = _vehicle animationPhase _source;
if (_forceAnimatePhase != _phase) then
{
_forceAnimate = getArray (_cfgAnimationSources >> _source >> "forceAnimate2");
_forceAnimatePhase = 1 - _forceAnimatePhase;
};
private _forceAnimateAllowed = _forceAnimatePhase == _phase && {_phase != _phaseCurrent && {count _forceAnimate >= 2}};
if (_phase != _phaseCurrent) then
{
ANIM(_vehicle, _cfgAnimationSources >> _source, _source, _phase);
};
if (_forceAnimateAllowed) then
{
private _forcedAnimName = "";
private _forcedAnimState = -1;
private _forcedAnimStateCurrent = -1;
private _forcedAnimIndex = -1;
for "_i" from 0 to (count _forceAnimate - 2) step 2 do
{
_forcedAnimName = _forceAnimate select _i;
_forcedAnimState = _forceAnimate select (_i + 1);
_forcedAnimStateCurrent = _vehicle animationPhase _forcedAnimName;
if (_forcedAnimState != _forcedAnimStateCurrent) then
{
ANIM(_vehicle, _cfgAnimationSources >> _forcedAnimName, _forcedAnimName, _forcedAnimState);
};
_forcedAnimIndex = _animationList find _forcedAnimName;
if (_forcedAnimIndex > -1) then
{
_animationList set [_forcedAnimIndex, _forcedAnimName];
_animationList set [_forcedAnimIndex + 1, _forcedAnimState];
};
};
};
};
{
private _source = configName _x;
private _phase = _vehicle animationPhase _source;
private _lockCargoAnimationPhase = getNumber (_x >> "lockCargoAnimationPhase");
private _lockCargo = getArray (_x >> "lockCargo");
{
_vehicle lockCargo [_x, _lockCargoAnimationPhase == _phase];
} forEach _lockCargo;
private _code = getText (_x >> "onPhaseChanged");
if (_code != "") then
{
[_vehicle, _phase] call compile _code;
};
} forEach _allAnimationSourcesConfigs;
};
};
https://community.bistudio.com/wiki/Vehicle_Customization_(VhC)