Jump to content

Recommended Posts

Hi all,

 

I encounter a problem with JIP players for a name tags script.

 

When a player do JIP the name tags of currently connected players aren't shown until they respawn once. But after one respawn from other players the script works correctly even if the JIP player do JIP again.

I tried many ways to find a solution but for now I'm still stuck with this...

 

init.sqf :

[] execVM "scripts\nameTags.sqf";

initServer.sqf :

waitUntil {time > 0};

arrPlayers = [];

initPlayerServer.sqf :

_player = _this select 0;

waitUntil {(!isNull _player) && (_player == _player)};
waitUntil {time > 0};

waitUntil {!isNil "arrPlayers"};

_playerID = "playerID" + "_" + (getPlayerUID _player);

arrPlayers pushBackUnique _playerID; publicVariable "arrPlayers";

[[_player, _playerID], {

	params ["_player", "_playerID"];

	missionNamespace setVariable [_playerID, _player, false];
	_player setVehicleVarName _playerID;

}] remoteExec ["spawn", 0];

initPlayerLocal.sqf :

_didJIP = _this select 1;

waitUntil {(!isNull player) && (player == player)};

if (_didJIP) then {

	{

		//waitUntil {alive player};
		waitUntil {(!isNull player) && (player == player) && !((lifeState player) in ["DEAD", "DEAD-RESPAWN", "DEAD-SWITCHING"])};

		_playerID = "playerID" + "_" + (getPlayerUID player);

		[
			[player, _playerID],
			{
				params ["_player", "_playerID"];

				missionNamespace setVariable [_playerID, _player, false];
				_player setVehicleVarName _playerID;
			}
		]
		remoteExec ["call", remoteExecutedOwner];
	}
	remoteExec ["spawn", [0, -2] select isDedicated];

};

nameTags.sqf :

if !(hasInterface) exitWith {};

MISSION_ROOT = getMissionPath "";

KK_fnc_trueZoom = {
    (
        [0.5,0.5]
        distance2D
        worldToScreen
        positionCameraToWorld
        [0,3,4]
    ) * (
        getResolution
        select 5
    ) / 2
};

fnc_nameTags = {

	#define LIMITDISTANCE 2000
	#define NAMEDISTANCE 250
	#define ICON_sizeScale 0.75

	idNameTags = addMissionEventHandler ["Draw3D", {

		{
			_unit = (call compile _x);

			if (!(player distance2D _unit > LIMITDISTANCE) && alive _unit /*&& player != _unit*/ && !isNull _unit && (vehicle _unit == _unit || (vehicle _unit != _unit && effectiveCommander vehicle _unit == _unit))) then {

				_distanceUI = round (_unit distance vehicle player);
				_icon = "pictures\WEST.paa";
				_textSpaced = 0.0062;


			    _targetPosition = _unit modelToWorldVisual[0,0,2];
			    _playerPosition = positionCameraToWorld[0,0,0];

			    _distance = _targetPosition distance _playerPosition;

			   	_fov = call KK_fnc_trueZoom;

			    _dir = _targetPosition vectorDiff _playerPosition;

			    _playerDir = _playerPosition vectorFromTo positionCameraToWorld[0,0,1];

			    //_cross = (_playerDir) vectorCrossProduct (vectorUp player);
			    _cross = (_playerDir) vectorCrossProduct [0,0,1];

			    _drawUpNormal = vectorNormalized (_cross vectorCrossProduct _dir);

			    // CHECK INJURED
			    private ["_icon"];
			    if (lifeState _unit == "INCAPACITATED") then {_icon = MISSION_ROOT + "pictures\INJURED.paa"} else {_icon = MISSION_ROOT + "pictures\WEST.paa"};


			    // ICON
			    _uiScale = (0.55 / (getResolution select 5)) * ICON_sizeScale;
				_iconSize = (1 - ((_distance / LIMITDISTANCE) * 0.7)) * _uiScale * 1;

			    _drawUpIcon = _drawUpNormal vectorMultiply ((_textSpaced*2.8) * _distance / _fov);
			    _drawPosIcon = _targetPosition vectorAdd _drawUpIcon;
			    drawIcon3D [_icon, [1,1,1,1], _drawPosIcon, _iconSize, _iconSize, 0];

			    // NAME
			    private ["_drawPosDist"];

			    if (_distance <= NAMEDISTANCE || {cursorTarget == _unit}) then {

			    	_drawUpName = _drawUpNormal vectorMultiply ((_textSpaced*2) * _distance / _fov);
			    	_drawPosName = _targetPosition vectorAdd _drawUpName;

			    	if (damage _unit > 0 && player getUnitTrait "Medic" && !(lifeState _unit == "INCAPACITATED")) then {

			    		drawIcon3D ["", [1,1,1,1], _drawPosName, 0, 0, 0, (name _unit) + " (" + (str (floor((1 - damage _unit) * 100))) + "%)", 2];
			    	} else {

			    		drawIcon3D ["", [1,1,1,1], _drawPosName, 0, 0, 0, name _unit, 2];
			    	};

			    	_drawUpDist = _drawUpNormal vectorMultiply (_textSpaced * _distance / _fov);
			    	_drawPosDist = _targetPosition vectorAdd _drawUpDist;

			    } else {

			    	_drawUpDist = _drawUpNormal vectorMultiply ((_textSpaced*2) * _distance / _fov);
			    	_drawPosDist = _targetPosition vectorAdd _drawUpDist;
			    };

			    // DISTANCE
			    drawIcon3D ["", [0.8,1,1,1], _drawPosDist, 0, 0, 0, format ["%1 m", _distanceUI], 2];

			    // VEHICLE
				if (vehicle _unit != _unit && effectiveCommander vehicle _unit == _unit) then {

					_drawUpVeh = _drawUpNormal vectorMultiply ((_textSpaced*4.6) * _distance / _fov);
					_drawPosVeh = _targetPosition vectorAdd _drawUpVeh;
					_veh = getText (configFile >> "CfgVehicles" >> (typeOf vehicle _unit) >> "DisplayName");
					drawIcon3D ["", [0.443,0.776,0.443,1], _drawPosVeh, 0, 0, 0, _veh, 2];
				};
			};

		} forEach arrPlayers;
	}];

};

