Advertisement
Guest User

hopefully

a guest
Feb 9th, 2014
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. scriptName "Functions\init.sqf";
  2. textLogFormat ["PRELOAD_ Functions\init.sqf %1", _this];
  3. /*
  4. File: init.sqf
  5. Author: Karel Moricky
  6.  
  7. Description:
  8. Function library initialization.
  9. All files have to start with 'fn_' prefix and they name have to be same as name of function.
  10. Don't forget to exclude comma after last item in array!
  11.  
  12. Caution:
  13. Do not execute this init directly - there is dependency with MPF and need to run on all machines.
  14.  
  15. Parameter(s):
  16. _this select 0: 'Function manager' logic
  17.  
  18. Returns:
  19. Nothing
  20. */
  21.  
  22. if (!isServer) then {textLogFormat ["MPF_Client FUNCTIONS init.sqf ..."];};
  23.  
  24. private ["_recompile"];
  25. _recompile = (count _this) > 0;
  26.  
  27. //--- Functions are already running
  28. if ((!isNil "BIS_fnc_init") && !_recompile) exitwith {textLogFormat["PRELOAD_ Functions already running."];};
  29. textLogFormat ["Log: [Functions] Init script executed at %1",time];
  30.  
  31.  
  32. //--------------------------------------------------------------------------------------------------------
  33. //--- PREPROCESS -----------------------------------------------------------------------------------------
  34. //--------------------------------------------------------------------------------------------------------
  35.  
  36. //--- Create variables for all functions (and preprocess them after first call)
  37. for "_t" from 0 to 2 do {
  38. _pathConfig = [configfile,campaignconfigfile,missionconfigfile] select _t;
  39. _pathFile = ["ca\modules\functions","functions","functions"] select _t;
  40.  
  41. _cfgFunctions = (_pathConfig >> "cfgfunctions");
  42. for "_c" from 0 to (count _cfgFunctions - 1) do {
  43. _currentTag = _cfgFunctions select _c;
  44.  
  45. //--- Is Tag
  46. if (isclass _currentTag) then {
  47. _tagName = configname _currentTag;
  48. _itemPathTag = gettext (_currentTag >> "file");
  49.  
  50. for "_i" from 0 to (count _currentTag - 1) do {
  51. _currentCategory = _currentTag select _i;
  52.  
  53. //--- Is Category
  54. if (isclass _currentCategory) then {
  55. _categoryName = configname _currentCategory;
  56. _itemPathCat = gettext (_currentCategory >> "file");
  57.  
  58. for "_n" from 0 to (count _currentCategory - 1) do {
  59. _currentItem = _currentCategory select _n;
  60.  
  61. //--- Is Item
  62. if (isclass _currentItem) then {
  63.  
  64. _itemName = configname _currentItem;
  65. _itemPathItem = gettext (_currentItem >> "file");
  66. _itemPath = if (_itemPathItem != "") then {_itemPathItem} else {
  67. if (_itemPathCat != "") then {_itemPathCat + "\fn_" + _itemName + ".sqf"} else {
  68. if (_itemPathTag != "") then {_itemPathTag + "\fn_" + _itemName + ".sqf"} else {""};
  69. };
  70. };
  71. _itemPath = if (_itemPath == "") then {_pathFile + "\" + _categoryName + "\fn_" + _itemName + ".sqf"} else {_itemPath};
  72. call compile format ["
  73. if (isnil '%2_fnc_%3' || %4) then {
  74. %2_fnc_%3 = {
  75. if (!%4) then {debuglog ('Log: [Functions] %2_fnc_%3 loaded (%1)')};
  76. %2_fnc_%3 = compile preprocessFileLineNumbers '%1';
  77. _this call %2_fnc_%3;
  78. };
  79. %2_fnc_%3_path = '%1';
  80. };
  81. ",_itemPath,_tagName,_itemName,_recompile];
  82. };
  83. };
  84. };
  85. };
  86. };
  87. };
  88. };
  89.  
  90. //"
  91.  
  92. private ["_test", "_test2"];
  93. _test = (_this select 0) setPos (position (_this select 0)); if (isnil "_test") then {_test = false};
  94. _test2 = (_this select 0) playMove ""; if (isnil "_test2") then {_test2 = false};
  95. _testvar = getText (configFile >> "CfgMissions" >> "Missions" >> "SP_BearRising" >> "directory");
  96. if (_testvar != "") then {
  97. (_test || _test2) call (compile (preprocessFileLineNumbers "ca\modules\functions\fn_initCounter.sqf"));
  98. } else { // Player has A2 Free
  99. if (_test || _test2) then {0 call (compile (preprocessFileLineNumbers "ca\modules\functions\misc\fn_initCounter.sqf"))};
  100. };
  101.  
  102. //--------------------------------------------------------------------------------------------------------
  103. //--- INIT COMPLETE --------------------------------------------------------------------------------------
  104. //--------------------------------------------------------------------------------------------------------
  105.  
  106. waitUntil {!isNil "BIS_MPF_InitDone"}; //functions init must be after MPF init
  107. BIS_fnc_init = true;
  108.  
  109.  
  110. //if ((missionStart select 0) != 0) then {endLoadingScreen;textLogFormat["PRELOAD_ HACK isServer %1 endLoadingScreen (init functions EH)", isServer];}; //TODO:FIXME:HACK: - in multiplayer game freezes because init.sqf is not launched in MP preload
  111.  
  112.  
  113.  
  114. textLogFormat ["Log: [Functions] Init script terminated at %1",time];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement