Page MenuHomeFeedback Tracker

Swivel Targets will not react to EHs when managed by dedicated server
New, NormalPublic

Description

This is NOT a duplicate of https://feedback.bistudio.com/T86313 !

Reference to research as far as coding knowledge allowed: https://forums.bohemia.net/forums/topic/221167-addmpeventhandler-not-working-on-dedicated-server/

General description:

Swivel Targets adressed via their parent "base" object "Target_Swivel_01_base_F" will not react to EventHandlers placed on hitPart or hit (tested hit this just in case...).

The beheaviour of swivel targets being uncontrollable in MP environment in T86313 could be fixed via following code provided by user https://forums.bohemia.net/profile/900806-pierremgi/

This code is placed in each swivel targets init field in the arma3 editor:

0 = this spawn {
  waitUntil {
    !isNil {_this getVariable "BIS_exitScript"} && { !(_this getVariable "BIS_exitScript")}
  };
  if !(isServer) then {
    _this setVariable ["BIS_exitScript",true]
  }
};

Also user Best2nd (UO) found that the animation source for swivel targets no longer is "terc" but "popup_Source".
Using this in combination with "BIS_leaningEnabled" and "BIS_poppingEnabled" we were at least able to control the swivels actions across all connected clients to the dedicated server the mission was tested on.

While now animation and up/down control work, the swivel will still not react to EH input like normal popup targets do when shot.

Weirdly enough the EH already preconfigured for the swivel targets still uses terc instead of popup_Source. This is beyond my knowledge.

Details

Severity
Trivial
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Operating System Version
1803
Category
Scripting
Steps To Reproduce
  1. Place a swivel target (left/right/ground) on an island in editor.
  2. Create two game logic objects close to it named: a) initCenter b) aSwivelArea
  3. Place code from description in init field of swivel target to enable MP support.
  4. Make sure that the unit you placed has a value set via init: isInstructor
  5. Setup a small sign and name it "testswivel" and use following addAction command on it via script:
if (!isDedicated) then {
//	params ["_player"];
	if (player getVariable ["isInstructor", false]) then {
		testswivel addAction ["<t color='#FF2222'>Raise Practice Targets",{["setup",10,aSwivelArea,true] remoteExec ["Fnc_popup", 2];}];
		testswivel addAction ["<t color='#FF2222'>Lower Practice Targets",{["reset",10,aSwivelArea,false] remoteExec ["Fnc_popup", 2];}];
	};
};
  1. Make sure that the init.sqf of the mission contains:
Fnc_popup = compile preprocessFileLineNumbers "popups.sqf";

if (isServer) then {
	_nul = [] spawn {
		waitUntil {time > 0};
		[] call Fnc_popup;
	};
};
  1. Place this code in the mission folder that is supposed to make the swivels work and name it "popups.sqf":
///////////////////////////////////////////////////////////////////////////////////////////
//Script to be called by inits or scripts for operating swivel and popup
//targets around a specified object "_centerObj".
//params: [ShouldTargetsAutoPop?,WhichSwitchShouldRun?,WhatDistanceFromObject?,WhatObject?]
//By Pax
///////////////////////////////////////////////////////////////////////////////////////////
params [
	["_execution", "init"],
	["_distance", 500],
	["_centerObj", initCenter],
	["_popEnabled", false]
];

_targets = nearestObjects [position _centerObj, ["TargetBase", "Target_Swivel_01_base_F"], _distance];