fnc_toogleNameTags = {

	if (!isNil "idNameTags") then {

		systemChat "Name tags desactivated";
		removeMissionEventHandler ["Draw3D", idNameTags];
		idNameTags = nil;

	} else {

		systemChat "Name tags activated";
		[] call fnc_nameTags;

	};
};

waituntil {!isnull (finddisplay 46)};
(findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 219) then {[] call fnc_toogleNameTags}"];

Thanks to Whalenator for his multi-line with drawIcon3D !

 

 

 

Rather than using allPlayers command to get all connected players in order to draw the name tags, I used an array if string with the UID of each players broadcasted by the server.

 

Normally the problem come from the initPlayerLocal.sqf where a JIP player ask all other clients thier UID and player object.

 

Here is a sample mission for testing : nameTags.VR.pbo

 

To activate/desactivate the name tags use the WIN LEFT key.

Share this post


Link to post
Share on other sites
19 hours ago, Crazy_Man said:

init.sqf :


[] execVM "scripts\nameTags.sqf";

 

Have you tried running this from initPlayerLocal.sqf instead?

Share this post


Link to post
Share on other sites
28 minutes ago, RCA3 said:

Have you tried running this from initPlayerLocal.sqf instead?

It contains

if !(hasInterface) exitWith {};

at the beginning, so it will work only on client PCs.

I would recommend to rewrite the script that it will be client only.

Share this post


Link to post
Share on other sites

Thanks for the responses.

 

Since the fnc_nametags is fired by a displayAddEventHandler the script is excuted localy for each clients, no problem with that.

 

So basically the problem occurs only if a player do JIP and so cannot see the nametags of already connected players who didn't respawn at least once since he connected.

 

I figure that, in the initPlayerlocal.sqf, the line :

waitUntil {(!isNull player) && (player == player) && !((lifeState player) in ["DEAD", "DEAD-RESPAWN", "DEAD-SWITCHING"])};

(who try to check if an already connected client responde to the JIP client with his player object when it is not null (not dead or not waiting for respawn) in order to name it locally as a variable on the JIP client) doesn't work as intended...

 

Share this post


