Chapter I
Getting Into A Multiplayer Frame of Mind
It is important to realize that multiplayer scripting differs a lot from single player scripting. We first need to get our thought pattern thinking multiplayer.
3DGS multiplayer is set in client/server mode. What this means is that all the clients' actions will actually be done on the server unless you specifically tell a client to do otherwise using commands like proc_local() or ent_createlocal().
Lets look at some examples comparing single player to multiplayer.
Single Player
ent_create(player_mdl, position, move);
action move
{
}
In single player mode, you create your player and the action move is done on your computer.
Multiplayer
client
ent_create(player_mdl, position, move);
server
action move
{
}
In muliplayer mode, a client creates his player and his action move is done on the server.
Not only is the action done on the server, but the player's entity itself is actually created on the server, even though the ent_create() was done on the client. The server actually creates the parent entity and sends clones to all the clients, keeping track of which client created the entity.
This may seem like a subtle difference. But try taking a single player game and converting it to multiplayer and you will quickly learn that it really isn't so subtle after all.
So when trying to get into the multiplayer frame of mind we must remember that the server is doing most of the activities. The clients do some basic things, such as gather input from player and then send that data to the server, which actually does the movement, etc.
It is very important when starting a multiplayer game to distinguish if the player is a host or a client. When starting the game you first use the command line to define what a player is. The host will use the command line -sv -cl, while a client will use the command line -cl.
After the game begins, we can then use 3DGS defined variables such as server, client, and connection to determine whether this player is actually a host or a client. How a multiplayer game starts is always more complex than a single player game.
So lets think multiplayer.