Advertisement

Author Topic: Script not working on dedicated server?  (Read 1498 times)

0 Members and 1 Guest are viewing this topic.

Offline Blacknite

  • Members
  • *
  • Chiefs runs the navy!
Script not working on dedicated server?
« 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.

Offline i0n0s

  • Moderator
  • *****
Re: Script not working on dedicated server?
« Reply #1 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.

Offline Blacknite

  • Members
  • *
  • Chiefs runs the navy!
Re: Script not working on dedicated server?
« Reply #2 on: 30 Aug 2010, 01:34:01 »
How should it be then?

Offline i0n0s

  • Moderator
  • *****
Re: Script not working on dedicated server?
« Reply #3 on: 30 Aug 2010, 01:44:54 »
Use a publicVariable to broadcast the action to the server.

Offline Blacknite

  • Members
  • *
  • Chiefs runs the navy!
Re: Script not working on dedicated server?
« Reply #4 on: 30 Aug 2010, 04:42:44 »
Isnt that what "if(isServer) then(" does?

Offline i0n0s

  • Moderator
  • *****
Re: Script not working on dedicated server?
« Reply #5 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.