Link to post
Share on other sites
2 hours ago, Crazy_Man said:

I figure that, in the initPlayerlocal.sqf, the line :


waitUntil {(!isNull player) && (player == player) && !((lifeState player) in ["DEAD", "DEAD-RESPAWN", "DEAD-SWITCHING"])};

(...) doesn't work as intended...

I don't think you need that line or the other above that...

On 5/16/2021 at 1:06 AM, Crazy_Man said:

waitUntil {(!isNull player) && (player == player)};

...when using initPlayerlocal.sqf.

 

Try what I said first (and remove those two lines) and we can go from there...

Share this post


Link to post
Share on other sites

Ok, tested right now on dedicated but same issue.

 

I just rectify a detail :

 

"So basically the problem occurs only if a player do JIP and so cannot see the nametags of already connected players who didn't respawn at least once since he connected."

 

If I try a second JIP I can see the nametags of my friend who already respawned once.

 

initPlayerLocal.sqf :

_didJIP = _this select 1;


if (_didJIP) then {

	{

		_playerID = "playerID" + "_" + (getPlayerUID player);

		[
			[player, _playerID],
			{
				params ["_player", "_playerID"];

				missionNamespace setVariable [_playerID, _player, false];
				_player setVehicleVarName _playerID;
			}
		]
		remoteExec ["call", remoteExecutedOwner];
	}
	remoteExec ["spawn", [0, -2] select isDedicated];

};

[] execVM "scripts\nameTags.sqf";

 

 

Share this post


Link to post
Share on other sites

Try commenting out this on initPlayerServer.sqf:

waitUntil {(!isNull _player) && (_player == _player)};
waitUntil {time > 0};

edit: check your inbox.

  • Thanks 1

Share this post


Link to post
Share on other sites

waitUntil {(!isNull _player) && (_player == _player)};

waitUntil {time > 0};

 

is useless in initPlayerLocal.sqf   & initPlayerServer.sqf (player has joined)

(and weird _player == _player is just a waste of code,... player == player or even _player == player could be understandable in initPlayerLocal but still useless anyway)

 

Player command is available and local for initPlayerLocal as the name of sqf supposes. (This command has no sense on dedicated server)

 

  • Thanks 1

Share this post


Link to post
Share on other sites

The problem is solved !

 

Thanks for responses.

 

Special thanks to RCA3 for testing. 😉

 

initServer.sqf :

waitUntil {time > 0};

arrPlayers = [];

initPlayerServer.sqf :

_player = _this select 0;

waitUntil {!isNil "arrPlayers"};

_playerID = "playerID" + "_" + (getPlayerUID _player);

arrPlayers pushBackUnique _playerID; publicVariable "arrPlayers";

initPlayerLocal.sqf :

[_this select 1] execVM "scripts\nameTags.sqf";

nameTags.sqf :

params ["_didJIP"];

_playerID = "playerID" + "_" + (getPlayerUID player);

[[player, _playerID, _didJIP],{

		if (!hasInterface) exitWith {};

		params ["_player", "_playerID", "_didJIP"];

		missionNamespace setVariable [_playerID, _player, false];
		_player setVehicleVarName _playerID;


		if (_didJIP) then {

			_clientID = "playerID" + "_" + (getPlayerUID player);

			[
				[player, _clientID],
				{
					params ["_player", "_clientID"];

					missionNamespace setVariable [_clientID, _player, false];
					_player setVehicleVarName _clientID;
				}
			]
			remoteExecCall ["call", remoteExecutedOwner];

		};
	}
]
remoteExecCall ["call", 0];


MISSION_ROOT = getMissionPath "";

KK_fnc_trueZoom = {
    (
        [0.5,0.5]
        distance2D
        worldToScreen
        positionCameraToWorld
        [0,3,4]
    ) * (
        getResolution
        select 5
    ) / 2
};

