Jump to content
Sign in to follow this  
A-SUICIDAL

ctrlSetText problem

Recommended Posts

I'm trying to get a dialog text to show the current damage number value, but it gives me problems when I try to use %1

this is a more simple version of the script, just to give you an idea what I am trying to do:

_dam = getDammage _object;
_status ctrlSetText format ["%1",_dam];

Instead of the damage value being displayed, it instead displays the word "scalar".

If I try testing it using...

_status ctrlSetText "hi";

... it does work correctly.

I also tried doing this...

_dam = getDammage _object;
_text = format["%1",_dam];
_status ctrlSetText _text;

...but that didn't work either.

Does anybody know the correct way to do this?

I spent 2 days just trying to learn how to create a dialog and I finally got everything exactly the way I want it and everything works, except this one thing - and it's now driving me nuts, lol.

I read this thread: http://forums.bistudio.com/showthread.php?131515-ctrlSetText-ctrlText-not-working

and this thread: http://forums.bistudio.com/showthread.php?128910-Dialog-IDD-amp-IDC&p=2074703&viewfull=1#post2074703

and I've been back and forth to the dialog wiki, but I can't seem to get this resolved.

Even in this thread, a guy by the name of ManDay explains exactly what I tried to do. http://forums.bistudio.com/showthread.php?60788-CtrlSetText-in-Description-ext

...but it didn't work for me.

---------- Post added at 01:25 AM ---------- Previous post was at 01:03 AM ----------

I just tried doing it this way...

_dam = getDammage _object;
_status ctrlSetText "hi";
sleep 5;
ctrlSetText [_status, format["%1", _dam]];

The word "hi" appeared, but then 5 seconds later nothing happened. It still just showed "hi" on the screen. No errors were reported and the word "scalar" did not appear.

Share this post


Link to post
Share on other sites

Do

diag_log _dam;

If it will return "scalar" then getDammage didn't return damage value (_object is not valid object pointer).

Share this post


Link to post
Share on other sites

I was just using an example above. The real script is pretty long and deals with a players(_unit) remaining health that gets shown in a dialog/hud. I think the reason why it won't work is because I am trying to use ctrlSetText within an addEventHandler script, because ctrlSetText seems to test fine outside the EH, but I need it to be within the EH for it to work correctly. There is something else I need to do to get it to work within an EH.

Share this post


Link to post
Share on other sites

I think my main problem is when I use disableSerialization; I then get errors where I use _unit or anything with an underscore. I'm not sure how to work around this.

Below are the scripts that relate to everything that I am trying to do. Basically I have create a dialog that shows your health status on the screen. It appears in the bottom right corner of the screen and sits there the entire mission like it's an additional HUD feature. It simply says Health: 100 and the word "Health:" changes from green, to yellowgreen, yellow, orange and red as you take more damage and the number "100" changes in value and always appears in white text.

I have event damage handlers that disables all body part damage that a player would normally take and I base the player damage on "overall" damage only. This allows me to give the player additional body armor and insures me that my health calculations are exact, but it disables the player from looking bloody. Then I have another event handle for when the player is "Hit" that then calculates the damage taken and it is supposed to then update the dialog with the current health value and change the color of the word "Health:". It will also "setHit" at certain health levels to make the player appear bloody, starting with the hands, then body, legs and lastly face.

