target_practice 163 Posted June 25, 2016 I've looked around and found a bunch of threads on installing functions in missions, but none seem to answer the question of how to get around the initialization order problem. Although (I believe) the obvious way to add a function from a mission folder is to include an execVM line for its file in the init.sqf, but init fields are executed before the init.sqf. So is there a way to deal with this? Share this post Link to post Share on other sites
killzone_kid 1331 Posted June 25, 2016 What initialisation order problem? If function is defined in CfgFunctions it is available in object init field. Share this post Link to post Share on other sites
ozdeadmeat 12 Posted June 25, 2016 How are you declaring the function? Have a look here specificly the attribute section. There is an option called preInit. Make sure when you declare your function that you enabled that switch and you should be all good. Let us know if your still having problems. Share this post Link to post Share on other sites
target_practice 163 Posted June 25, 2016 What initialisation order problem? If function is defined in CfgFunctions it is available in object init field. I should clarify that it is a custom function, one of yours in fact. Share this post Link to post Share on other sites
kylania 568 Posted June 25, 2016 Here's a really quick demo showing how to set up the Functions library and how not to use init.sqf/initServer.sqf functions for what you're trying to do. There are three functions in the demo, all with the same code. fnc_removeLauncher_InitServer declared in initServer.sqf, fnc_removeLauncher declared in init.sqf and tp_fnc_removeLauncher declared via the Functions library. The PMCL AT Rifleman on the left is using the fnc_removeLauncher_InitServer function from it's init field to remove it's launcher. Clearly this didn't work. :) Same for the AA Missile Specialist in the middle. His function was declared in the init.sqf. Only the AT Missile Specialist on the left lost his launcher because the function called from his init field was declared in CfgFunctions. This also shows how to have a preInit file with multiple common functions instead of a file per function. We disable stamina from initPlayerLocal.sqf using a common function to allow you to run around with 15 explosive charges in your backpack. Also we declare a function to allow you to steal a loadout from other units via addAction. This is a bit more verbose then it needs to be, but helps keep things organized. To get the Functions Library going: description.ext: class CfgFunctions { #include "functions\cfgFunctions.hpp" }; functions\cfgFunctions.hpp: class TargetPracticeFunctions { tag = "tp"; // Functions tag. Functions will be called as [] call tp_fnc_chooseMission class coreFunctions { // Since these are called from a file they'll be called by their names in the file, ie, fnc_tp_disableStamina class coreFunctions {file = "functions\coreFunctions.sqf"; description = "core functions, called on mission start."; preInit = 1;}; }; class functions { file = "functions"; // Folder where individual function files are stored. class removeLauncher {}; // File name is functions\fn_removeLauncher.sqf }; }; functions\coreFunctions.sqf: // Disable Stamina tp_fnc_core_disableStamina = { params ["_unit"]; _unit enableStamina false; }; // Copy gear from a unit tp_fnc_core_copyGear = { params["_object", "_caller", "_id", "_args", "_copyFrom","_loadout"]; _copyFrom = cursorTarget; if (!(_copyFrom isKindOf "Man")) exitWith {}; _loadout = getUnitLoadout _copyFrom; _caller setUnitLoadout _loadout; hint format["You copied %1's gear.", name _copyFrom]; }; (Disable stamina is called from initPlayerLocal.sqf while the copy gear function is called from an addAction in the player's init field.) functions\fn_removeLauncher.sqf: params["_unit"]; _weapon = secondaryWeapon _unit; _unit removeWeapon _weapon; So removeLauncher was called via: [_this] call tp_fnc_removeLauncher; and stamina disable was called via: [_this] call tp_fnc_core_disableStamina; To add more functions you'd just add a new line to your cfgFunctions.cfg and a new functions\fn_stuffInventoryWithPistolMags.sqf file. class stuffInventoryWithPistolMags {}; // File name is functions\fn_stuffInventoryWithPistolMags.sqf Thanks to a tip from Larrow I've refactored this to match his suggestion. 1 Share this post Link to post Share on other sites
killzone_kid 1331 Posted June 25, 2016 I should clarify that it is a custom function, one of yours in fact. You can still define it in CfgFunctions, in which case it will be compiled before mission is started so it will be available in object init. Share this post Link to post Share on other sites