fnc_nameTags = {

	#define LIMITDISTANCE 2000
	#define NAMEDISTANCE 250
	#define ICON_sizeScale 0.75

	idNameTags = addMissionEventHandler ["Draw3D", {

		{
			_unit = (call compile _x);

			if (!(player distance2D _unit > LIMITDISTANCE) && alive _unit/* && player != _unit */&& !isNull _unit && (vehicle _unit == _unit || (vehicle _unit != _unit && effectiveCommander vehicle _unit == _unit))) then {

				_distanceUI = round (_unit distance vehicle player);
				_icon = "pictures\WEST.paa";
				_textSpaced = 0.0062;


			    _targetPosition = _unit modelToWorldVisual[0,0,2];
			    _playerPosition = positionCameraToWorld[0,0,0];

			    _distance = _targetPosition distance _playerPosition;

			   	_fov = call KK_fnc_trueZoom;

			    _dir = _targetPosition vectorDiff _playerPosition;

			    _playerDir = _playerPosition vectorFromTo positionCameraToWorld[0,0,1];

			    _cross = (_playerDir) vectorCrossProduct [0,0,1];

			    _drawUpNormal = vectorNormalized (_cross vectorCrossProduct _dir);

			    // CHECK INJURED
			    private ["_icon"];
			    if (lifeState _unit == "INCAPACITATED") then {_icon = MISSION_ROOT + "pictures\INJURED.paa"} else {_icon = MISSION_ROOT + "pictures\WEST.paa"};


			    // ICON
			    _uiScale = (0.55 / (getResolution select 5)) * ICON_sizeScale;
				_iconSize = (1 - ((_distance / LIMITDISTANCE) * 0.7)) * _uiScale * 1;

			    _drawUpIcon = _drawUpNormal vectorMultiply ((_textSpaced*2.8) * _distance / _fov);
			    _drawPosIcon = _targetPosition vectorAdd _drawUpIcon;
			    drawIcon3D [_icon, [1,1,1,1], _drawPosIcon, _iconSize, _iconSize, 0];

			    // NAME
			    private ["_drawPosDist"];

			    if (_distance <= NAMEDISTANCE || {cursorTarget == _unit}) then {

			    	_drawUpName = _drawUpNormal vectorMultiply ((_textSpaced*2) * _distance / _fov);
			    	_drawPosName = _targetPosition vectorAdd _drawUpName;

			    	if (damage _unit > 0 && player getUnitTrait "Medic" && !(lifeState _unit == "INCAPACITATED")) then {

			    		drawIcon3D ["", [1,1,1,1], _drawPosName, 0, 0, 0, (name _unit) + " (" + (str (floor((1 - damage _unit) * 100))) + "%)", 2];
			    	} else {

			    		drawIcon3D ["", [1,1,1,1], _drawPosName, 0, 0, 0, name _unit, 2];
			    	};

			    	_drawUpDist = _drawUpNormal vectorMultiply (_textSpaced * _distance / _fov);
			    	_drawPosDist = _targetPosition vectorAdd _drawUpDist;

			    } else {

			    	_drawUpDist = _drawUpNormal vectorMultiply ((_textSpaced*2) * _distance / _fov);
			    	_drawPosDist = _targetPosition vectorAdd _drawUpDist;
			    };

			    // DISTANCE
			    drawIcon3D ["", [0.8,1,1,1], _drawPosDist, 0, 0, 0, format ["%1 m", _distanceUI], 2];

			    // VEHICLE
				if (vehicle _unit != _unit && effectiveCommander vehicle _unit == _unit) then {

					_drawUpVeh = _drawUpNormal vectorMultiply ((_textSpaced*4.6) * _distance / _fov);
					_drawPosVeh = _targetPosition vectorAdd _drawUpVeh;
					_veh = getText (configFile >> "CfgVehicles" >> (typeOf vehicle _unit) >> "DisplayName");
					drawIcon3D ["", [0.443,0.776,0.443,1], _drawPosVeh, 0, 0, 0, _veh, 2];
				};
			};

		} forEach arrPlayers;
	}];

};

fnc_toogleNameTags = {

	if (!isNil "idNameTags") then {

		systemChat "Name tags desactivated";
		removeMissionEventHandler ["Draw3D", idNameTags];
		idNameTags = nil;

	} else {

		systemChat "Name tags activated";
		[] call fnc_nameTags;

	};
};

waituntil {!isnull (finddisplay 46)};
(findDisplay 46) displayAddEventHandler ["KeyDown", "if ((_this select 1) == 219) then {[] call fnc_toogleNameTags}"];

 

SOLVED

  • Like 1

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

×