taro8 806 Posted June 7, 2011 Hello everyone. I wanted to ask how can I display custom unit name above its head. I have team of 4 guys and I want their callsigns to show above their heads. I already tried 3D credits, but text dosent move with units and it dosent stay in place if you move away or get closer. I wanted nameplate to howver just above head at all times How should I do this? Note: I did check out threads about 3D credits, but I wasnt able to find or understand how to do this properly. Share this post Link to post Share on other sites
2nd ranger 282 Posted June 7, 2011 (edited) EDIT: Obviously this requires the Functions Module to be present in the mission. Save this as a text file called, for example, Names.hpp. Make sure the file type is saved as .hpp and it's not just called that. Run it from init like this NameTags = preprocessFileLineNumbers "Names.hpp"; #include "Names.hpp"; The section I have highlighted is the relevant part for your needs, //--- Character introduction _playerID = [1,0] select (player == player); // Generic Tags { //_info = format ["%1",name _x]; //_info = localize format ["STR_PMC_CP01_INFO_%1_%2",_playerID,vehiclevarname _x]; _x setvariable [ "BIS_info", //format ["<t align='left'>%1<br /><t size='0.5'>%2</t></t>",_names select _forEachIndex,_info] format ["<t color='#cccccc' size='0.7' align='left' font='TahomaB'>%1</t><br/> <t color='#4AA02C' size='0.4' align='left' font='Zeppelin33'>US Army Soldier</t>",name _x] ]; } foreach []; { //_info = format ["%1",name _x]; //_info = localize format ["STR_PMC_CP01_INFO_%1_%2",_playerID,vehiclevarname _x]; _x setvariable [ "BIS_info", //format ["<t align='left'>%1<br /><t size='0.5'>%2</t></t>",_names select _forEachIndex,_info] format ["<t color='#cccccc' size='0.7' align='left' font='TahomaB'>%1</t><br/> <t color='#DC143C' size='0.4' align='left' font='Zeppelin33'>%2</t>",name _x,faction _x] ]; } foreach switchableunits; //Custom Tags [b] _names = ["<t color='#cccccc' size='0.5' align='left' font='TahomaB'>[color="Blue"]Sgt. Petrov[/color]</t><br /> <t color='#DC143C' size='0.3' align='left' font='Zeppelin33'>[color="DarkRed"]Team Leader[/color]</t>", "<t color='#cccccc' size='0.5' align='left' font='TahomaB'>[color="Blue"]General Zhukov[/color]</t><br /> <t color='#DC143C' size='0.3' align='left' font='Zeppelin33'> [color="DarkRed"]K-9 Tracker[/color]</t>", "<t color='#cccccc' size='0.6' align='left' font='TahomaB'>[color="Blue"]Spc. Subakov[/color]</t><br /> <t color='#DC143C' size='0.35' align='left' font='Zeppelin33'>[color="DarkRed"]K-9 Handler[/color]</t>" ]; { //_info = localize format ["",_playerID,vehiclevarname _x]; //_info = localize format ["STR_PMC_CP01_INFO_%1_%2",_playerID,vehiclevarname _x]; _x setvariable [ "BIS_info", format ["%1",_names select _forEachIndex] ]; } foreach [[color="Green"]Petrov, Zhukov, Subakov[/color]]; [/b] [] spawn {scopename "CP01: Character info"; sleep 0.1; if (bis_contact) exitwith {}; disableserialization; 21 cutrsc ["rscDynamicText","plain"]; #define DISPLAY (uinamespace getvariable "BIS_dynamicText") #define CONTROL (DISPLAY displayctrl 9999) _w = 1;//0.5; _h = 1;//0.3; CONTROL ctrlsetposition [ 0, 0, _w, _h ]; CONTROL ctrlsetfade 1; CONTROL ctrlcommit 0; while {!BIS_contact} 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"]; }; This will display a custom name you give the unit, currently in white but you can change that, and underneath, in red and a smaller font, there will be a tag, like 'Team Leader'. Blue = Your custom name for the unit Red = Custom tag underneath the name Green = The units' actual names you gave them in the editor, obviously in the order you define them above. This displays the names when you point at the unit. I don't know how to make it display the names at all times. There is a variable in the script that you can set to true if for some reason you don't want to see the names anymore. Currently it is BIS_Contact but you can change it to whatever. You must set BIS_Contact = false; in the init for this to work. EDIT: Also, the section at the top of the script (Generic Tags) allows you to display the actual identity name of the unit so you don't have to define custom names for everyone. This can be useful for things like having alot of friendly forces in the mission who you don't want to shoot accidentally. The only thing you have to define is their 'Tag' underneath the name ('US Army Soldier' in my example), which will appear in green (or any colour of your choice). You can enable it for whomever you like in the ForEach [] part, for example ForEach units groupName/ArrayofUnits/[unit1,Unit2...]. Edited July 30, 2012 by 2nd Ranger Share this post Link to post Share on other sites
therev709 10 Posted June 20, 2011 I cannot for the life of me get this to work. Here is my init.sqf: BIS_Contact = false; if (isserver) then {NameTags = preprocessFileLineNumbers "tags.hpp"; }; #include "tags.hpp"; And here is my tags.hpp: //--- Character introduction _playerID = [1,0] select (player == player); _names = ["<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>SSGT. Ryner</t><br /><t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Squad Leader</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'> SGT. Dunn</t><br /><t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Team Leader</t>" "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>PFC. York</t><br /><t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Anti-Tank</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'> SPC. Guin</t><br /><t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Medic</t>" "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>CPL. Dash</t><br /><t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Automatic Rifleman</t>",]; { _info = localize format ["",_playerID,vehiclevarname _x]; //_info = localize format ["STR_PMC_CP01_INFO_%1_%2",_playerID,vehiclevar name _x]; _x setvariable [ "BIS_info", format ["<t align='left'>%1<br /><t size='0.5'>%2</t></t>",_names select _forEachIndex,_info] ]; } foreach [s1,t1,t2,t3,t4]; [] spawn {scopename "CP01: Character info"; sleep 0.1; if (bis_contact) exitwith {}; disableserialization; 21 cutrsc ["rscDynamicText","plain"]; #define DISPLAY (uinamespace getvariable "BIS_dynamicText") #define CONTROL (DISPLAY displayctrl 9999) _w = 1;//0.5; _h = 1;//0.3; CONTROL ctrlsetposition [ 0, 0, _w, _h ]; CONTROL ctrlsetfade 1; CONTROL ctrlcommit 0; while {!BIS_contact} 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"]; }; Share this post Link to post Share on other sites
2nd ranger 282 Posted June 20, 2011 You had some missing and superfluous commas. Here: _names = ["<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>SSGT. Ryner</t><br /> <t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Squad Leader</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'> SGT. Dunn</t><br /> <t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Team Leader</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>PFC. York</t><br /> <t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Anti-Tank</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'> SPC. Guin</t><br /> <t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Medic</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>CPL. Dash</t><br /> <t color='#DC143C' size='0.4' font='Zeppelin33Italic'> Automatic Rifleman</t>"]; Share this post Link to post Share on other sites
h34dup 148 Posted July 30, 2012 (edited) Hey all, sorry to necropost, but I have been trying to implement this exact system as seen in a couple of great CAMPs I've been playing through. I'd like to add this functionality to my missions moving forward, and was able to extract the code from the SOV TF94 Campaign, and eventually found the following thread: http://forums.bistudio.com/showthread.php?117177-Player-names-above-head I understand how this works for the most part, however, it's acting strangely in the editor for me-- the names will only begin to appear after hitting escape with the cursor over a teammate. Then, once this functionality is active, the names stay on screen even when the player is no longer looking at anyone. Anyone know what's going on? EDIT: it seems to also work when making any adjustment and saving (ie. like when testing changes made to description.ext) after a short delay. If it works reliably in SP once exported then the only real issue is why it's not going away when the player is not looking at anyone. EDIT 2: The code might help, here is my tags.hpp: //--- Character introduction _playerID = [1,0] select (player == player); _names = ["<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Gary</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>Team Leader</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Rick</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>2nd-in-Command</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Doc</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>Medic</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Murray</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>Logistics</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Pappy</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>Communications</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Stan</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>Paramilitary Expert</t>", "<t color='#cccccc' size='0.8' valign='top' font='TahomaB'>Chris</t><br /> <t color='#FF9900' size='0.4' font='Zeppelin33'>Operations</t>"]; { _info = localize format ["",_playerID,vehiclevarname _x]; //_info = localize format ["STR_PMC_CP01_INFO_%1_%2",_playerID,vehiclevar name _x]; _x setvariable [ "BIS_info", format ["<t align='left'>%1<br /><t size='0.5'>%2</t></t>",_names select _forEachIndex,_info] ]; } foreach [Gary, Rick, Doc, Murray, Pappy, Stan, Chris]; [] spawn {scopename "CP01: Character info"; sleep 0.1; if (bis_contact) exitwith {}; disableserialization; 21 cutrsc ["rscDynamicText","plain"]; #define DISPLAY (uinamespace getvariable "BIS_dynamicText") #define CONTROL (DISPLAY displayctrl 9999) _w = 1;//0.5; _h = 1;//0.3; CONTROL ctrlsetposition [ 0, 0, _w, _h ]; CONTROL ctrlsetfade 1; CONTROL ctrlcommit 0; while {!BIS_contact} 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"]; }; Thanks in advance! Edited July 30, 2012 by h34dup Share this post Link to post Share on other sites
roguetrooper 2 Posted July 31, 2012 (edited) There is an easier way to display names. Not the arcadish above-head display, but the names show up when targetting the unit: Put a trigger on the map: * axis 0 - 0 * multiple activation * condition: !(isNull cursortarget) and (alive player) and (alive cursorTarget) and (cursorTarget iskindof "Man") and ((cursorTarget distance player) <= [color="#FF0000"][b]100[/b][/color]) and ((player knowsAbout cursorTarget) > [color="#FF0000"][b]0[/b][/color]) * on activation: txt=name cursorTarget; if !(isPlayer cursorTarget) then {txt="AI"}; ctext = format ["%1",txt]; 123 cutText [ctext,"plain down",0]; * on deactivation: 123 cuttext ["","plain",0]; You can change the red values to your taste. There should be a distance limit (this example: 100 metres) up to which the names are displayed, to have no names show up of units that are hundreds of metres away. This example displays "AI" instead of the unit's name when targetting an AI unit. You can also give further conditions of what names shall show up, such as only the names of the player's allies: ... and (side cursorTarget == side player) and... Edited July 31, 2012 by RogueTrooper Share this post Link to post Share on other sites
h34dup 148 Posted July 31, 2012 (edited) There is an easier way to display names. Not the arcadish above-head display, but the names show up when targetting the unit:Put a trigger on the map: * axis 0 - 0 * multiple activation * condition: !(isNull cursortarget) and (alive player) and (alive cursorTarget) and (cursorTarget iskindof "Man") and ((cursorTarget distance player) <= [color="#FF0000"][b]100[/b][/color]) and ((player knowsAbout cursorTarget) > [color="#FF0000"][b]0[/b][/color]) * on activation: txt=name cursorTarget; if !(isPlayer cursorTarget) then {txt="AI"}; ctext = format ["%1",txt]; 123 cutText [ctext,"plain down",0]; * on deactivation: 123 cuttext ["","plain",0]; You can change the red values to your taste. There should be a distance limit (this example: 100 metres) up to which the names are displayed, to have no names show up of units that are hundreds of metres away. This example displays "AI" instead of the unit's name when targetting an AI unit. You can also give further conditions of what names shall show up, such as only the names of the player's allies: ... and (side cursorTarget == side player) and... Thanks RogueTrooper! I gave this a shot and it works, but this is for a SP campaign, so all of the team members show up as AI. Although I did like the formatting of the original example, this one is more minimal and functional, and I'd happily use it if I can make it work for each individual AI (some will be playable in certain missions, others wont) team member -- showing the team member's name and role within the team (which isn't the unit role displayed by default). So the question is: how could we make the trigger test for whether cursorTarget was pointing at a specific unit? I was looking at isAgent, although I'm not sure what the proper handle would be. EDIT: I see that you can remove it saying "AI" in the On Activation field, now I'm wondering if I can assign the role of each unit to display next to or underneat the name on a second line. EDIT 2: Figured it out, it's simpler than I thought. In the On Activation field you can say: if (Doc == cursorTarget) then {txt="Doc\nMedic"}; Edited July 31, 2012 by h34dup Share this post Link to post Share on other sites
h34dup 148 Posted July 31, 2012 I found the original threads, turns out AZCoder was the originator of the functionality, yet even in his test mission, the names don't go away when the cursorTarget is not on a displayname-enabled unit. However, the two Camps I've seen seem to have this working correctly. I've PM'ed AZC in hopes of finding out the issue with the original code. http://forums.bistudio.com/showthread.php?129117-3D-text-on-objects http://forums.bistudio.com/showthread.php?125162-Player-names-over-player&p=2025914#post2025914 Rogue's alternative is in-place and working like I want it to (although the names cant be formatted, which is what I still want to do, and the reason I'm still probing for answers with this AZC function), so thanks for providing me with a working plan-B! Share this post Link to post Share on other sites
kylania 568 Posted July 31, 2012 You guys are thinking small time. Go big! Use attachTo to stick a main battle tank on the guy's head and have a custom setObjectTexture with the name on the barrel of the tank's main gun. Share this post Link to post Share on other sites
AZCoder 921 Posted July 31, 2012 Kylania - although I really like your idea, I'm not sure many players would appreciate the humor :D I had to test my own test-mission and come to think of it, this function broke after 1.62 patch came out. Except for me, it would not display the name until I hit ESC key. Anyway, that's fixed. I just to had to change the sleep from 0.01 to 0.5, updated mission is available: http://www.azcoder.com/a2files/DisplayNames.Desert_E.zip I also want to clarify that this function is based on what they did in PMC campaign, I just modified it for my own purposes. I've seen a couple other campaigns implement their own version, such as DEVGRU. Share this post Link to post Share on other sites
h34dup 148 Posted July 31, 2012 Kylania - although I really like your idea, I'm not sure many players would appreciate the humor :DI had to test my own test-mission and come to think of it, this function broke after 1.62 patch came out. Except for me, it would not display the name until I hit ESC key. Anyway, that's fixed. I just to had to change the sleep from 0.01 to 0.5, updated mission is available: http://www.azcoder.com/a2files/DisplayNames.Desert_E.zip I also want to clarify that this function is based on what they did in PMC campaign, I just modified it for my own purposes. I've seen a couple other campaigns implement their own version, such as DEVGRU. Awesome, thanks a lot AZC, got it working in a breeze with the new sample mission! Share this post Link to post Share on other sites