Jump to content
Sign in to follow this  
BEAKSBY

How to configure a functions library (CfgFunctions)?

Recommended Posts

Thanks SilentSpike...

...but there is nothing specifically on setting-up CfgFunctions.HPP. I'm not sure where to place the following, or what file name or type should be, as per the the link above

class CfgFunctions{
class myTag
{
};
class Anything
{
	tag = "myTag"; // Custom tag name
	requiredAddons[] = {"A3_Data_F"}; // Optional requirements of CfgPatches classes. When some addons are missing, functions won't be compiled.
};
};

Based on previous examples I've created this but not sure if this is correct.

1) I've created a folder called "functions" in my mission folder.

then added to it: another folder called "subfolder" and

CfgFunctions.HPP

class BEAKS
{
class subfolder
{
	class RepairRearmFlip;
	class unitStatusCost;

};
};

2) inside "subfolder" I've added my functions as: fn_RepairRearmFlip.sqf , fn_unitStatusCost.sqf

3) In my scripts I call or spawn these functions as for example:

_return = [cursortarget] call BEAKS_fnc_unitStatusCost;

and...

[_return select 0, _return select 1] spawn BEAKS_fnc_RepairRearmFlip;

Am I on the right track?

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Excuse me, I totally missed that the link in your original post was to the same page :p

Should really stop posting when my attention is so low. Never dealt with CfgFunctions.hpp personally, but by looking at a view distance dialogue archive I have I see this.

class TAWVD
{
tag = "TAWVD";
class TAW_VD
{
	file = "taw_vd";
	class onSliderChange {};
	class onTerrainChange {};
	class updateViewDistance {};
	class openTAWVD {};
	class trackViewDistance {};
	class tawvdInit {postInit = 1;};
};
};

"file" is the directory where all the functions are (in this case the functions are all in a folder named taw_vd in the root of the mission).

The filenames are indeed prefaced with "fn_"

In other words, it looks exactly the same as functions defined in description.ext (which can be seen on that page).

So yeah, looks like you're on the right track. The only thing is that CfgFunctions.hpp doesn't need to be in that specific directory. Just put

#include "filepath\CfgFunctions.hpp"

inside CfgFunctions in your mission's description.ext

Share this post


Link to post
Share on other sites
So yeah, looks like you're on the right track. The only thing is that CfgFunctions.hpp doesn't need to be in that specific directory. Just put

#include "filepath\CfgFunctions.hpp"

inside CfgFunctions in your mission's description.ext

Thanks again but...

...when I placed the following my functions are still not working? Does it matter whether they are inline or as-a-file?

description.ext

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

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Post your cfgFunctions.hpp and your folder/file naming and structure. You're previous examples where missing the "file" and "tag" entries.

Share this post


Link to post
Share on other sites
Post your cfgFunctions.hpp and your folder/file naming and structure. You're previous examples where missing the "file" and "tag" entries.

The CfgFunctions.hpp is in the spoiler of my first post as well as my folder/file structure. The example I'm using is based on a working mission from DNA_UK (who helped me a while back on another issue). He did not have to define the tag or path in his CfgFunctions.hpp.

my folder it set-up like so:

%ROOT%\functions\subolder\fn_unitStatusCost.sqf

description.ext

author = "BEAKS";
onLoadName = "Repair Rearm and Flip";

class Header
{
gameType = SC;
minPlayers = 1;
maxPlayers = 6;
};

enableDebugConsole = 1;

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

functions folder contains cfgFunctions.hpp

cfgFunctions.hpp

class BEAKS
{
class subfolder
{
	class RepairRearmFlip;
	class unitStatusCost;

};
};

subfolder contains: fn_RepairRearmFlip.sqf and fn_unitStatusCost.sqf

fn_RepairRearmFlip.sqf

private ["_veh", "_status", "_totalCost"];
_veh = cursorTarget;
_status = _this select 0;
_totalCost = _this select 1;

sleep 3;

// Repair
if ( (_status == "Repair") or (_status == "Repair/Rearm") or (_status == "Repair/Flip") or (_status == "Repair/Rearm/Flip") ) then {
	waitUntil {
		_veh setFuel 1;
		_veh setDamage 0;
		true;
	};
};

