Jump to content
  • 0

[WIP] Targets Name and Weapon Information


Salutesh

Question

Hello lovely Epoch Commuity,

 

i need a little help out there because i am still a noob in this...

 

The scripts function:

 

If a player is aiming on a other player he can see get displayed his name, rank and his equiped Weapon infromation, like the name and the picture.

 

What actually works:

 

The name get displayed if you aim a Player and Npc, but no Rank, Weapon image or name will be displayed.

 

 

player_tags.sqf

if (isDedicated) exitWith {};
  
//#define _debug true   //UNCOMMENT TO RUN DEBUG, WILL SHOW TIME TAKEN AND ANY LOSS OF FRAMES
#define _refresh 0.34
#define _distance 300

while{true}do{
        #ifdef _debug
                _initTime = diag_tickTime;
                _frameNo = diag_frameNo;
        #endif
	_blank = " ";
	// PLAYER NAME CHECK AND DISPLAY
        _target = cursorTarget;
        if (_target isKindOf "Man" && player == vehicle player) then{
        	if((side _target == playerSide) && (player distance _target) < _distance)then{
			_weaponsplayer = weapons _target;
			_name = name _target;
                        _nameString = "<t size='0.5' shadow='2' color='#FFFFFF'>" + format['%1 %2',_target getVariable ['unitname', name _target]] + "</t>";
			_weaponsplayer =  _weaponsplayer select 0;
			_weaponsplayername = getText (configFile >> "CfgWeapons" >> _weaponsplayer >> "displayname");
			_weaponspic = getText (configFile >> "CfgWeapons" >> _weaponsplayer >> "picture");
			_rank = [_target,"displayNameShort"] call BIS_fnc_rankParams;

			// PRINT THE RANK/NAME/WEAPON ONSCREEN
			_nameString = format ["<t size='0.6' color='#1c75e4'>%1</t><br/>",_name];
			[_nameString,0.5,0.9,_refresh,0,0,3] spawn bis_fnc_dynamicText;
                };
        };
        #ifdef _debug
        player sidechat format["time: %1, frames: %2",_initTime - diag_tickTime,_frameNo - diag_frameNo];
        #endif
        sleep _refresh;
};

init.sqf

[] execVM "scripts\player_systems\player_tags.sqf";
Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Have rewritten it for you (untested and probably has a few errors).

 

Will cover some of the changes below.

if (isDedicated) exitWith {};
  
//#define _debug true   //UNCOMMENT TO RUN DEBUG, WILL SHOW TIME TAKEN AND ANY LOSS OF FRAMES
#define _refresh 0.34
#define _distance 300
#define _blank " "

// ===========================================================
// Presumption that this should only be against other players.
// ===========================================================

while{true}do{
        if !(isNil "_debug") then {
                _initTime = diag_tickTime;
                _frameNo = diag_frameNo;
        };
	// PLAYER NAME CHECK AND DISPLAY
        _target = cursorTarget;
        
        _isTargetPlayer = (isPlayer _target);
        _isPlayerInVehicle = (Player = vehicle Player);
        
        if ((_isTargetPlayer) && {_isPlayerInVehicle}) then{
        	if(((side _target) == (side player)) && {((player distance _target) < _distance)})then{
			_targetName = name _target;
			_targetRank = [_target,"displayNameShort"] call BIS_fnc_rankParams;
			_targetWeaponName = (weaponstate _target) select 0;
   			_targetWeaponClass = (weaponstate _target) select 1;
			_targetWeaponPic = getText (configFile >> "CfgWeapons" >> _targetWeaponClass >> "picture");

			// PRINT THE RANK/NAME/WEAPON ONSCREEN
			//_nameString = format ["<t size='0.6' color='#1c75e4'>%1</t><br/>",_targetName];
			_nameString = format ["Name: %1, Rank: %2, Weapon [%3]: %3",_targetName, _targetRank, _targetWeaponPic, _targetWeaponName];
			[_nameString,0.5,0.9,_refresh,0,0,3] spawn bis_fnc_dynamicText;
                };
	        if !(isNil "_debug") then {  // only display if target isMan.
		        player sidechat format["time: %1, frames: %2",_initTime - diag_tickTime,_frameNo - diag_frameNo];
		};
        };
        uiSleep _refresh;
};

#IFDEF is fine but quite old Skool ;) .  isNil works just as well.

 

If statements seemed to have a number of brackets missing and if you have the 2nd and subsequent condition evaluations wrapped in {} then it uses lazy evaluation.

 

I personally prefer to get values and then test conditions separately as if statements can sometime be a bit funny if the evaluations are running commands.

 

Playerside returns the players initial side when the mission started which can change over the course of the mission.  Side player give the current player side.

 

WeaponState provides an array fo the current weapon.

 

Have grouped the info gathering together (get name, get rank, get weapon info) more for readibility.

 

Debug only reports to sidechat only if a player is in the crosshairs and not for every object.

 

This only reports for players and not for AI (not sure if that is what you wanted).

 

Not sure why you were defining _nameString twice, removed one definition as it was being overwritten later anyway.

 

Changed sleep to UISleep which is more accurate.

 

I have commented out the formatting for differnet colours / styles and you can add them back in as desired.  I have rewritten the line to define nameString as you didn't include the rank of weapon name originally.

 

Some commands may not work remotely (i.e. if your client is not the owner of the object you are running the command against).  In the BIS Wiki a lot of the commands show if they need to be run agains local or global objects and if the effect is local or global.  Not all of the commands have this info though including weaponState (or weapons for that matter).  

 

Not sure if you can add a weapon pic to a text line as have no experience of trying to do so.

 

