OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: Blacknite on 29 Aug 2010, 17:42:19

Title: Script not working on dedicated server?
Post by: Blacknite on 29 Aug 2010, 17:42:19
I have some scripts that are executed through the Action Menu from an interactive ai, but it only works from the person that is hosting it (not the people ingame with the host) and it doesnt work on a dedicated server.

Here is an example of one of the scripts I have for it:

Locktruck.sqf
Code: [Select]
if(isServer)then{
VCO removeAction UnLockTruck;
Truck1 lock false;
Truck2 lock false;
Truck3 lock false;
Truck4 lock false;
LockTruck = VCO addAction ["Lock Road Vehicles", "LockTruck.sqf"];
};
if(!isServer)then{
};

UnLockTruck.sqf
Code: [Select]
if(isServer)then{
VCO removeaction LockTruck;
Truck1 lock true;
Truck2 lock true;
Truck3 lock true;
Truck4 lock true;
UnlockTruck = VCO addaction["Unlock Road Vehicles","UnLockTruck.sqf"];
};

if(!isServer)then{
};
VCO being the Interactive AI.
Title: Re: Script not working on dedicated server?
Post by: i0n0s on 29 Aug 2010, 18:53:34
Those actions where only started local. So the isServer part will only run if activated by the hosted player.
Title: Re: Script not working on dedicated server?
Post by: Blacknite on 30 Aug 2010, 01:34:01
How should it be then?
Title: Re: Script not working on dedicated server?
Post by: i0n0s on 30 Aug 2010, 01:44:54
Use a publicVariable to broadcast the action to the server.
Title: Re: Script not working on dedicated server?
Post by: Blacknite on 30 Aug 2010, 04:42:44
Isnt that what "if(isServer) then(" does?
Title: Re: Script not working on dedicated server?
Post by: i0n0s on 30 Aug 2010, 20:20:47
No,
if you select the action, your script will only start on your client. The other clients won't notice it.
isServer only checks if you're the server. This is not the case if you're not the host. So your code will be skipped and not executed.
To execute the command on the server, define a boolean variable, add a PublicVariableEventHandler to the variable via the init file and only on the server.
This handler will execute your code you currently have in your action.
Then you modify the action to toggle the variable and broadcast it via publicVariable.
At the time the server will get the modified variable, he will run your code for the action.

A small downside is left: The handler won't fire if the publicVariable was executed on the same client. See the Biki comment on this. So you need a small modification to make sure that the new code will work on hosted sessions.

And I would recommend to inform yourself about the locality of commands and the effect.
It's important to know these for multiplayer scripting.