6thSense.eu/EG: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
A view on Multiplayer Editing, by [http://community.bistudio.com/wiki/User:Sickboy Sickboy]
A view on Multiplayer Editing, by [http://community.bistudio.com/wiki/User:Sickboy Sickboy]
<br /><br />
<br /><br />
'''Player Object'''<br />
= Player Object(s) =
* Player is indeed a null object on server<br />
* Player is indeed a null object on server<br />
* You can '''not''' verify if an object is a null object by testing: object == objNull because objNull doesn't equal anything, not even itself, you must use: isNull object<br />
* You can '''not''' verify if an object is a null object by testing: object == objNull because objNull doesn't equal anything, not even itself, you must use: isNull object<br />
Line 23: Line 23:
T_Players (array) will contain the current player objects. The list is automaticly cleared of dead players or players who left.<br />If you execute this on every machine:
T_Players (array) will contain the current player objects. The list is automaticly cleared of dead players or players who left.<br />If you execute this on every machine:
<code>{ _x globalChat ("Really, My name is: " + name _x) } forEach T_Players;</code>
<code>{ _x globalChat ("Really, My name is: " + name _x) } forEach T_Players;</code>
Then on every machine it will apear as if all players wrote "Really, My name is: (name)" in globalChat.<br /><br /><br />'''Player/Server/JIP'''<br />The Basics:<br />
Then on every machine it will apear as if all players wrote "Really, My name is: (name)" in globalChat.<br /><br /><br />
= Player/Server/JIP =
The Basics:<br />
* A JIP Player is a player that joins while the mission is already in progress (Join In Progress)
* A JIP Player is a player that joins while the mission is already in progress (Join In Progress)
* What is synchronized at JIP
* What is synchronized at JIP
Line 60: Line 62:
* Client or ServerClient: T_Client<br />
* Client or ServerClient: T_Client<br />
* Client or ServerClient, NOT JIP: T_Client && !T_JIP<br />
* Client or ServerClient, NOT JIP: T_Client && !T_JIP<br />
* JIP Client: T_JIP<br /><br /><br />'''Locallity:'''<br />
* JIP Client: T_JIP<br /><br /><br />
 
= Locallity =
* Players are local to their own machine<br />
* Players are local to their own machine<br />
* AI Are local to the server, unless they are part of a team lead by a player, in that case, that AI is local to the player teamleader machine.<br />
* AI Are local to the server, unless they are part of a team lead by a player, in that case, that AI is local to the player teamleader machine.<br />
Line 74: Line 78:
* Every variable that you 'publicVariabled' will be sent to JIP players. The value of these variables do not equal the current value of the variable, but instead, the value as it was at the moment it was 'publicVariabled'.<br />
* Every variable that you 'publicVariabled' will be sent to JIP players. The value of these variables do not equal the current value of the variable, but instead, the value as it was at the moment it was 'publicVariabled'.<br />
* Every vehicleInit that has been set (object setVehicleInit "blablalba"; processInitCommands), is synchronized to JIP Players<br />
* Every vehicleInit that has been set (object setVehicleInit "blablalba"; processInitCommands), is synchronized to JIP Players<br />
* There is no general rule of thumb available for Join in Progress compatible scripting etc, at least not to my knowledge. Basicly it all depends on what you are making, what the functionality is, and how this relates to Multiplayer. Basicly you have to keep all the above in mind while developing for Join in Progress compatible projects.<br /><br /><br />'''Interesting functions for Multiplayer'''<nowiki>:</nowiki><br />
* There is no general rule of thumb available for Join in Progress compatible scripting etc, at least not to my knowledge. Basicly it all depends on what you are making, what the functionality is, and how this relates to Multiplayer. Basicly you have to keep all the above in mind while developing for Join in Progress compatible projects.<br /><br /><br />
 
= Interesting functions for Multiplayer =
* [http://community.bistudio.com/wiki/publicVariable publicVariable]<br />
* [http://community.bistudio.com/wiki/publicVariable publicVariable]<br />
* [http://community.bistudio.com/wiki/addPublicVariableEventHandler addPublicVariableEventHandler]<br />
* [http://community.bistudio.com/wiki/addPublicVariableEventHandler addPublicVariableEventHandler]<br />

Revision as of 20:07, 23 January 2008

A view on Multiplayer Editing, by Sickboy

Player Object(s)

  • Player is indeed a null object on server
  • You can not verify if an object is a null object by testing: object == objNull because objNull doesn't equal anything, not even itself, you must use: isNull object
  • To test if a certain object is a player, use: isPlayer object
  • player is a variable, just like any other variable. A variable can contain different values. In this case the variable "player" contains an Object.
    The value of the variable "player" is:
    Server: a null object
    Clients: the object (vehicle) that represents the player on this computer
    If there are 3 player slots in game,
    player1 I name: p1
    player2 I name: p2
    player3 I name: p3

    then on p3's computer:
    player == p3
    you can access the other players through the variables: p1 and p2

    on p2's computer:
    player == p2
    and you can access the other players through the variables: p1 and p3
    etc. etc.

  • To get a list of all (connected)player-objects in the mission, which gets updated every 5 seconds:

T_players = []; T_trig = createTrigger ["EmptyDetector",getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition")]; T_trig setTriggerType "NONE"; T_trig setTriggerActivation ["ANY", "PRESENT", true]; T_trig setTriggerArea [30000, 30000, 0, false ]; T_trig setTriggerStatements ["this", "", ""]; private ["_ar"]; while {true} do { _ar = []; { if (isPlayer _x) then { _ar = _ar + [_x] } } forEach (list T_trig); T_players = [] + _ar; sleep 5; }; T_Players (array) will contain the current player objects. The list is automaticly cleared of dead players or players who left.
If you execute this on every machine: { _x globalChat ("Really, My name is: " + name _x) } forEach T_Players; Then on every machine it will apear as if all players wrote "Really, My name is: (name)" in globalChat.


Player/Server/JIP

The Basics:

  • A JIP Player is a player that joins while the mission is already in progress (Join In Progress)
  • What is synchronized at JIP
    • weather
    • time passed since mission start
    • all variables (+values) which were publicVariable'd before (done by publicVariable)
    • vehicleInits (set by setVehicleInit
    • the current gamestate (alive/death, position, status etc)
  • What is not synchronized at JIP
    • time that was artificially changed; by skipTime and setDate
    • if the value was changed of a variable which was publicVariabled earlier on, the earlier value is synchronized, not the current
  • To only run something on dedicated server or serverClient: isServer
  • To only run something on clients, and never on dedicated server or serverClient: !isServer
  • To only run something on clients or server Clients: !(isNull player)

    JIP Script example to figure out what the machine exactly is, in init.sqf or sorts:

T_INIT = false; T_Server = false; T_Client = false; T_JIP = false; if (isServer) then { T_Server = true; if (!(isNull player)) then { T_Client = true }; T_INIT = true; } else { T_Client = true; if (isNull player) then { T_JIP = true; [] spawn { waitUntil { !(isNull player) }; T_INIT = true }; } else { T_INIT = true; }; }; Any script that has to work with the player object will have to wait until T_INIT == true:
waitUntil { T_INIT };

Conditions to use:

  • Dedicated Server: T_Server && !T_Client
  • Dedicated Server or ServerClient: T_Server
  • ClientOnly: T_Client && !T_Server
  • Client or ServerClient: T_Client
  • Client or ServerClient, NOT JIP: T_Client && !T_JIP
  • JIP Client: T_JIP


Locallity

  • Players are local to their own machine
  • AI Are local to the server, unless they are part of a team lead by a player, in that case, that AI is local to the player teamleader machine.
  • Empty Vehicles are local to the server
  • Controlled Vehicles are local to the machine of the driver (incase of AI, this is by default the server, incase of player, this is the player's machine. Again, if the AI is part of a group lead by a player, the vehicle will be local to the player teamleader machine)
  • The locallity of functions is documented in the biki
  • Functions like: Say, sideChat, globalChat, groupChat etc. etc. are executed locally. So if you want to execute them on every computer, you will have to make sure that the script runs on every computer
  • setFuel, setDammage, setSpeed, etc. etc. effects are global, so basicly you can run the script that uses these functions on every machine, but only execute the function there where the vehicle is local, e.g: if (local _veh) then { _veh setDammage 0.5 };
  • Triggers created in editor are global; they exist on all machines, and they run on all machines (conditions checked, onActivation/onDeActivation executed when condition is true etc)
  • Triggers created in scripts are local and only exist/run on the machine where they got created.
  • Most eventHandlers are local. This means that the eventHandler only executes on the machine where the unit who triggered the eventHandler, is local. Some events are global, like getIn, getOut, Fired and Init. A complete list you can find here: http://community.bistudio.com/wiki/Armed_Assault:_EventHandlers_List


    General
  • IMHO best practice would be to keep as much as possible server sided, because this should result in the least complex scripting and least amount of data sending/receiving. Only interface elements should reside on Clients, or functionality that only interacts with the player himself or his machine.
  • Every variable that you 'publicVariabled' will be sent to JIP players. The value of these variables do not equal the current value of the variable, but instead, the value as it was at the moment it was 'publicVariabled'.
  • Every vehicleInit that has been set (object setVehicleInit "blablalba"; processInitCommands), is synchronized to JIP Players
  • There is no general rule of thumb available for Join in Progress compatible scripting etc, at least not to my knowledge. Basicly it all depends on what you are making, what the functionality is, and how this relates to Multiplayer. Basicly you have to keep all the above in mind while developing for Join in Progress compatible projects.


Interesting functions for Multiplayer