The code above is meant to provide a starting point for you to build on.  I will be happy to provide direction on errors and alternative commands but will not be writing, debugging and providing a fully working custom script (well, anymore than I may have already above).  Very busy on writing the A3 total conversion I am doing and don't really have much more spare time.

 

Also, people program in different ways and styles depending on what that particular through process makes easier for them.  The changes above are mainly suggestions and advice meant to help and not intended as criticism.  Everyone starts somewhere and luckily the community here, for the most part, is pretty supportive of new scripters :) .

Link to comment
Share on other sites

  • 0

Have rewritten it for you (untested and probably has a few errors).

 

Will cover some of the changes below.

if (isDedicated) exitWith {};

//#define _debug true //UNCOMMENT TO RUN DEBUG, WILL SHOW TIME TAKEN AND ANY LOSS OF FRAMES

#define _refresh 0.34

#define _distance 300

#define _blank " "

// ===========================================================

// Presumption that this should only be against other players.

// ===========================================================

while{true}do{

if !(isNil "_debug") then {

_initTime = diag_tickTime;

_frameNo = diag_frameNo;

};

    // PLAYER NAME CHECK AND DISPLAY

_target = cursorTarget;

_isTargetPlayer = (isPlayer _target);

_isPlayerInVehicle = (Player = vehicle Player);

if ((_isTargetPlayer) && {_isPlayerInVehicle}) then{

    if(((side _target) == (side player)) && {((player distance _target) < _distance)})then{

            _targetName = name _target;

            _targetRank = [_target,"displayNameShort"] call BIS_fnc_rankParams;

            _targetWeaponName = (weaponstate _target) select 0;

               _targetWeaponClass = (weaponstate _target) select 1;

            _targetWeaponPic = getText (configFile >> "CfgWeapons" >> _targetWeaponClass >> "picture");

            // PRINT THE RANK/NAME/WEAPON ONSCREEN

            //_nameString = format ["<t size='0.6' color='#1c75e4'>%1</t><br/>",_targetName];

            _nameString = format ["Name: %1, Rank: %2, Weapon [%3]: %3",_targetName, _targetRank, _targetWeaponPic, _targetWeaponName];

            [_nameString,0.5,0.9,_refresh,0,0,3] spawn bis_fnc_dynamicText;

};

     if !(isNil "_debug") then { // only display if target isMan.

         player sidechat format["time: %1, frames: %2",_initTime - diag_tickTime,_frameNo - diag_frameNo];

        };

};

uiSleep _refresh;

};

#IFDEF is fine but quite old Skool ;) .  isNil works just as well.

 

If statements seemed to have a number of brackets missing and if you have the 2nd and subsequent condition evaluations wrapped in {} then it uses lazy evaluation.

 

I personally prefer to get values and then test conditions separately as if statements can sometime be a bit funny if the evaluations are running commands.

 

Playerside returns the players initial side when the mission started which can change over the course of the mission.  Side player give the current player side.

 

WeaponState provides an array fo the current weapon.

 

Have grouped the info gathering together (get name, get rank, get weapon info) more for readibility.

 

Debug only reports to sidechat only if a player is in the crosshairs and not for every object.

 

This only reports for players and not for AI (not sure if that is what you wanted).

 

Not sure why you were defining _nameString twice, removed one definition as it was being overwritten later anyway.

 

Changed sleep to UISleep which is more accurate.

 

I have commented out the formatting for differnet colours / styles and you can add them back in as desired.  I have rewritten the line to define nameString as you didn't include the rank of weapon name originally.

 

Some commands may not work remotely (i.e. if your client is not the owner of the object you are running the command against).  In the BIS Wiki a lot of the commands show if they need to be run agains local or global objects and if the effect is local or global.  Not all of the commands have this info though including weaponState (or weapons for that matter).  

 

Not sure if you can add a weapon pic to a text line as have no experience of trying to do so.

 

The code above is meant to provide a starting point for you to build on.  I will be happy to provide direction on errors and alternative commands but will not be writing, debugging and providing a fully working custom script (well, anymore than I may have already above).  Very busy on writing the A3 total conversion I am doing and don't really have much more spare time.

 

Also, people program in different ways and styles depending on what that particular through process makes easier for them.  The changes above are mainly suggestions and advice meant to help and not intended as criticism.  Everyone starts somewhere and luckily the community here, for the most part, is pretty supportive of new scripters :) .

 

Thank you very much for this very detailed listing of what you changed and your help RimBlock!!!

I'm still a beginner and with your help I'm a little smarter :)

I will now take time to look over the script and think about is just to understand what you changed and will then test it.

 

Thank you very much again RimBlock!

 

Got a screenshot of this plz dude?

 

I will post a image then how it looks like in game.

Link to comment
Share on other sites

  • 0

Ok i tested it out and it says there is a missing ( on Line 23 and i get also no player informations.
Try to figure out what is missing but i cant see any typos?!

 

EDIT: Ok i fixed it by myself! WHUAY!!

 

Change:

_isPlayerInVehicle = (Player = vehicle Player);

to:

_isPlayerInVehicle = (Player == vehicle Player);

And it works! I love you RimBlock! :D

Link to comment
Share on other sites

  • 0

Line 24, remove one of the first ('s

        	if(((side _target) == (side player)) && {((player distance _target) < _distance)})then{

so looks

        	if((side _target) == (side player)) && {((player distance _target) < _distance)})then{

worth a try :)

Link to comment
Share on other sites

  • 0

Line 24, remove one of the first ('s

        	if(((side _target) == (side player)) && {((player distance _target) < _distance)})then{

so looks

        	if((side _target) == (side player)) && {((player distance _target) < _distance)})then{

worth a try :)

 

I can try that but is already working without any erros with the fix a post before

Here is how it looks like in game:

 

nzjQLsu.jpg

 

I can just try it out with my HC only because i have no players...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...