Thought I write this little post to summarise basic MP knowledge, as I have noticed the actual mechanism of mission delivery is not quite clear for beginners. Here is the link to find all related posts to Multiplayer Coding.
An MP game is a relationship between server, which is central coordinating body, and clients, which are mainly players, with exception of headless client or when 1 player hosts the game and acts as a server. In any case the loading of the game is identical:
Server
- Could be player hosted or dedicated
- Starts first
- Reads mission from MPMissons folder on the server machine
- Runs the mission
- Executes mission scripts
Client 1
- Connects to the server
- Downloads copy of the mission from the server
- Runs downloaded mission copy
- Executes mission scripts
Headless client 1
- Connects to the server
- Downloads copy of the mission from the server
- Runs downloaded mission copy
- Executes mission scripts
Client 2
- Connects to the server
- Downloads copy of the mission from the server
- Runs downloaded mission copy
- Executes mission scripts
…
Client 101
- Connects to the server
- Downloads copy of the mission from the server
- Runs downloaded mission copy
- Executes mission scripts
As you can see, while server runs mission from local folder, any client that connects to the server, downloads copy of the mission from the server. This way all connected clients including the server have the same mission and execute the same mission scripts. This means that a mission script will be executed once on the server, once on the 1st client, once on the 2nd client, once on the… etc. Sometimes it is necessary to run scripts on every connected machine, sometimes it is necessary to run it on only specific machine, like server only or headless client only, or on any player client but not headless client, etc. The following commands are used to recognise the machine on which script runs:
- isServer – to detect a server
- isDedicated – to detect dedicated server
- hasInterface – to detect headless client
Here is the table with values of these commands on different machines:
Dedicated Server | Hosting Client | Headless Client | Player Client | Single Player | |
isServer | true | true | false | false | true |
isDedicated | true | false | false | false | false |
hasInterface | false | true | false | true | true |
In order to control code execution, one can use if then construct. If true, then run the code, if false, then ignore it. Here are some examples of conditions to be used depending on task at hand:
Enjoy,
KK