Jump to content
RyanBolder

CtrlSetPosition (x,y)

Recommended Posts

On 1.9.2018 at 4:01 PM, bad benson said:

@RyanBolder that's what the comment ontop of th script is about.

 

basically when you do UI stuff using ctrlCreate you need to make sure you clean up after yourself properly because when you use the restart mission functionality arma does not clean up by itself. so without that isNil check and saving the control (line in this case) in the uiNamespace before hand you will get a new line everytime you restart (restart using the restart button in the ESC/Pause menu). they will start stacking up and only the latest one would react to your code.

 

if it's not clear still, jsut remove the parts and see what happens.

I know it doesnt goes away when i restart but it doesnt even show when i delete the lines where uinamespace is used.

 

/*EDIT MY BAD GOT IT WORKING THANK YOU GUYS <3

Share this post


Link to post
Share on other sites

So this is the last problem. When i do this with drawline3d i can draw a line on every player but it doesnt seem to work with displays. Maybe someone has an idea. After this problem is solved or we know a bit more about this, this thread can be closed hope it helped many people out there.  Especially thank you both @HazJ
@Larrow

uiNamespace setVariable [ "unitLine", nil ];

addMissionEventHandler [ "Draw3D", {
{
    	disableSerialization;
	
	_posA = worldToScreen ( getPosATL _x vectorAdd[ 0, 0, 0 ] );
	_posB = worldToScreen ( getPosATL _x vectorAdd[ 0, 0, 2 ] );
	
	_ctrl = uiNamespace getVariable "unitline";
	
	if ( isNil "_ctrl" ) then {
		_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10001 ];
		uiNamespace setVariable [ "unitLine", _ctrl ];
	};
	
	_ctrl ctrlSetPosition [
		_posA select 0,
		_posA select 1,
		( _posB select 0 ) - ( _posA select 0 ),
		( _posB select 1 ) - ( _posA select 1 )
	];
	_ctrl ctrlCommit 0;
}Foreach AllUnits;
}]; 

 

Share this post


Link to post
Share on other sites
6 hours ago, RyanBolder said:

When i do this with drawline3d i can draw a line on every player but it doesnt seem to work with displays.

Are you changing the IDC for each line you draw, and saving each line rather than just the one in the uiNamespace variable?

 

uiNamespace setVariable [ "unitLines", [ [], [] ] ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;
	
	{
	    
		_posA = worldToScreen getPosATLVisual _x;
		_posB = worldToScreen ( getPosATLVisual _x vectorAdd[ 0, 0, 2 ] );
		
		_linesInfo = uiNamespace getVariable "unitlines";
		_unitIndex = _linesInfo select 0 find _x;
		_ctrl = if ( _unitIndex > -1 ) then {
			_linesInfo select 1 select _unitIndex;
		};
		
		if ( isNil "_ctrl" ) then {
			_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10000 + count ( _linesInfo select 1 ) ];
			_index = _linesInfo select 0 pushBack _x;
			_linesInfo select 1 set[ _index, _ctrl ];
		};
		
		_ctrl ctrlSetPosition [
			_posA select 0,
			_posA select 1,
			(( _posB select 0 ) - ( _posA select 0 )) + pixelW,
			( _posB select 1 ) - ( _posA select 1 )
		];
		_ctrl ctrlCommit 0;
		
	}forEach ( allUnits - [ player ] );
}]; 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 5.9.2018 at 3:23 AM, Larrow said:

Are you changing the IDC for each line you draw, and saving each line rather than just the one in the uiNamespace variable?

 


uiNamespace setVariable [ "unitLines", [ [], [] ] ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;
	
	{
	    
		_posA = worldToScreen getPosATLVisual _x;
		_posB = worldToScreen ( getPosATLVisual _x vectorAdd[ 0, 0, 2 ] );
		
		_linesInfo = uiNamespace getVariable "unitlines";
		_unitIndex = _linesInfo select 0 find _x;
		_ctrl = if ( _unitIndex > -1 ) then {
			_linesInfo select 1 select _unitIndex;
		};
		
		if ( isNil "_ctrl" ) then {
			_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10000 + count ( _linesInfo select 1 ) ];
			_index = _linesInfo select 0 pushBack _x;
			_linesInfo select 1 set[ _index, _ctrl ];
		};
		
		_ctrl ctrlSetPosition [
			_posA select 0,
			_posA select 1,
			(( _posB select 0 ) - ( _posA select 0 )) + pixelW,
			( _posB select 1 ) - ( _posA select 1 )
		];
		_ctrl ctrlCommit 0;
		
	}forEach ( allUnits - [ player ] );
}]; 

 

Wasnt changing the IDC for each line. This helps again Thank you very much my seriosly last problem is that the line stayes on my screen when the target dies.

 

if !(alive _x ) then {

    _ctrl ctrlShow false;

};

 

Doesnt work :( Any idea?

Share this post


Link to post
Share on other sites

Hello again after i havent got a answer let me clear up more what the problem is (I have been waiting for 2 weeks because i dont want to do spam).

 

I was still experimenting with my drawline project but my last point/last error was the problem that the lines werent cleaned after the target died. I think i must clear the namespace for that but i really dont know much about namespaces i havent used them before i would really appreciate it if anyone can give me an advice or way i can clear the lines which arent on the target.

I tried several things with ctrlDelete ctrlSetFade ctrlShow etc. . All that didnt help me. The problem is like this:

 

59zPYqK.png

TARGET ALIVE

G268Lr4.png

TARGET DIED = LINE STUCK ON SCREEN

Line doesnt clean Up.

 

I use the code above.

Share this post


Link to post
Share on other sites

Unfortunately we are not here to write scripts for you. There is a forum section for that.

Saying 'I have been waiting blah blah long' I find just generally rude. We are not a paid support service and are here, just like you, as a hobby interest.

If you are having a problem, rather than 'It dont work', maybe show some of the things you have tried, as in your complete code.

Saying I have tried blah and blah without showing your code helps no one, especially you as you will learn nothing from your mistakes.

Then people might be willing to help you out and discuss why what you have tried is not working.

 

Unfortunately I'm a fucking nice guy and, I presume much to the disgust of some, I'm always willing to write and provide code for people to copy and paste. But again if you do not provide code that you have tried to change when experiencing problems your are never going to learn anything from C&P.

 

Fix for code previously provided so as to hide lines for dead units

Spoiler

uiNamespace setVariable [ "unitLines", [ [], [] ] ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;

	{

		_posA = worldToScreen getPosATLVisual _x;
		_posB = worldToScreen ( getPosATLVisual _x vectorAdd[ 0, 0, 2 ] );

		_linesInfo = uiNamespace getVariable "unitlines";
		_unitIndex = _linesInfo select 0 find _x;
		_ctrl = if ( _unitIndex > -1 ) then {
			_linesInfo select 1 select _unitIndex;
		};

		if ( isNil "_ctrl" ) then {
			_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10000 + count ( _linesInfo select 1 ) ];
			_index = _linesInfo select 0 pushBack _x;
			_linesInfo select 1 set[ _index, _ctrl ];
		};


		_ctrl ctrlSetPosition [
			_posA select 0,
			_posA select 1,
			(( _posB select 0 ) - ( _posA select 0 )) + pixelW,
			( _posB select 1 ) - ( _posA select 1 )
		];
		_ctrl ctrlCommit 0;

	}forEach ( allUnits - [ player ] );

	_linesInfo = uiNamespace getVariable[ "unitLines", [ [], [] ] ];
	{
		if !( alive _x ) then {
			ctrlDelete ( _linesInfo select 1 select _forEachIndex );
			_linesInfo select 1 set [ _forEachIndex, controlNull ];
			_linesInfo select 0 set [ _forEachIndex, objNull ];
		};
	}forEach ( _linesInfo select 0 );

	_linesInfo set [ 0, ( _linesInfo select 0 ) - [ objNull ] ];
	_linesInfo set [ 1, ( _linesInfo select 1 ) - [ controlNull ] ];

}];

 

TEST_MISSION that provides a function library to draw/remove unit lines.

  • Like 4
  • Thanks 1

Share this post


Link to post
Share on other sites
16 hours ago, Larrow said:

Unfortunately we are not here to write scripts for you. There is a forum section for that.

Saying 'I have been waiting blah blah long' I find just generally rude. We are not a paid support service and are here, just like you, as a hobby interest.

If you are having a problem, rather than 'It dont work', maybe show some of the things you have tried, as in your complete code.

Saying I have tried blah and blah without showing your code helps no one, especially you as you will learn nothing from your mistakes.

Then people might be willing to help you out and discuss why what you have tried is not working.

 

Unfortunately I'm a fucking nice guy and, I presume much to the disgust of some, I'm always willing to write and provide code for people to copy and paste. But again if you do not provide code that you have tried to change when experiencing problems your are never going to learn anything from C&P.

 

Fix for code previously provided so as to hide lines for dead units

  Hide contents


uiNamespace setVariable [ "unitLines", [ [], [] ] ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;

	{

		_posA = worldToScreen getPosATLVisual _x;
		_posB = worldToScreen ( getPosATLVisual _x vectorAdd[ 0, 0, 2 ] );

		_linesInfo = uiNamespace getVariable "unitlines";
		_unitIndex = _linesInfo select 0 find _x;
		_ctrl = if ( _unitIndex > -1 ) then {
			_linesInfo select 1 select _unitIndex;
		};

		if ( isNil "_ctrl" ) then {
			_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10000 + count ( _linesInfo select 1 ) ];
			_index = _linesInfo select 0 pushBack _x;
			_linesInfo select 1 set[ _index, _ctrl ];
		};


		_ctrl ctrlSetPosition [
			_posA select 0,
			_posA select 1,
			(( _posB select 0 ) - ( _posA select 0 )) + pixelW,
			( _posB select 1 ) - ( _posA select 1 )
		];
		_ctrl ctrlCommit 0;

	}forEach ( allUnits - [ player ] );

	_linesInfo = uiNamespace getVariable[ "unitLines", [ [], [] ] ];
	{
		if !( alive _x ) then {
			ctrlDelete ( _linesInfo select 1 select _forEachIndex );
			_linesInfo select 1 set [ _forEachIndex, controlNull ];
			_linesInfo select 0 set [ _forEachIndex, objNull ];
		};
	}forEach ( _linesInfo select 0 );

	_linesInfo set [ 0, ( _linesInfo select 0 ) - [ objNull ] ];
	_linesInfo set [ 1, ( _linesInfo select 1 ) - [ controlNull ] ];

}];

 

TEST_MISSION that provides a function library to draw/remove unit lines.

You're a legend i wont forget your help thank you. 

 

This can be closed thanks for everyone who helped out.

Share this post


Link to post
Share on other sites
18 hours ago, Larrow said:

Unfortunately we are not here to write scripts for you. There is a forum section for that.

Saying 'I have been waiting blah blah long' I find just generally rude. We are not a paid support service and are here, just like you, as a hobby interest.

If you are having a problem, rather than 'It dont work', maybe show some of the things you have tried, as in your complete code.

Saying I have tried blah and blah without showing your code helps no one, especially you as you will learn nothing from your mistakes.

Then people might be willing to help you out and discuss why what you have tried is not working.

 

Unfortunately I'm a fucking nice guy and, I presume much to the disgust of some, I'm always willing to write and provide code for people to copy and paste. But again if you do not provide code that you have tried to change when experiencing problems your are never going to learn anything from C&P.

 

Fix for code previously provided so as to hide lines for dead units

  Reveal hidden contents


uiNamespace setVariable [ "unitLines", [ [], [] ] ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;

	{

		_posA = worldToScreen getPosATLVisual _x;
		_posB = worldToScreen ( getPosATLVisual _x vectorAdd[ 0, 0, 2 ] );

		_linesInfo = uiNamespace getVariable "unitlines";
		_unitIndex = _linesInfo select 0 find _x;
		_ctrl = if ( _unitIndex > -1 ) then {
			_linesInfo select 1 select _unitIndex;
		};

		if ( isNil "_ctrl" ) then {
			_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10000 + count ( _linesInfo select 1 ) ];
			_index = _linesInfo select 0 pushBack _x;
			_linesInfo select 1 set[ _index, _ctrl ];
		};


		_ctrl ctrlSetPosition [
			_posA select 0,
			_posA select 1,
			(( _posB select 0 ) - ( _posA select 0 )) + pixelW,
			( _posB select 1 ) - ( _posA select 1 )
		];
		_ctrl ctrlCommit 0;

	}forEach ( allUnits - [ player ] );

	_linesInfo = uiNamespace getVariable[ "unitLines", [ [], [] ] ];
	{
		if !( alive _x ) then {
			ctrlDelete ( _linesInfo select 1 select _forEachIndex );
			_linesInfo select 1 set [ _forEachIndex, controlNull ];
			_linesInfo select 0 set [ _forEachIndex, objNull ];
		};
	}forEach ( _linesInfo select 0 );

	_linesInfo set [ 0, ( _linesInfo select 0 ) - [ objNull ] ];
	_linesInfo set [ 1, ( _linesInfo select 1 ) - [ controlNull ] ];

}];

 

TEST_MISSION that provides a function library to draw/remove unit lines.

Too nice and too gorge' LOL! :rofl::rofl: Hehe

I sent you some beer money for that thing you helped me with and for your awesome help across the forum.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Instead of creating new thread, thought I'd ask here. Using drawLine3D and am wondering how to made it see able at night time? Doesn't make a difference on how bright the colour is, when completely dark, it renders invisible (except in NV).

Share this post


Link to post
Share on other sites

Anyone got any ideas? Still looking for a solution.

@Larrow perhaps? :happy:

 

EDIT: Added code (sloppy).

["tacHUD", "onEachFrame",
{
	_players = allUnits - (entities "HeadlessClient_F");
	{
		_namePos = (_x modelToWorldVisual (_x selectionPosition "head"));
		_namePos set [2, 2.08];
		_healthPos = (_x modelToWorldVisual (_x selectionPosition "spine3"));
		_healthColour = if (damage _x isEqualTo 0) then {[0, 1, 0, 1]} else {[0.87, 0.5, 0, 1]};
		if (damage _x >= 0.85) then {_healthColour = [1, 0, 0, 1];};
		_size = (0.55 / (getResolution select 5) * 1);
		if (!isNull _x && !(lifeState _x isEqualTo "INCAPACITATED") && {_x distance getPosATL player <= 25 && _x distance getPosATL player > 1}) then
		{
			drawIcon3D ["", [1, 1, 1, 1], _namePos, _size, _size, 0, format ["%1", name _x], 1, 0.03, "RobotoCondensed"];
			drawIcon3D ["", _healthColour, _healthPos, _size, _size, 0, format ["%1%2", round ((1 - (damage _x)) * 100), "%"], 1, 0.03, "RobotoCondensed"];
			drawLine3D [(player modelToWorldVisual (player selectionPosition "spine1")), (_x modelToWorldVisual (_x selectionPosition "spine1")), [0, 1, 0, 1]];
		};
	} forEach _players;
}] call BIS_fnc_addStackedEventHandler;

 

Share this post


Link to post
Share on other sites
On 15/1/2019 at 5:51 AM, HazJ said:

EDIT: Added code (sloppy).

 

Hahaha !

 

Very good Hajz !  :thumb:

 

 

Share this post


Link to post
Share on other sites

Got a few suggestions from soneone but not going to bother. Seems more work than it is worth.

 

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

×