Jump to content
mattjb

Need help with Personal Aid Kit mod

Recommended Posts

I've created a mod that is based on calling a script using postInit, which utilizes several function calls and variables from ACE.

It was seemingly working for some time, but recently I discovered a flaw that I would like to iron out before I continue with other similar mods based on the same structure/framework.

I've narrowed it down to likely some kind of race condition:

1) The ACE add action appears on first server start & client join, but attempting to use the menu item from it does nothing.

    a) ACE_isUnconscious is null, ACE_medical_pain is null, bodyPartStatus is a non-existent array

    20180624125100_1.jpg

2) If client leaves and rejoins server, the mod is working fine and as intended.

    a) ACE vars are defined now, mod works:

    20180624125114_1.jpg

 

Relevant portions of the code that I would think are most relevant are here:

 

config.cpp

#include "BIS_AddonInfo.hpp"
class CfgPatches //Very important, makes this text into something Arma cares about. https://community.bistudio.com/wiki/CfgPatches
{
	class WTF_WolfPAK
	{
		units[] = {}; // Unit classnames addind in this mod. None added here.
		weapons[] = {}; // Weapon classnames added by this mod. None added here.
		requiredVersion = 1;
		requiredAddons[] = {"A3_Modules_F","ace_medical","ace_medical_ai"};
	};
};
class CfgFunctions //Script converted to function to be run at the beginning of missions.
{
	class wolfpak //Prefix or tag to keep things tidy. Register it on http://www.ofpec.com/tags/ to aid in compatibility with other addons/mods. See this for a better explanation http://www.ofpec.com/faq/index.php?action=read&cat=202&id=56
	{
		class functions //Define for postInit below. It looks for files with this format fn_thisClassName.sqf (fn_clientFPSinit.sqf)
		{
			file = "wolfpak\functions"; // Location of the .sqf function within the .pbo file.
			class initWolfPAK
			{
			    postInit = 1;
			};
		}; //Call the function at the beginning of every mission. https://community.bistudio.com/wiki/Functions_Library_(Arma_3)#Pre_and_Post_Init
	};
};
class Extended_PreInit_EventHandlers {
    wolfpak = "call compile preprocessFileLineNumbers 'wolfpak\XEH_preInit.sqf'";
};
class cfgMods
{
	author = "76561198102736622"; // Your Steam community ID aka GUID
	timepacked = "1522002158"; // Current build timestamp in UNIX/Epoch format. https://www.epochconverter.com/clock
};

fn_initWolfPAK.sqf

[] execVM "wolfpak\WolfPAKinit.sqf";

WolfPAKinit.sqf

[[], {
    if (isServer) exitWith {};

    waitUntil {
        !(isNull player) &&
        {(player == player)} &&
        {!isNil "BIS_fnc_init"}
    };

    _unit = player;

    if (hasInterface) then {
        if (isNil {_unit getVariable ["WolfPAKActive", nil]}) then {
            _unit setVariable ["WolfPAKActive", true];
            // WolfPAK v1.5 - initialization code

            #include "\z\ace\addons\medical\script_component.hpp"
                _unit sideChat format ["bodypartstatus: %1",_unit getVariable [QGVAR(bodyPartStatus),[]]];
                _unit sideChat format ["unconscious: %1",_unit getVariable 'ACE_isUnconscious'];
                _unit sideChat format ["pain: %1",_unit getVariable 'ACE_medical_pain'];
            _fullHeal = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{(('ACE_personalAidKit' in (items _player + assignedItems _player)) or ('ACE_personalAidKit' in (items _target + assignedItems _target))) and ( (!(_target getVariable [QGVAR(bodyPartStatus),[]] isEqualTo [0,0,0,0,0,0])) or (_target getVariable 'ACE_medical_pain' > 0) or (_target getVariable 'ACE_isUnconscious' isEqualTo true))}] call ace_interact_menu_fnc_createAction;

            [[_unit, 0, ["ACE_MainActions"], _fullHeal],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];
            [_unit, 1, ["ACE_SelfActions"], _fullHeal] call ace_interact_menu_fnc_addActionToObject;
            systemChat "Initialized WolfPAK v1.5 (PBO)";
            // End of WolfPAK v1.5 - initialization code
        };
    };
}] remoteExec ["spawn", -2, true];

Any advice or suggestions to try?

Share this post


Link to post
Share on other sites

I don't use ACE but you could add a default value for those that are returned as undefined. Maybe the player is sometimes loading into fast but this wouldn't always be the case  Maybe add a check for certain things and to see if ACE is fully initialised.

https://community.bistudio.com/wiki/getVariable

Alt syntax.

Where are ACE_isUnconscious and stuff set/defined?

Share this post


Link to post
Share on other sites

ACE_isUnconscious as such are variables on the unit. They are normally nil until an event happens which sets them. the way to go is using getVariables alternative syntax, as you can expect if ACE_isUnconscious is nil means that the person is up and running so the default value is false.

For ACE_medical_pain default value is 0.

For ACE_medicalbodyPartStatus  it is [0,0,0,0,0,0] or an empty array, depends on use case.

Share this post


Link to post
Share on other sites

I'll try each of these strategies -- also will tinker with diwako's idea of substituting ACE_medicalbodyPartStatus in place of QGVAR(bodyPartStatus), which I never liked using in the first place as it seemed to require the: #include "\z\ace\addons\medical\script_component.hpp"

 

Will try adjusting the ACE action condition:

_fullHeal = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{(('ACE_personalAidKit' in (items _player + assignedItems _player)) or ('ACE_personalAidKit' in (items _target + assignedItems _target))) and ( (!(_target getVariable [QGVAR(bodyPartStatus),[0,0,0,0,0,0]] isEqualTo [0,0,0,0,0,0])) or (_target getVariable ['ACE_medical_pain', 0] > 0) or (_target getVariable ['ACE_isUnconscious', false] isEqualTo true))}] call ace_interact_menu_fnc_createAction;

 

Or as a last resort trying to initialize the ACE vars with defaults if nil:

if (_unit getVariable [QGVAR(bodyPartStatus),[]] isEqualTo []) then { 
                _unit setVariable [QGVAR(bodyPartStatus),[0,0,0,0,0,0]];

};

if (isNil (_unit getVariable ['ACE_isUnconscious', nil])) then {
                _unit setVariable ['ACE_isUnconscious', false];

};

if (isNil (_unit getVariable ['ACE_medical_pain',nil])) then {
                _unit setVariable ['ACE_medical_pain', 0];

};

Share this post


Link to post
Share on other sites

There is no point in initializing them. ACE will do this for you, you just have to use the default value from the getVariable command. you also should never include hpp files which are not yours and can change in any update. Best just use what the compile to instead.

Share this post


Link to post
Share on other sites

Thanks, diwako, your earlier suggestions of specifying defaults for getVariable seemed to have fixed the race condition.

Currently working on making the rest of the mod compliant with regarding to removal of hpp files.

I've posted another follow-up issue that is related to the same mod, but a different issue -- if you have any insight on that as well...

 

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

×