// Rearm
if ( (_status == "Rearm AT Soldier") or (_status == "Rearm") or (_status == "Repair/Rearm") or (_status == "Rearm/Flip") or (_status == "Repair/Rearm/Flip") ) then {
	_veh setVehicleAmmo 1;
	if (_veh isKindOf "Man") then {
		if (backpack cursorTarget != "") then {
			switch (typeOf _veh) do {
				case "B_soldier_AT_F" : {clearAllItemsFromBackpack _veh;  _veh setAmmo ["launch_B_Titan_short_F", 1]; for "_i" from 1 to 4 do {_veh addItemToBackpack "Titan_AT"};
				_veh addItemToBackpack "Titan_AP"};
				case "B_soldier_LAT_F" : {clearAllItemsFromBackpack _veh; _veh setAmmo ["launch_NLAW_F", 1]; for "_i" from 1 to 4 do {_veh addItemToBackpack "NLAW_F"}};
				case "B_G_Soldier_LAT_F" : {clearAllItemsFromBackpack _veh; _veh setAmmo ["launch_RPG32_F", 1]; for "_i" from 1 to 4 do {_veh addItemToBackpack "RPG32_F"}};
				case "O_Soldier_AT_F" : {clearAllItemsFromBackpack _veh; _veh setAmmo ["launch_O_Titan_short_F", 1]; for "_i" from 1 to 4 do {_veh addItemToBackpack "Titan_AT"};
				_veh addItemToBackpack "Titan_AP"};
				case "O_G_Soldier_LAT_F" : {clearAllItemsFromBackpack _veh; _veh setAmmo ["launch_RPG32_F", 1]; for "_i" from 1 to 4 do {_veh addItemToBackpack "RPG32_F"}};
			}; //end switch case
		}; // if backbpack
	};
};

// Flip
if ( (_status == "Flip") or (_status == "Repair/Flip") or (_status == "Repair/Flip") or (_status == "Repair/Rearm/Flip") ) then {
	waitUntil {
	_veh setPos [getPos _veh select 0, getPos _veh select 1, 0]; 
	true;
	};
};
hint format ["_veh %1  \n  _status %2 \n _totalCost %3", typeOf _veh, _status, _totalCost] ;

fn_unitStatusCost.sqf

private ["_magCount",""_mags,"_totalCurAmmo","_VehAmmoArray","_getVehicleAmmoDef","_maxAmmoArray","_VehAmmoArray","_defBPAmmoCountAll","_status","_veh","_repairCost","_rearmManCost",
"_rearmVehCost","_totalCost","_vehCost"];
_magCount = 0;
_mags = [];
_totalCurAmmo = 0;
_VehAmmoArray = [];
_getVehicleAmmoDef = 0;
_getBPAmmoDef = 0;
_maxAmmoArray = []; 
_VehAmmoArray = [];
_defBPAmmoCountAll = 0;
_status = "";
_veh = cursorTarget;
_repairCost = 0;
_rearmManCost = 0;
_rearmVehCost = 0;
_totalCost = 0;
_vehCost =  _veh getVariable "value";

// default ammo per magazine for soldiers and in their backpack
if (_veh isKindOf "Man") then {
	if (backpack _veh != "") then {
		{_defBPAmmoCountAll = _defBPAmmoCountAll + (getNumber (configFile >> "CfgVehicles" >> backpack _veh >> "TransportMagazines" >> _x >> "count"));
		} forEach ["_xx_RPG32_F","_xx_RPG32_HE_F","_xx_NLAW_F","_xx_Titan_AT","_xx_Titan_AP"];


		_getBPAmmoDef = ( (count backpackItems _veh) / _defBPAmmoCountAll);
	};
};

// default ammo per magazine for vehicles
if (_veh isKindOf "LandVehicle") then {
		_VehAmmoArray =  getArray (configFile >> "CfgVehicles" >> typeOf _veh >> "Turrets" >> "MainTurret" >> "magazines");
		_defTotalAmmo = 0;
		{
			_defTotalAmmo = _defTotalAmmo + (getNumber (configFile >> "CfgMagazines" >> _x >> "count"));
		} forEach _VehAmmoArray;
		if ((typeOf _veh ==  "B_G_Offroad_01_armed_F") or (typeOf _veh ==  "O_G_Offroad_01_armed_F")) then {_defTotalAmmo = 400};   // cheat as it's not defined in CfgVehicles // need to update this for O_G_Offroad_01_armed_F
			_magCount = count (magazines (_veh));
			_totalCurAmmo = 0;
		{
			_totalCurAmmo = _totalCurAmmo + (_x select 1);
		} forEach (magazinesAmmo _veh);
		// _getVehicleAmmoDef = 0;
		_getVehicleAmmoDef = (_totalCurAmmo/_defTotalAmmo);
};

