Jump to content
Sign in to follow this  
Igitur

BIS_fnc_loadFunctions

Recommended Posts

Hi all,

Is there an official way of loading a simple script addon on game start ? I thought this BIS function would do the trick, but it's not clear at all (to me) how it works :

//A3\functions_f\Variables\fn_loadFunctions.sqf

/*

Author: Karel Moricky

Description:

Compile scripts and save them into globally available functions.

Parameter(s):

0: STRING - script path

1: STRING - variable prefix

2: ARRAY - list of variables to be declared. Elements can be of following types:

variable: STRING - variable is (prefix + variable), loaded from (path + variable + ".sqf")

[variable:STRING,fileName:STRING] - variable is (prefix variable), loaded from (path + fileName + ".sqf")

3: BOOL - true for global persistent execution on all clients

Returns:

BOOL

*/

private ["_path","_variables","_globalExec","_variable","_fileName"];

_path = [_this,0,"",[""]] call bis_fnc_param;

_prefix = [_this,1,"",[""]] call bis_fnc_param;

_variables = [_this,2,[],[[]]] call bis_fnc_param;

_globalExec = [_this,3,true,[false]] call bis_fnc_param;

if (_prefix == "BIS_fnc_") then {_prefix = ""; ["Prefix 'BIS_fnc_' is reserved for functions."] call bis_fnc_error;};

{

_variable = [_x,0,"",[""]] call bis_fnc_paramin;

_fileName = [_x,1,_variable,[""]] call bis_fnc_paramin;

if (_variable != "" && _fileName != "") then {

_file = format ["scriptname '%1'; private '_fnc_scriptName'; _fnc_scriptName = '%1';",_prefix + _variable] + preprocessfilelinenumbers (_path + _fileName + ".sqf");

missionnamespace setvariable [_prefix + _variable,compileFinal _file];

};

} foreach _variables;

//--- Global execution

if (ismultiplayer && isserver && _globalExec) then {

[

[_path,_prefix,_variables,false],

_fnc_scriptName,

true,

true,

true

] call bis_fnc_mp;

};

true

How can i use that function to hook my script, if not from another script ? Should I call it from the mod.cpp ? Any other file ? And what's the syntax to be used ?

Thanks in advance for your help :)

Share this post


Link to post
Share on other sites
. . . Is there an official way of loading a simple script addon on game start ? . . .

You may want to dabble with the different attributes that cfgFunctions offers, instead of using BIS_fnc_loadFunctions. Such as the preInit and postInit parameters. I've provided a simplified example of how to setup cfgFunctions. It's how I handle functions and it's clean. Hope that helps.

description.ext

class CfgFunctions 
{
   #include "functions.hpp"
};  

functions.hpp

class ICE
{
   class stuff
   {
       file = "functions";
	class myFunction           {};
	class myOtherFunction      {};
       class myInitFunction       {postInit = 1}; // To call the function upon mission start, after objects are initialized. Passed arguments are ["postInit"]

   };
};  

fn_myFunction.sqf

/*
call ICE_fnc_myFunction
*/

hint "This is my function.";

fn_myOtherFunction.sqf

/*
call ICE_fnc_myOtherFunction
*/

hint "This is my other function.";

fn_myInitFunction.sqf

/*
call ICE_fnc_myInitFunction << Only as needed, as we are already using postInit to call this function at mission start.
*/

hint "This is my init function. It will be ran at mission start since I used postInit = 1.";

Kind Regards,

Iceman77

Edited by Iceman77

Share this post


Link to post
Share on other sites

Thank you guys for the replies.

I'm currently using CBA's preInit EH to load the scripts on game launch and make them work as addons. It does work pretty well (but, for some reason, not on a "group" type respawn). The only problem i have with CBA dependancy is err.. the dependancy and, since i'm not using any other CBA function, i thought i should find a more standardized method. Hence my question.

Iceman, I'll check out your ideas when i'm back from work and try using CfgFunctions instead of CfgPatches. The exemples you provide are very interesting. Thanks a lot for your time :)

Best regards,

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  

×