Jump to content
Tiberius_161

Script only partially works on dedicated server

Recommended Posts

Hi all,

 

I created a conversation script that is activated with an Addaction. Within that script the conversation partner should 1) stop and either 2) sometimes pull a gun or 3) another script fires that spawns enemies around him. It all works fine in single player, and the conversation runs fine on a dedicated server. However number 1, 2 and 3 don't manifest on a dedicated server. I use Engima's script for the civilian population and the addAction code bit is as follows:

[[_this select 0, ["Talk","talk\talk_init.sqf", [true, false]]], "addAction",true,true] call BIS_fnc_MP;

Conversation Script:

_talke = _this select 0; ////NPC who has the addaction
_talker = _this select 1; ////Player who initiates the conversation
_civilianFriendly = (_this select 3) select 0; ////PLACEHOLDER
_elder = (_this select 3) select 1; ////PLACEHOLDER

_enemychance = 8; 
_chance = 0;

_talkciv1 = [];
_talkciv2 = [];

_talkciv1 = postalk1 call BIS_fnc_selectRandom; ////All conversation stored in seperate script, no issues there
_talkciv2 = postalk2 call BIS_fnc_selectRandom; ////All conversation stored in seperate script, no issues there  

sleep 1;
if (_talke distance _talker < 5) then
{
	_talke removeAction 0;
	_chance = random 10;
			
	/////PART WHERE HE SHOULD RANDOMLY PULL A GUN OR TURN SUICIDE BOMBER
	if (_chance > _enemychance) then 
	{
		null = [_talke, _talker] execVM "Talk\Attacks\PersonalAttack.sqf";
		_talker globalChat _talkciv1; //// HE SAYS THE LINE, SO THAT WORKS
	}
	else
	{
		if  (_chance >= 7) then 
		{
			null = [_talke] execVM "Talk\attacks\AttackInit.sqf"; /////PART WHERE ENEMIES SHOULD BE SPAWNED. THEY NEVER DO.
		};
				
		_talke disableAI "move"; /////DOES NOT WORK, HE KEEPS WALKING
		_talker globalChat _talkciv1;
						
		sleep 3;
					
		if (_talke distance _talker <= 5) then 
		{
			_talker globalChat _talkciv2;
			sleep 8;
			_talke enableAI "move";	
		}
		else
		{
			_talke enableAI "move";
		};
	};
};

I have used the AttackInit.sqf in other missions on a dedicated server and it works fine there, so I don't understand why it won't work here. 
Also, I am aware that using execVM is not the best coa for this type of use. I am going to use functions for this. 

 

Does anyone have an idea on what I could try? 

Share this post


Link to post
Share on other sites

The civilian script is running on the server, and since the civs are spawned on server your script running on the player's machine will not be able to control them.

 

You will need to transfer the script execution to the server. 

Share this post


Link to post
Share on other sites

Thnx for the reply. Do you mean that I should run the entire conversation script on the server or only the other scripts? 

Share this post


Link to post
Share on other sites

It depends. For example: is the mission intended to be played by many players, or just a few? And how much of the conversation needs to be known by the server? How much load is in the server?

 

At least the parts controlling the civs must be on the server, and the parts showing text (and playing sounds) must be on the client.

 

Spontaneously I think I would have put as much as possible on the server. If the server is controlling the movement of the civs, shouldn't it also control their speech? Sending text lines to player's screen is easy. You can use script command remoteExec to both start the script on server, and to show text on clients.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Engima, apologies to bother you again with the same problem, but i am still having problems with the script. 

 

I have tried to use remoteExec but I the units won't spawn with the addaction. 

This what I use right now: [_this,["Talk", {"talk\talk_init.sqf"}]] remoteExec ["addAction",0]; 

 

When using the addaction with BIS_fnc_MP method, I managed to get both scripts to run using bis_fnc_mp instead of execVM. 

But the disableAI part still does not work... For that I tried "move" remoteExec ["disableAI", 0, _talke], which works in the editor

Probably because the script still does not run on the server. How can I run the script on the server? 

 

Edited by Tiberius_161

Share this post


Link to post
Share on other sites

Problems solved.

 

Got it working with 

[[_talke,"move"], "disableAI"] call BIS_fnc_MP;

Although script is still not running on the server,all problems are solved so that's good :).   

Share this post


Link to post
Share on other sites

Don't use BIS_fnc_MP.

https://community.bistudio.com/wiki/BIS_fnc_MP

Quote

This function is now provided for backward compatibility only. Please use the engine based commands remoteExec or remoteExecCall instead.

Read and learn the actual syntax of remoteExec, it is pretty simple.

https://community.bistudio.com/wiki/remoteExec

Quote

<params> remoteExec ["fnc_someScriptedFunction", targets, JIP];

[_talke, "MOVE"] remoteExec ["disableAI", 0, FALSE];

Adjust targets parameter accordingly.

Share this post


Link to post
Share on other sites

disableAI is arguments_local.gif  effects_global.gif 

 

You don't have (and avoid) to broadcast that on each client. More or less, this kind of AIs are on server if not in a group led by a player.

So, coming from an addAction (local on player-caller's PC), you just need to remote exec on server:

[_talke, "MOVE"] remoteExec ["disableAI", 2];

But, for whatever reason, if you're unsure with the AI's locality, just:

[_talke, "MOVE"] remoteExec ["disableAI", _talke];

Share this post


Link to post
Share on other sites

Thank you both for your answer :). I have applied the remoteExec. I am going to read up more on the locality subject.

 

Share this post


Link to post
Share on other sites
3 hours ago, Tiberius_161 said:

Thank you both for your answer :). I have applied the remoteExec. I am going to read up more on the locality subject.

 

That's very important for server and clients performances. Starting with MP things, man usually focus on EL or EG. Because it's obvious that EL should be broadcast for "shared" effect on all clients (typically the hint command, if needed). But, it's easy to forget the AL constraint: "have to be local", just thinking the code will work for some shared unit/object. addAction EL is a good case to understand that the caller and the object can be on different PCs, so the code has to be remote on the right PC.

A very good exercise, for MP:

During a mission (spawn instead edit), spawn a rubber boat on a strand (or what you want), and try to make any player can push it (setVelocity) via an addAction.

  • Thanks 1

Share this post


Link to post
Share on other sites

Good example. Most important in MP scripting is:

 

1. Knowing on which machine each units is local, and

2. Knowing which machine is executing each script.

 

Make sure to never loose track of this, and it will save you a lot of headache.

 

Note also that different script commands has global or local effect, and each script command need to be understood in this sense. For example: createVehicle has global effect (a vehicle is created on all machines), while addAction has local effect (only adds the action om the machine running the command).

 

Triggers placed in the editor should be seen as one trigger per connected machine.

  • Thanks 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

×