Jump to content
Sign in to follow this  
dreadedentity

Simple Icons

Recommended Posts

Dread's Simple Icons

Hello all,

Have you ever wanted to put icons above the heads of certain units? You're in luck! Now that's possible. This has now become a 2-part release, the original script and a (supposedly) JIP compatible version. Let me state for the record right now that I'm no good at multiplayer scripting, but that shouldn't be a problem because of the way I set up the JIP script anyway. Have fun!

9/24/2014 1:35pm US eastern:

I have just updated both scripts, you can now choose the icon you use for each unit. If you don't want to, the script will revert to the old way of auto-choosing based on side.

Example Mission (Dropbox) (contains old scripts, copy/paste from below)

Photo from example Mission:

http://i.imgur.com/Itl0llM.jpg (177 kB)

Notes:

You can leave P2 as "" to have no text underneath the icons.

You can make and use your own icons with the latest release!

(untested)DO NOT TERMINATE YOUR SCRIPT. It will not stop drawing the icons, actually, all it will do is make it not possible to ever stop drawing the icons because that code is contained within the script itself. The correct way to stop drawing the icons is with BIS_fnc_removeStackedEventHandler. You can then terminate the script if you wish.

Version: Consider-to-be Final Release (I might add stuff if the suggestions are really awesome)

Stable in: Current release of Arma 3 (at the date of this posting).

Known Bugs: None that I know of.

DE_simpleIcons.sqf

/////////////////////////////////////
// Function file for Armed Assault //
// Created by: DreadedEntity       //
/////////////////////////////////////

/*
USAGE:

_handle = ["P1", "P2", ["P3_a", "P3_b", "P3_c", etc.], P4, "P5"] execVM "DE_simpleIcons.sqf";

_handle = Can be anything. Multiple instances can use the exact same handle without issue.
P1: STRING - UNIQUE(!!!) name for the onEachFrame event. Name must be unique or instances will be overwritten.
P2: STRING - Text you want to appear under each icon.
P3: ARRAY - Array of classnames("STRINGS") of units you want to make icons for.
P4: NUMBER - Distance from player to create unit icons.
P5: STRING (OPTIONAL) - Name of icon you want to use. (include filetype)

EXAMPLE:
null = ["eachFrame", "Kill", ["O_SOLDIER_F", "O_OFFICER_F"], 1000, "targetCiv.jpg"] execVM "DE_simpleIcons.sqf";
Any Opfor riflemen and officers within 1000 meters of the player will have a purple marker above their heads when run.
*/

_name = _this select 0;
_text = _this select 1;
_classNames = _this select 2;
_distance = _this select 3;
_icon = [_this, 4, "None", [""]] call BIS_fnc_param;

waitUntil {time > 0};

MISSION_ROOT = call {
   private "_arr";
   _arr = toArray __FILE__;
   _arr resize (count _arr - 19);
   toString _arr
}; //Kudos to Killzone_Kid for this

_units = nearestObjects [player, _classNames, _distance];