// Determine _status		
switch (true) do {			
	case   ((!(_veh isKindOf "LandVehicle")) && (!(_veh isKindOf "Man"))): {};
	case   ((_veh isKindOf "Man") && (_getBPAmmoDef < 1) && (backpack _veh != "")) : {_status = "Rearm AT Soldier"};
	if (_veh isKindOf "LandVehicle") then {
		case   ((damage _veh > 0) && (_getVehicleAmmoDef == 1) && (((vectorUp _veh) select 2) > 0.66)): {_status = "Repair"};	
		case   ((_getVehicleAmmoDef < 1) && (damage _veh == 0) && (((vectorUp _veh) select 2) > 0.66)): {_status = "Rearm"};	
		case   ((((vectorUp _veh) select 2) < 0.66) && (_getVehicleAmmoDef == 1) && (damage _veh == 0)) : {_status = "Flip"};	
		case   ((damage _veh > 0) && (_getVehicleAmmoDef < 1) && (((vectorUp _veh) select 2) > 0.66)) : {_status = "Repair/Rearm"	};	
		case   ((damage _veh > 0) && (((vectorUp _veh) select 2) < 0.66) &&  (_getVehicleAmmoDef == 1)): {_status = "Repair/Flip"};	
		case   ((_getVehicleAmmoDef < 1) && (((vectorUp _veh) select 2) < 0.66) && (damage _veh == 0)) : {_status = "Rearm/Flip"};	
		case   ((_getVehicleAmmoDef < 1) && (((vectorUp _veh) select 2) < 0.66) && (damage _veh > 0)) : {_status = "Repair/Rearm/Flip"};	
	}; // "LandVehicle"
	// case (_status == "") : {exitWith {}};
};//end switch case

// Calculate _totalCost for either Repair or Rearm or Both		
_repairCost = round ((damage _veh) * (_vehCost/2));
_rearmManCost = round ((1 - _getBPAmmoDef) * (_vehCost/2));
_rearmVehCost = round ((1 - _getVehicleAmmoDef) * (_vehCost/2));
if (_veh isKindOf "Man") then {_totalCost = _rearmManCost} else { _totalCost = _repairCost + _rearmVehCost};

[_status, _totalCost] // _status, _totalCost to be returned as _return in addAction

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

There are multiple ways to do it. SilentSpike explained it correctly. Follow his post. Define the tag and the file location and make sure the files start with "fn_".

Share this post


Link to post
Share on other sites
There are multiple ways to do it. SilentSpike explained it correctly. Follow his post. Define the tag and the file location and make sure the files start with "fn_".

I tried it and even used the method from https://community.bistudio.com/wiki/Functions_Library_(Arma_3). It loads fine without any errors. I think it is the way I might be call the fucntions.

here's what how I'm calling them:

myAction = player addAction ["dynamic", {
_return = [cursortarget] call BEAKS_fnc_unitStatusCost;
[_return select 0, _return select 1] spawn BEAKS_fnc_RepairRearmFlip}, [], 10, true, true, "",
   "_return = [cursortarget] call BEAKS_fnc_unitStatusCost;
   _display = ('<t size=''0.85''>' +   (_return select 0) +'</t>') + ('<t size=''0.85''  color=''#ff0000''>' + ' $ '+ str  (_return select 1) +'</t>');
   player setUserActionText [myAction, _display ];
   alive cursortarget && ((_this distance cursortarget) < 5) && {({cursortarget iskindof _x}count['Man','LandVehicle'] > 0)  &&  (!(isplayer cursortarget)) && ((_return select 1) > 0)}"
];  

---------- Post added at 02:39 ---------- Previous post was at 02:31 ----------

Solved it,

Thanks again for your support!

I misplaced a stupid quote in my fn_unitStatusCost.sqf where I declare the private variable...see ""_mags...

sigh

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  

×