Jump to content
Deleted

Script in "initServer.sqf" Doesn't Execute in Dedicated Multiplayer Server

Recommended Posts

Good Afternoon All,

I've run into an issue where a script that I've created where the script itself doesn't execute even though it's scripted to in the "initServer.sqf". The script itself works fine and I've tested it extensively in Singleplayer and in my own LAN server, but when I load it up onto my dedicated server it doesn't run unless I specifically call it after the start of the mission.

This script should be executed on the server only and works by calculating the change in damage to the main rotor, evaluates if that change is lower than a specific threshold (here 0.02 to be exact), and if it is lower it will then subtract that damage. This effectively cancels out the "background damage" that's caused by over-torquing the main rotor on the H-60 while still allowing outside damage, like small arms fire, to be applied.

So far, I have tried placing the whole script in the "initServer.sqf" file, creating a separate .SQF file for the script and execVM-ing it through both an "init" box and "initServer.sqf", creating a function in the "initServer.sqf" and calling it, and a myriad of other things including delaying the script's execution until after mission start and so forth. None of my attempts have worked.

I would appreciate any and all input on this matter. Thanks guys.

Here is the script itself:
 

params ["_helicopter", "_Debug_Messages"];

//////////////////////////////////ADDING OVERTORQUE REMOVER

	if (_Debug_Messages == true) then {
	
		hint parseText format ["<t font = 'PuristaBold'>MythScript</t> is now active.<br></br><br></br>Attached to: %1", typeOf _helicopter];
	
	};

	sleep 5;
		
	_lastDamage = 0.02;
		
	_change = 0;
		
	while {alive _helicopter} do {

		if (_Debug_Messages == true) then {
		
			hintSilent parseText format ["Change: %3<br></br><br></br>Current Rotor Damage (raw): %1<br></br><br></br>Current Rotor Damage (corrected): %2", _lastDamage, (round (_lastDamage * 100)), _change];
			
		};
		
		_change = (_helicopter getHitPointDamage "hithrotor") - _lastDamage;
		
		if (_change < 0.02 && _change > 0) then {
		
			_helicopter setHitPointDamage ["hithrotor", ((_helicopter getHitPointDamage "hithrotor") - _change)];
			
		};
		
		_lastDamage = (_helicopter getHitPointDamage "hithrotor");
		
		if (_lastDamage == 0.04) then {
		
			_helicopter setHitPointDamage ["hithrotor",0];
			
		};
		
		sleep 0.5;
		
	};

//////////////////////////////////

 

Share this post


Link to post
Share on other sites
41 minutes ago, Deleted said:

This script should be executed on the server only

 

You will never see the hints - hint and hintSilent are LE. They would need to be remoteExec'd.

 

This won't work at all if you are just pasting it into initServer.sqf, as you aren't passing any params to it - "_helicopter" and "_Debug_Messages" will be undefined. How are you calling it in SP? How are you calling it when you try your other methods?

 

  • Like 1

Share this post


Link to post
Share on other sites

The script is running on your dedicated server but it does'nt work as intended because you did not pay attention to locality.

Multiplayer scripting is very different to Singleplayer scripting because on each line of your script you have to ask on which machine that command has to be executed.

 

Basically 2 commands of your script do not work as intended:

 

1. your hint command gets executed on server only and therefore its string will only get shown on server.

2. the command setHitPointDamage is executed on server as well but its arguments have to be local on the machine where this command gets executed to take any effect. But the argument _helicopter is local on the machine of the pilot player who is flying it. Therefore the whole command has to get executed on that machine.

 

How to get those commands executed where they have to get executed?

The command you need to learn is remoteExec

 

How to know which command needs such "remote execution"?

Every command on the top of its biki page has some icons like "AL" or "EL". Those icons show you if the effects of this command are local to the machine where it is executed like with the hint command or if the arguments of the command have to be local on the machine where it gets executed loke with the setHitPointDamage command.  

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, Harzach said:

 

You will never see the hints - hint and hintSilent are LE. They would need to be remoteExec'd.

 

This won't work at all if you are just pasting it into initServer.sqf, as you aren't passing any params to it - "_helicopter" and "_Debug_Messages" will be undefined. How are you calling it in SP? How are you calling it when you try your other methods? 

 


I apologize for my explanation, as it does leave a ton of questions from the start. For the past few times that I've tried it, I've set it up in two ways to test two approaches at once.

1.) In the helicopter's init box I typed in:

if (!isServer) exitWith {};

[this, true] execVM "Scripts\H60Setup.sqf";

2.) Additionally, I assigned a global variable to the helicopter in the 3DEN editor and called it "testHelicopter", and then execVM-ed the script through the "initServer.sqf" like this:

[testHelicopter, true] execVM "Scripts\H60Setup.sqf";

 

Share this post


Link to post
Share on other sites
15 minutes ago, sarogahtyp said:

The script is running on your dedicated server but it does'nt work as intended because you did not pay attention to locality.

Multiplayer scripting is very different to Singleplayer scripting because on each line of your script you have to ask on which machine that command has to be executed.

 

Basically 2 commands of your script do not work as intended:

 

1. your hint command gets executed on server only and therefore its string will only get shown on server.

2. the command setHitPointDamage is executed on server as well but its arguments have to be local on the machine where this command gets executed to take any effect. But the argument _helicopter is local on the machine of the pilot player who is flying it. Therefore the whole command has to get executed on that machine.

 

How to get those commands executed where they have to get executed?

The command you need to learn is remoteExec

 

How to know which command needs such "remote execution"?

Every command on the top of its biki page has some icons like "AL" or "EL". Those icons show you if the effects of this command are local to the machine where it is executed like with the hint command or if the arguments of the command have to be local on the machine where it gets executed loke with the setHitPointDamage command.  


I see. That makes sense, thank you very much. I suppose I should revisit the BI Wiki to evaluate which commands are local and which are global.

So from what I understand from your comments, should I place something like this in the helicopter's init box?
 

if (!isServer) exitWith {};

[[HelicopterVarName, true], "Scripts\H60Setup.sqf"] remoteExec ["execVM", 0];

 

Share this post


Link to post
Share on other sites
Just now, Deleted said:


I see. That makes sense, thank you very much. I suppose I should revisit the BI Wiki to evaluate which commands are local and which are global.

So from what I understand from your comments, should I place something like this in the helicopter's init box?
 


if (!isServer) exitWith {};

[[HelicopterVarName, true], "Scripts\H60Setup.sqf"] remoteExec ["execVM", 0];

 

No this would execute the script on each machine which is exactly the opposite of what the first line (if (!isServer ...) does.

You have to use remoteExec within your scipt on the 2 commands I mentioned.

hint has to get executed on each client and not on server. use -2 as the target parameter on remoteExec for this.

setHitPointDamage has to get executed where _helicopter is local. therefore u use _helicopter as target parameter of remoteExec

Share this post


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

No this would execute the script on each machine which is exactly the opposite of what the first line (if (!isServer ...) does.

You have to use remoteExec within your scipt on the 2 commands I mentioned.

hint has to get executed on each client and not on server. use -2 as the target parameter on remoteExec for this.

setHitPointDamage has to get executed where _helicopter is local. therefore u use _helicopter as target parameter of remoteExec

 

I followed your instructions and it works well! Thank you very much for your help sir, as well as your explanations!

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Deleted said:

...and I've tested it extensively in Singleplayer and in my own LAN server

Just here to say the reason it worked in both of these contexts and not on dedicated server is because in the above, both contexts are simultaneously server and player. But for dedicated server you are just player

  • 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

×