switch (toLower _execution) do {
	case "init": {
		{
			//isKindOf Swivel else isKindOf popup
			if (typeOf _x isKindOf "Target_Swivel_01_base_F") then {
				_x setVariable ["BIS_leaningEnabled", false, true];
				_x setVariable ["BIS_poppingEnabled", false, true];
				_x animateSource ["popup_Source", 1];
			} else {
				_x setVariable ["nopop", true, true];
				_x animateSource ["terc", 1];
			};
		}forEach _targets;
	};
	
	case "setup": {
		//Make sure _targets are reset before running the setup phase (layerEightProtection)
		["reset", _distance, _centerObj] call Fnc_popup;
		//Inform Instructor who asked for setup that the command was received
		"Command received - Targets are being setup" remoteExec ["systemChat", remoteExecutedOwner];
		{
			if (typeOf _x isKindOf "Target_Swivel_01_base_F") then {
				//Is this target told to auto-pop?
				_x setVariable ["rePop", _popEnabled];
				//Raise the target
				_x animateSource ["popup_Source", 0];
				//Making sure leaning is enabled for the animation
				_x setVariable ["BIS_leaningEnabled", true, true];
				//Add Hit EH and store the EH ID on the target
				_x setVariable [
					"HitEH",
					_x addEventHandler [
						"HitPart", {
							params [
								"_target",
								"",
								"",
								""
							];
							//If auto-pop was set
							if (_target getVariable "rePop") then {
								_target setVariable [
									"rePopThread", _target spawn {
										"AUTOPOP" remoteExec ["systemChat", remoteExecutedOwner];
										sleep (1 + random 4);
										_this animateSource ["popup_Source", 0];
									}
								];
							//No auto-pop set
							} else {
								//Bin Hit EH
								"NOPOP" remoteExec ["systemChat", remoteExecutedOwner];
								((_this select 0) select 0) RemoveEventHandler ["HitPart",0];
								//Clean Shit up
								_target setVariable ["HitEH", nil];
								_target setVariable ["rePop", nil];
							};
						}
					]
				];
			} else {
				//Is this target told to auto-pop?
				_x setVariable ["rePop", _popEnabled];
				//Raise the target
				_x animateSource ["terc", 0];
				//Add Hit EH and store the EH ID on the target
				_x setVariable [
					"HitEH",
					_x addEventHandler [
						"Hit", {
							params [
								"_target",
								"",
								"",
								""
							];
							//If auto-pop was set
							if (_target getVariable "rePop") then {
								_target setVariable [
									"rePopThread", _target spawn {
										sleep (1 + random 4);
										_this animateSource ["terc", 0];
									}
								];
							//No auto-pop set
							} else {
								//Bin Hit EH
								_target removeEventHandler ["Hit", _thisEventHandler];
								//Clean Shit up
								_target setVariable ["HitEH", nil];
								_target setVariable ["rePop", nil];
							};
						}
					]
				];
			};
		} forEach _targets;
	};
	
	case "reset": {
		//Inform Instructor of action
		"Command received - Targets are being reset" remoteExec ["systemChat", remoteExecutedOwner];
		{
			//If the target for whatever reason still has an active EH:
			if !(isNil {_x getVariable "HitEH"}) then {
				//if auto-pop is set
				if (_x getVariable "rePop") then {
					//Is the target currently waiting to rePop?
					if (!isNil {_x getVariable "rePopThread"} && {!isNull (_x getVariable "rePopThread")}) then {
						//If it is waiting, terminate the Thread
						terminate (_x getVariable "rePopThread");
					};
					_x setVariable ["rePopThread", nil];
				};
				if (typeOf _x isKindOf "Target_Swivel_01_base_F") then {
					_x removeEventHandler ["HitPart", _x getVariable "HitEH"];
					_x setVariable ["HitEH", nil];
					_x setVariable ["rePop", nil];
					_x setVariable ["BIS_leaningEnabled", false, true];
					_x animateSource ["popup_Source", 1];
				} else {
					_x removeEventHandler ["Hit", _x getVariable "HitEH"];
					_x setVariable ["HitEH", nil];
					_x setVariable ["rePop", nil];
					_x animateSource ["terc", 1];
				};
			};
			//Lower the targets
		} forEach _targets;
	};
};
  1. Export mission to multiplayer
  2. upload to a dedicated server
  3. connect and run the mission
  4. after spawn the targets should be in constant down state, not moving.
  5. select to raise targets via sign action
  6. shoot the targets and you will see that the EH is not executed.

Popup targets are tested and work as expected including EH and up/down control.

Additional Information

My github where the mission lies is not up to date to the curent code which is on my computer and which I used in this bug report.

Event Timeline