[_name, "onEachFrame", 
{
{
	if ((alive _x) && {!isPlayer _x}) then
	{
		_iSize = (0.5) - (0.01 / (player distance _x));
		_unitPos = [(getPos _x) select 0, (getPos _x) select 1, ((getPos _x) select 2) + 2];
		if (_this select 2 != "None") then
		{
			drawIcon3D[MISSION_ROOT + "\icons\" + (_this select 2), [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];
		} else
		{
			switch (side _x) do
			{
				case west: {drawIcon3D[MISSION_ROOT + "\icons\targetWest.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
				case east: {drawIcon3D[MISSION_ROOT + "\icons\targetEast.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
				case independent: {drawIcon3D[MISSION_ROOT + "\icons\targetGuer.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
				case civilian: {drawIcon3D[MISSION_ROOT + "\icons\targetCiv.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
			};
		};
	};
}forEach (_this select 0);
}, [_units, _text, _icon]] call BIS_fnc_addStackedEventHandler;

waitUntil {{alive _x} count _units == 0};

[_name, "onEachFrame"] call BIS_fnc_removeStackedEventHandler;

@PersianMO brought it to my attention that this might not work with JIP's so I modified the script and it should work with JIP's perfectly

DE_simpleIconsJIP.sqf

/////////////////////////////////////
// Function file for Armed Assault //
// Created by: DreadedEntity       //
/////////////////////////////////////

/*
USAGE:

_handle = ["P1", "P2", [P3_a, P3_b, P3_c, etc.], "P4"] execVM "DE_simpleIconsJIP.sqf";

_handle = Can be anything. Multiple instances can use the exact same handle without issue.
P1: STRING - UNIQUE(!!!) name for the onEachFrame event. Name must be unique or instances will be overwritten.
P2: STRING - Text you want to appear under each icon.
P3: ARRAY - Array of OBJECTS you want to make icons for.
P4: STRING (OPTIONAL) - Name of icon you want to use. (include filetype)

EXAMPLE:
null = ["eachFrame", "Kill", enemyUnits] execVM "DE_simpleIconsJIP.sqf";
*/

_name = _this select 0;
_text = _this select 1;
_units = _this select 2;
_icon = [_this, 3, "None", [""]] call BIS_fnc_param;

waitUntil {time > 0};

MISSION_ROOT = call {
   private "_arr";
   _arr = toArray __FILE__;
   _arr resize (count _arr - 22);
   toString _arr
}; //Kudos to Killzone_Kid for this

[_name, "onEachFrame", 
{
{
	if ((alive _x) && {!isPlayer _x}) then
	{
		_iSize = (0.5) - (0.01 / (player distance _x));
		_unitPos = [(getPos _x) select 0, (getPos _x) select 1, ((getPos _x) select 2) + 2];
		if (_this select 2 != "None") then
		{
			drawIcon3D[MISSION_ROOT + "\icons\" + (_this select 2), [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];
		} else
		{
			switch (side _x) do
			{
				case west: {drawIcon3D[MISSION_ROOT + "\icons\targetWest.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
				case east: {drawIcon3D[MISSION_ROOT + "\icons\targetEast.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
				case independent: {drawIcon3D[MISSION_ROOT + "\icons\targetGuer.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
				case civilian: {drawIcon3D[MISSION_ROOT + "\icons\targetCiv.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};
			};
		};
	};
}forEach (_this select 0);
}, [_units, _text, _icon]] call BIS_fnc_addStackedEventHandler;

waitUntil {{alive _x} count _units == 0};
[_name, "onEachFrame"] call BIS_fnc_removeStackedEventHandler;

All persons are free to use and modify these scripts to fit their needs, provided the original credit remains intact or I am credited somewhere in the modified script.

Edited by DreadedEntity
Edited title to make it apparent that this is a release

Share this post


Link to post
Share on other sites

Thanks, overall I'm happy with how it turned out. I only wish that I could find the magical algorithm I'm looking for to make accurately sized icons depending on distance from the unit.

Also, I hope somebody can find something cool to do with this.

Share this post


Link to post
Share on other sites
Guest

Release frontpaged on the Armaholic homepage.

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

You are not registered on Armaholic, or at least not that we are aware of. In the future we offer the possibility to authors to maintain their own pages.

If you wish to be able to do this as well please register on Armaholic and let me know about it.

This is not mandatory at all! Only if you wish to control your own content you are welcome to join, otherwise we will continue to follow your work like we have always done ;)

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

Is it possible to get the same result with objects? (not units)

For example - visible Helipad at a certain distance due to your icon.

Share this post


Link to post
Share on other sites
Is it possible to get the same result with objects? (not units)

For example - visible Helipad at a certain distance due to your icon.

You would just need another case under the switch as well as another icon to display for the object.

Edited by JShock

Share this post


Link to post
Share on other sites

Yes, something like this should work

default {drawIcon3D[MISSION_ROOT + "\icons\targetEast.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};

Usage:

switch (something) do
{
    case a: {};
    case b: {};
    case c: {};
    default {};
};

I'll look into creating a better way to do this, but ideally, you want to put a little code as possible in since it will be running at least 50-60 times per second.

Share this post


Link to post
Share on other sites
Is it possible to get the same result with objects? (not units)

For example - visible Helipad at a certain distance due to your icon.

Looks like This script working with class_names too, something like this:

Add icon on a NATO ammo box "Box_NATO_Ammo_F"

init.sqf

null = ["eachFrame5", "Ammo", ["Box_NATO_Ammo_F"], 1000] execVM "DE_simpleIcons.sqf";

Then add line to case part

DE_simpleIcons.sqf

case Box_NATO_Ammo_F: {drawIcon3D[MISSION_ROOT + "\icons\targetCiv.jpg", [1,1,1,0.5], _unitPos, _iSize, _iSize, 0, _this select 1];};

Good work, DreadedEntity.

Did you test script in MP and dedicated server? working for JIP players too?

Share this post


Link to post
Share on other sites
Good work, DreadedEntity.

Did you test script in MP and dedicated server? working for JIP players too?

Thanks. I didn't do any tests in multiplayer, but all of the icon drawing is done locally. It should work for JIP's, as I believe they do run init.sqf at some point. The idea I had behind this was to create a local-area effect, like a UAV flying overhead and relaying enemy positions. The only problem with that is there is no guarantee that JIP's will see the same units because some could have gotten outside the search area, or some could have entered the search area. Even having players standing around in different positions could make them show different units.

I may hack together another script that allows you to input an array of OBJECTS and place markers over their heads. In fact, now that I think about it, it probably should have been that way all along.

EDIT: I edited the original post with a second script that should be perfect for JIP's

EDIT2: @MacintoshRUS it wasn't with the version of the script you saw, at least I don't think it was. I just updated the script to include being able to use custom icons. Since I don't know the effect of using the side command on a non-unit object, I strongly recommend specifying the icon you want to use to prevent the script trying to use it.

Edited by DreadedEntity

Share this post


Link to post
Share on other sites
EDIT: I edited the original post with a second script that should be perfect for JIP's

Thank you so much. So i should call DE_simpleIconsJIP.sqf script just for JIP players?

Share this post


Link to post
Share on other sites
Thank you so much. So i should call DE_simpleIconsJIP.sqf script just for JIP players?

No, you can call DE_simpleIcons.sqf also if you want, rather than be specifically for JIP's DE_simpleIconsJIP.sqf was just meant to synchronize what teammates see and what a joined player sees. Ideally, you would add all enemies to an array after creating them, then publicVariable the array, which could be received by a JIP, and then that JIP could run DE_simpleIconsJIP.sqf with the array as a parameter, ensuring that he sees what the other players are seeing. But you could use DE_simpleIconsJIP.sqf exclusively if you want.

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  

×