My problem comes in when I use addEventHandler ["Hit",... in the players init. For some reason it doesn't want to update my dialog when I use ctrlSetText or ctrlSetTextColor.

It is the very last thing I need to do to get everything working correctly. I could really use some help with this. It's a great script if I could just get it working correctly. I had everything working great when I was using simple hint messages instead of a dialog/hud, but I do not want to use hints, especially after I finally figured out how to create a dialog for this.

init.sqf:

_health_stats = execVM "dialog\health_status.sqf";

description.ext:

#include "dialog\dialog.cpp"

dialog.cpp:

#define CT_STATIC           0
#define ST_LEFT           0x00

class RscPicture
{
access = 0;
type = 0;
idc = -1;
style = 48;
colorBackground[] = {0,0,0,0};
colorText[] = {1,1,1,1};
font = "TahomaB";
sizeEx = 0;
lineSpacing = 0;
text = "";
fixedWidth = 0;
shadow = 0;
x = 0;
y = 0;
w = 0.2;
h = 0.15;
};

class RscTitles
{
class Health_Hud
  	{
     	idd = 1000;
    	movingEnable=0;
     	duration=1e+011;
     	name = "Health_Hud_Name";
     	onLoad = "uiNamespace setVariable ['HUD', _this select 0];";
onUnLoad = "uiNamespace setVariable ['HUD', nil]";
     	controlsBackground[] = {};
     	objects[] = {};
     	class controls
	{
		class bkgrnd
		{
			type = CT_STATIC;
			idc = 1001;
			style = ST_LEFT;
			x = 0.911977 * safezoneW + safezoneX;
			y = 0.949074 * safezoneH + safezoneY;
			w = 0.0625 * safezoneW;
			h = 0.025 * safezoneH;
			font = "Zeppelin32";
			sizeEx = 0.03;
			colorBackground[] = {0,0,0,0.7843};
			colorText[] = {1, 1, 1, 1};
			text = "";
		};
		class health
		{
			type = CT_STATIC;
			idc = 1002;
			style = ST_LEFT;
			x = 0.920836 * safezoneW + safezoneX;
			y = 0.95 * safezoneH + safezoneY;
			w = 0.03125 * safezoneW;
			h = 0.025 * safezoneH;
			font = "Zeppelin32";
			sizeEx = 0.03;
			colorBackground[] = {0, 0, 0, 0};
			colorText[] = {0.25,1,0,1};
			text = "Health: ";
		};
		class status
		{
			type = CT_STATIC;
			idc = 1003;
			style = ST_LEFT;
			x = 0.951044 * safezoneW + safezoneX;
			y = 0.95 * safezoneH + safezoneY;
			w = 0.0166639 * safezoneW;
			h = 0.0252316 * safezoneH;
			font = "Zeppelin32";
			sizeEx = 0.03;
			colorBackground[] = {0, 0, 0, 0};
			colorText[] = {1,1,1,1};
			text = "100";
		};
	};
};
titles[] = {introImage};
class introImage
{	
	idd = -1;	
	movingEnable = 0;
	fadein = 2;
	duration = 12;
	name = "IntroImage"; 
	controls[] = {"image1"};

	class image1: RscPicture
	{	
		x = -0.5;
		y = -0.35;
		w = 2;
		h = 1.8;
		text = "pictures\receiving_001.paa";
	};	
};
};

dialog\health_status.sqf:

disableSerialization;

health_hud_Shown = false;

cutRsc ["Health_Hud","PLAIN"];
_ui       = uiNamespace getVariable "HUD";
_bkgrnd   = _ui displayCtrl 1001;
_health   = _ui displayCtrl 1002;
_status   = _ui displayCtrl 1003;
_array_hud = [_bkgrnd,_health,_status];
{_x ctrlShow false} foreach _array_hud;

if !(health_hud_Shown) then {{_x ctrlShow true} foreach _array_hud; health_hud_Shown = true;};

player init:

this setVariable ["selections", []];
this setVariable ["gethit", []];
this addEventHandler 
[
"HandleDamage",
   	{
   		if (_this select 1 == "") then
   		{
   			_unit = _this select 0;
   			_selections = _unit getVariable ["selections", []];
   			_gethit = _unit getVariable ["gethit", []];
   			_selection = _this select 1;
   			if !(_selection in _selections) then
   			{
   				_selections set [count _selections, _selection];
   				_gethit set [count _gethit, 0];
   			};    
   			_i = _selections find _selection;
   			_olddamage = _gethit select _i;
   			_damage = _olddamage + ((_this select 2) - _olddamage) * 0.5;
   			_gethit set [_i, _damage];
   			_damage;
   		};
   	}
];
this addEventHandler 
[
   	"Hit",
   	{
	_unit = _this select 0;
   		_dam = getDammage _unit;
   		_dif = 1 - _dam;
   		_total = _dif * 100;
   		_hp = round _total;

   		if ((_hp <=100) && (_hp >80)) then 
   		{
		_health ctrlSetTextColor [0.25, 1, 0, 1];
		ctrlSetText [_status, format["%1", _hp]];
   			_unit setHit ["hands", 0.9];
   		};
   		if ((_hp <80) && (_hp >60)) then 
   		{
		_health ctrlSetTextColor [0.75, 1, 0, 1];
		ctrlSetText [_status, format["%1", _hp]];
		_unit setHit ["body", 0.9];
   		}; 
   		if ((_hp <60) && (_hp >40)) then 
   		{
		_health ctrlSetTextColor [1, 1, 0, 1];
		ctrlSetText [_status, format["%1", _hp]];
   			_unit setHit ["legs", 0.9];
   		};
   		if ((_hp <40) && (_hp >20)) then 
   		{
		_health ctrlSetTextColor [1, 0.5, 0, 1];
		ctrlSetText [_status, format["%1", _hp]];
			_unit setHit ["head", 0.9];
   		};
   		if ((_hp <20) && (_hp >0)) then 
   		{
		_health ctrlSetTextColor [1, 0, 0, 1];
		ctrlSetText [_status, format["%1", _hp]];
		_unit setHit ["legs", 1];
   		};
   		if (!alive _unit) then 
   		{
		_health ctrlSetTextColor [1, 0, 0, 1];
		ctrlSetText [_status, format["%1", _hp]];
   			_unit setHit ["hands", 1];
		_unit setHit ["body", 1];
		_unit setHit ["head", 1];
   		};
   	}
];

So the last part player init is where I use ctrlSetText and ctrlSetTextColor, but it's not working. Can somebody please help me with this?

Share this post


Link to post
Share on other sites

I figured it out and fixed it.

This is my new player init:

this setVariable ["selections", []];
this setVariable ["gethit", []];
this addEventHandler 
[
"HandleDamage",
   	{
   		if (_this select 1 == "") then
   		{
   			_unit = _this select 0;
   			_selections = _unit getVariable ["selections", []];
   			_gethit = _unit getVariable ["gethit", []];
   			_selection = _this select 1;
   			if !(_selection in _selections) then
   			{
   				_selections set [count _selections, _selection];
   				_gethit set [count _gethit, 0];
   			};    
   			_i = _selections find _selection;
   			_olddamage = _gethit select _i;
   			_damage = _olddamage + ((_this select 2) - _olddamage) * 0.25;
   			_gethit set [_i, _damage];
   			_damage;
   		};
   	}
];
this addEventHandler 
[
   	"Hit",
   	{
	_unit = _this select 0;
   		_dam = getDammage _unit;
   		_dif = 1 - _dam;
   		_total = _dif * 100;
   		_hp = round _total;
	_ui = uiNamespace getVariable "HUD";

   		if ((_hp <=100) && (_hp >80)) then 
   		{
		(_ui displayCtrl 1002) ctrlSetTextColor [0.25, 1, 0, 1];
		(_ui displayCtrl 1003) ctrlSetText format ["%1", _hp];
   			_unit setHit ["hands", 0.9];
   		};
   		if ((_hp <80) && (_hp >60)) then 
   		{
		(_ui displayCtrl 1002) ctrlSetTextColor [0.75, 1, 0, 1];
		(_ui displayCtrl 1003) ctrlSetText format ["%1", _hp];
   			_unit setHit ["body", 0.9];
   		}; 
   		if ((_hp <60) && (_hp >40)) then 
   		{
		(_ui displayCtrl 1002) ctrlSetTextColor [1, 1, 0, 1];
		(_ui displayCtrl 1003) ctrlSetText format ["%1", _hp];
   				_unit setHit ["legs", 0.9];
   		};
   		if ((_hp <40) && (_hp >20)) then 
   		{
		(_ui displayCtrl 1002) ctrlSetTextColor [1, 0.5, 0, 1];
		(_ui displayCtrl 1003) ctrlSetText format ["%1", _hp];
   				_unit setHit ["head", 0.9];
   		};
   		if ((_hp <20) && (_hp >0)) then 
   		{
		(_ui displayCtrl 1002) ctrlSetTextColor [1, 0, 0, 1];
		(_ui displayCtrl 1003) ctrlSetText format ["%1", _hp];
		_unit setHit ["legs", 1];
   		};
   		if (!alive _unit) then 
   		{
		(_ui displayCtrl 1002) ctrlSetTextColor [1, 0, 0, 1];
		(_ui displayCtrl 1003) ctrlSetText format ["%1", _hp];
   			_unit setHit ["hands", 1];
		_unit setHit ["body", 1];
		_unit setHit ["head", 1];
   		};
   	}
];

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

I tested it out a little. I now have a problem where my teammate gets hurt and his damage shows in my health hud, so now I have to find out how to make it so the damage a player takes is shown only in that players health hud.

==================

Edited

Resolved :)

Edited by A-SUICIDAL

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  

×