Jump to content
Sign in to follow this  
semedar

Player names over player

Recommended Posts

I've seen Domination maps with this feature but I can't figure out how they did this. Can anyone tell me how to implement this into my mission? :D

Share this post


Link to post
Share on other sites

fnc_displayName.sqf:

/* ----------------------------------------------------------------------------
Function: AZC_fnc_displayName
Author: AZCoder
Version: 1.0
Created: 1/3/2011
Description:
Displays name information next to target that player points at. This is 90% identical to
initmission.hpp from cp01.zargabad, from the PMC DLC.  AZC_fnc_displayName requires
target information to be listed in the stringtable keyed by STR_INFONAME_ with the
target map editor name appended. [color="BLUE"][b]An entry in CfgIdentities must exist and be set to the
given name. Stringtable example:
<Key ID="STR_INFONAME_Ian">
	<English>Delta Force Commanding Officer.</English>
</Key>[/b][/color]

Notes:  Set AZC_TERM_NAMES = true when you no longer wish this function to display names.

Parameters:
_nameList	- An array of map editor object names that have setIdentity performed *prior* to this function call.

Returns: Nothing

Examples:
[[bill, Rolf, Slasher]] call AZC_fnc_displayName; --> notice the double brackets
---------------------------------------------------------------------------- */
private["_nameList"];
_nameList = _this select 0;

{
_info = localize format ["STR_INFONAME_%1", vehicleVarName _x];
_x setvariable
[
	"BIS_info",
	format ["<t align='left'>%1<br /><t size='0.5'>%2</t></t>", name _x, _info]
];
} foreach _nameList;

[] spawn
{
AZC_TERM_NAMES = false;
sleep 0.1;
disableserialization;

21 cutrsc ["rscDynamicText","plain"];

#define DISPLAY	(uinamespace getvariable "BIS_dynamicText")
#define CONTROL	(DISPLAY displayctrl 9999)

_w = 1;
_h = 1;

CONTROL ctrlsetposition [
	0,
	0,
	_w,
	_h
];
CONTROL ctrlsetfade 1;
CONTROL ctrlcommit 0;

while {!AZC_TERM_NAMES} do 
{
	_target = cursortarget;
	if (!isnull _target && !visiblemap) then 
	{
		_pos = [getposatl _target select 0,getposatl _target select 1,(getposatl _target select 2) + 1.5];
		_pos2D = worldtoscreen _pos;
		_text = _target getvariable "BIS_info";
		if (count _pos2D > 0 && !isnil "_text") then 
		{
			CONTROL ctrlsetposition 
			[
				(_pos2D select 0)+0.1,
				(_pos2D select 1),
				_w,
				_h
			];
			CONTROL ctrlsetstructuredtext parsetext _text;
			CONTROL ctrlsetfade 0;
			CONTROL ctrlcommit 0.01;

		} 
		else 
		{
			CONTROL ctrlsetfade 1;
			CONTROL ctrlcommit 0.1;
		};
	} else 
	{
		CONTROL ctrlsetfade 1;
		CONTROL ctrlcommit 0.1;
	};
	sleep 0.01;
};

21 cuttext ["","plain"];
};
/* ----------------------------------------------------------------------------
Function: AZC_fnc_displayName
Author: AZCoder
Version: 1.0
Created: 1/3/2011
Description:
Displays name information next to target that player points at. This is 90% identical to
initmission.hpp from cp01.zargabad, from the PMC DLC.  AZC_fnc_displayName requires
target information to be listed in the stringtable keyed by STR_INFONAME_ with the
target map editor name appended. An entry in CfgIdentities must exist and be set to the
given name. Stringtable example:
<Key ID="STR_INFONAME_Ian">
	<English>Delta Force Commanding Officer.</English>
</Key>

Notes:  Set AZC_TERM_NAMES = true when you no longer wish this function to display names.

Parameters:
_nameList	- An array of map editor object names that have setIdentity performed *prior* to this function call.

Returns: Nothing

Examples:
[[bill, Rolf, Slasher]] call AZC_fnc_displayName; --> notice the double brackets
---------------------------------------------------------------------------- */
private["_nameList"];
_nameList = _this select 0;

{
_info = localize format ["STR_INFONAME_%1", vehicleVarName _x];
_x setvariable
[
	"BIS_info",
	format ["<t align='left'>%1<br /><t size='0.5'>%2</t></t>", name _x, _info]
];
} foreach _nameList;

[] spawn
{
AZC_TERM_NAMES = false;
sleep 0.1;
disableserialization;

21 cutrsc ["rscDynamicText","plain"];

#define DISPLAY	(uinamespace getvariable "BIS_dynamicText")
#define CONTROL	(DISPLAY displayctrl 9999)

_w = 1;
_h = 1;

CONTROL ctrlsetposition [
	0,
	0,
	_w,
	_h
];
CONTROL ctrlsetfade 1;
CONTROL ctrlcommit 0;

while {!AZC_TERM_NAMES} do 
{
	_target = cursortarget;
	if (!isnull _target && !visiblemap) then 
	{
		_pos = [getposatl _target select 0,getposatl _target select 1,(getposatl _target select 2) + 1.5];
		_pos2D = worldtoscreen _pos;
		_text = _target getvariable "BIS_info";
		if (count _pos2D > 0 && !isnil "_text") then 
		{
			CONTROL ctrlsetposition 
			[
				(_pos2D select 0)+0.1,
				(_pos2D select 1),
				_w,
				_h
			];
			CONTROL ctrlsetstructuredtext parsetext _text;
			CONTROL ctrlsetfade 0;
			CONTROL ctrlcommit 0.01;

		} 
		else 
		{
			CONTROL ctrlsetfade 1;
			CONTROL ctrlcommit 0.1;
		};
	} else 
	{
		CONTROL ctrlsetfade 1;
		CONTROL ctrlcommit 0.1;
	};
	sleep 0.01;
};

21 cuttext ["","plain"];
};

Description.ext:

http://community.bistudio.com/wiki/Description.ext#CfgIdentities

Init.sqf:

AZC_fnc_displayName = compile preprocessFileLineNumbers "functions\fnc_displayName.sqf";
[[[color="Red"]unit1, unit2, unit3[/color]]] call AZC_fnc_displayName;

stringtable.xml:

  <?xml version="1.0" encoding="utf-8" ?> 
- <Project name="GambitRoyale">
- <Package name="Campaign">
- <Container name="Missions">
- <Key ID="STR_INFONAME_[color="Red"]unit1[/color]">
 <English>[color="Red"]Grenadier[/color]</English> 
 </Key>
- <Key ID="STR_INFONAME_[color="Red"]unit2[/color]">
 <English>[color="Red"]Automatic Rifleman[/color]</English> 
 </Key>
- <Key ID="STR_INFONAME_[color="Red"]unit3[/color]">
 <English>[color="Red"]Asst. Team Leader[/color]</English> 
 </Key>
 </Container>
 </Package>
 </Project>

The red marked stuff needs to be changed by you !

Edited by Wiggum

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  

×