Jump to content
Sign in to follow this  
meatball

Headless Client Auto Detect

Recommended Posts

I've been messing around with elec's Headless Client Auto Detector script that he developed for A2 and trying to get it working for me in A3. It works for the most part, with one caveat, and maybe someone can see what's going wrong. I've stripped down the original script to the bare essentials and the basic concept is:

1) The 'Detector' script is called in the init.sqf for all machines.

2) The script will figure out if there's a headless client and set a variable (elec_hc_connected) to 0. If there is no HC, it will set the server's elec_hc_connected to 0, and all other machines will be set to 1.

3) In any scripts I call (AI spawn/etc) that I want to run on the HC if available, or server, if there is no HC, you put if(elec_stop_exec == 1) exitWith{}; as the first line so it will drop out for everything but the HC, or server if HC isn't connected.

Here's the stripped down script:

elec_stop_exec = 0;
elec_hc_connected = 0;

//Check if switch is set
if (!(isServer) && !(hasInterface)) then {
	elec_hc_connected = 1;
	publicVariable "elec_hc_connected";
} else {
	if (!isServer) then{ 
		elec_stop_exec = 1;
	};
	sleep 3;
if(elec_hc_connected == 0) then { 
		if (!isServer) then{ 
		elec_stop_exec = 1;
		};
	} else {
		if ((isServer) OR (hasInterface)) then{ 
		elec_stop_exec = 1;
		};;
	};
};

What I'm finding is:

1) 'Server' / Game being hosted on a players machine, AI called in scripts spawn correctly.

2) Dedicated Server with a Headless Client connected, AI called in scripts spawn correctly.

3) Dedicated Server, no headless client connected. AI called in scripts never spawn.

Don't know if it's a timing thing, or what, but something isn't working right. Reading through it, I don't see why in situation 3, the server would get the variable set to 1, but I'm not sure. Any thoughts?

---------- Post added at 00:02 ---------- Previous post was at 23:33 ----------

Actually, I think I can strip it down even further. Put the following code in a script that's called for all in init.sqf.

// Headless Client Autodetect v0.1
// By Meatball
// Inspiration/Ideas from elec's HeadelessClient Autodetection Switch script

// In any script you want to run on HC if available, or on server otherwise, make the first line: 
// if(spawnExec != 1) exitWith{};
// This will exit out of the script on any machine that does not have the spawnExec variable set to 1.

// Set the spawnExec variable on all machines to 0.
spawnExec = 0;

// If this is the server and spawnExec has not already been reset by the HC (see below), set spawnExec to 1.
if (isServer and (spawnExec !=2)) then {spawnExec = 1;};

// If this is a dedicated client, transmit spawnExec out to all clients as 2, then reset HC variable to 1.
if (!(isServer) && !(hasInterface)) then {spawnExec = 2;publicVariable "spawnExec";spawnExec = 1;};

Edited by Meatball

Share this post


Link to post
Share on other sites

Wanted to followup on this. The code I have settled on seems to be working in most of my testing, but I'm finding some people telling me that it's not working for setups with just a dedicated server but no Headless Client attached. As in scripts that have the if(spawnExec != 1) exitWith{}; check in them are not running on the dedicated server.

Anyone have any thoughts why that might be the case looking at the script above?

Share this post


Link to post
Share on other sites

I suppose that your HC connects to a civilian slot.

If yes, ask them if their HC is connected to his slot.

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  

×