Jump to content
cyprus

Trouble with making a health status mod.

Recommended Posts

I'm trying to make a simple addon that adds a hint at the top of the screen that shows your current health.  I found a couple relevant scripts online, and with experimenting and tweaking, I got something that works.  However, enabling the mod doubles to quadruples mission loading times.  I tried commenting out the code in the script and left the config.cpp intact, and that fixed the load times, so there's a clue, but I'm not sure where to go from here.

 

Here is the config.cpp:

class CfgPatches
{
    class health_status
    {
          units[] = {};
          weapons[] = {};
          requiredAddons[] = {};
    };
};

class CfgFunctions
{
	class ASS
	{
		class MyCategory
		{
			class MyInit
			{
				postInit=1;
                file = "\health_status\healthstatus.sqf";
                description = "script run after mission started and object initialization is complete";
			};
		};
	};

};

 

Here is the script itself

while {alive player} do 
{
	_health = getDammage player;
	hintSilent parseText format["Health: %1",(((1-_Health)*100)-((1-_Health)*100 mod 1))];
	sleep 0.01;
};

 

I used the addon builder from the Arma 3 tools, and unselected the binarize option because binarizing the mod causes it not to work.

Share this post


Link to post
Share on other sites

For your config try using this instead

class CfgPatches
{
	class health_status
	{
		requiredVersion = 1.0;
		author[] = { "cyprus" };
		units[] = {};
		weapons[] = {};
		requiredAddons[] = {};
	};
};

class CfgFunctions
{
	class health_status
	{
		class Functions
		{
			class init
			{
				postInit=1;
				file = "\health_status\healthstatus.sqf";
			};
		};
	};

};

And for your script use

if !(hasInterface) exitWith{};

waitUntil {!isNull player};

player addMissionEventHandler ["Draw3D", {
	if (alive player) then {
		_health = getDammage player;
		hintSilent parseText format["Health: %1",(((1-_health)*100)-((1-_health)*100 mod 1))];
	};
}];

this will make it run on each frame so it will always be updated correctly and never run more than necessary.  Also, use the two lines above in your inits if you want to run only on clients (IE not server and not HC). Those should prevent it from lagging during loading.

Share this post


Link to post
Share on other sites

When I try that on a mission the mod doesn't work.  In the editor it says:

 

'...};

 

waitUntil {!isNull player};

 

player |#addMissionEventHandler ["Draw3D", {

if (...'

Error Missing ;

File health_status\healthstatus.sqf, line 5

 

I tried messing with it, but I couldn't figure it out.  Thank you very much for helping me out, though.  I really appreciate it.  Hopefully it's an easy fix. 

Share this post


Link to post
Share on other sites

ah, I see what I did wrong.  Change it to

if !(hasInterface) exitWith{};
 
waitUntil {!isNull player};
 
addMissionEventHandler ["Draw3D", {
	if (alive player) then {
		_health = getDammage player;
		hintSilent parseText format["Health: %1",(((1-_health)*100)-((1-_health)*100 mod 1))];
	};
}];

I did it from memory and forgot addMissionEventHandler doesn't need any object arguments like regular eventhandlers do.

Share this post


Link to post
Share on other sites

Hey it's been a while, but I just wanted to let you know that the mod works great.  No problems so far and there seems to be 0 impact on performance.  Thank you for helping me out.

  • Like 1

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

×