I really get headache from this. I try to make an addon to dynamically change viewdistance but i can't get it to work. It seems that scripts in addons behave completely different than any other scripts.
The error it throws:
'|#|' };
Error missing {
Thats all. After this, my PC completely locks up, alt+tab doesn't work nor ctrl+F4. Only Hardreset brings me back to work.
Ok, here what i have:
config.cpp:
class stm_dyn_vd
{
version[] = {};
dedicated[] = {};
class stm_dyn_vd
{
#include "\Dta\stm_dyn_vd_cfg.hpp"
};
};
class CfgPatches
{
class stm_dyn_vd
{
units[] = {};
weapons[] = {};
requiredVersion = 0.1;
requiredAddons[] = {"Extended_EventHandlers"};
};
};
class Extended_Init_EventHandlers
{
class CAManBase
{
stm_init = "_this exec ""\stm_dyn_vd\stm_scripts\stm_check.sqf""";
};
};
stm_dyn_vd_cfg.hpp
STM_minViewDistance = 2000; //Define min allowed viewdistance, it will not fall below this value
STM_maxViewDistance = 4000; //Define max allowed viewdistance, it will not raise above this value
STM_estFlightLevel = 1000; //Define at which height the maxViewDistance should be reached
STM_TargetFPS = 25; //Define min FPS where DYN_VD should start to reduce viewdistance to get back to playable FPS
STM_groundOffset = 0; //Define min player height before raising viewdistance
STM_configHint = 0; //Show Hints to find best settings, 1 = ON/0 = OFF
stm_check.sqf
_unit = _this select 0;
if (isPlayer _unit)then
{
STM_FPS_COUNTER = compile loadFile "\stm_dyn_vd\stm_scripts\stm_bench.sqf";
nil = [] execVM "\stm_dyn_vd\stm_scripts\stm_dyn_vd.sqf";
};
stm_bench.sqf
private["_c","_d"];
_c = time;
_d = 0;
while {!(time > (_c +0.25))} do
{
_d = _d +1;
sleep 0.001;
};
_d = ((_d * acctime)*4);
_d;
stm_dyn_vd.sqf
_STM_GRND_OFFSET = getNumber (configFile >> "stm_dyn_vd" >> "stm_dyn_vd" >> "STM_groundOffset");
_STM_MIN_DIST = getNumber (configFile >> "stm_dyn_vd" >> "stm_dyn_vd" >> "STM_minViewDistance");
_STM_MAX_DIST = getNumber (configFile >> "stm_dyn_vd" >> "stm_dyn_vd" >> "STM_maxViewDistance");
_STM_MAX_HEIGHT = getNumber (configFile >> "stm_dyn_vd" >> "stm_dyn_vd" >> "STM_estFlightLevel");
_STM_TARGET_FPS = getNumber (configFile >> "stm_dyn_vd" >> "stm_dyn_vd" >> "STM_TargetFPS");
_STM_CFG_HINT = getNumber (configFile >> "stm_dyn_vd" >> "stm_dyn_vd" >> "STM_configHint");
_STM_STEP_WIDTH = ((_STM_MAX_DIST - _STM_MIN_DIST) / _STM_MAX_HEIGHT);
_STM_VIEW_DIST = (_STM_MIN_DIST + (((getPosASL player select 2) - _STM_GRND_OFFSET)*_STM_STEP_WIDTH));
setViewDistance _STM_VIEW_DIST;
_STM_MIN_FPS = (_STM_TARGET_FPS - (_STM_TARGET_FPS / 10));
_STM_MAX_FPS = (_STM_TARGET_FPS + (_STM_TARGET_FPS / 10));
_STM_ASSUMED_VD = _STM_VIEW_DIST;
for [{_i=0}, {_i<10}, {_i=_i+1}] do
{
_STM_ACTUAL_FPS = [] call STM_FPS_COUNTER;
if (_STM_ACTUAL_FPS > _STM_MAX_FPS) then
{
_STM_ACT_PLR_LVL = floor((getPosASL player select 2) - _STM_GRND_OFFSET);
_STM_ASSUMED_VD = (_STM_MIN_DIST + (_STM_ACT_PLR_LVL * _STM_STEP_WIDTH));
if (_STM_ASSUMED_VD > _STM_VIEW_DIST) then
{
_STM_VIEW_DIST = _STM_VIEW_DIST + (_STM_STEP_WIDTH * (sqrt _STM_ACTUAL_FPS));
if (_STM_VIEW_DIST > _STM_MAX_DIST) then
{
_STM_VIEW_DIST = _STM_MAX_DIST;
};
};
if (_STM_ASSUMED_VD < _STM_VIEW_DIST) then
{
_STM_VIEW_DIST = _STM_VIEW_DIST - (_STM_STEP_WIDTH * (sqrt _STM_ACTUAL_FPS));
if (_STM_VIEW_DIST < _STM_MIN_DIST) then
{
_STM_VIEW_DIST = _STM_MIN_DIST;
};
};
};
if (_STM_ACTUAL_FPS < _STM_MIN_FPS) then
{
_STM_VIEW_DIST = _STM_VIEW_DIST - (_STM_STEP_WIDTH * (sqrt _STM_ACTUAL_FPS));
if (_STM_VIEW_DIST < _STM_MIN_DIST) then
{
_STM_VIEW_DIST = _STM_MIN_DIST;
};
};
setViewdistance _STM_VIEW_DIST;
if (_STM_CFG_HINT == 1) then
{
hint format ["FPS: %1\nViewdistance: %2 Meter\nTarget VD: %3", _STM_ACTUAL_FPS, _STM_VIEW_DIST, _STM_ASSUMED_VD];
};
_i = 0;
};
This all i got in there. The folders are named properly as written in the config.
The scripts worked when directly used in the editor (so not in an addon), only thing i've changed was to define the values from the .hpp file directly in the stm_dyn_vd.sqf since the .hpp file was not loaded at this point of testing.
Anything else remained as it was (except script path to folder).
If anyone can see where the error is...please point me to it.
Myke out