Difference between revisions of "Modding:Modder Guide/APIs/Multiplayer"

From Stardew Valley Wiki
Jump to navigation Jump to search
(move content from Modding:Modder Guide/APIs (only author is Pathoschild))
 
(expand)
Line 1: Line 1:
 
{{../../header}}
 
{{../../header}}
  
===Multiplayer===
+
The multiplayer API provides methods to support modding in a multiplayer context. This API is still minimal, but much more will be added in later versions of SMAPI.
The multiplayer API provides methods to support modding in a multiplayer context:
+
 
 +
__TOC__
 +
==Methods==
 +
===GetNewID===
 +
In some cases the game expects a 'multiplayer ID' value, which is a unique 64-bit number. This is mainly intended for cases where the game expects a multiplayer ID for data sync, such as when creating farm animals:
 
<source lang="c#">
 
<source lang="c#">
// get a unique multiplayer ID (e.g. for animal IDs)
+
int animalID = this.Helper.Multiplayer.GetNewID();
int uniqueID = this.Helper.Multiplayer.GetNewID();
+
var animal = new FarmAnimal("Cow", animalID, ownerID);
 +
</source>
  
// get the locations being sync'd from the main player
+
===GetActiveLocations===
 +
In multiplayer mode, the game doesn't sync all locations to other players. Each farmhand will receive data for their current location, the farm, farmhouse, and farm buildings. You can get a list of the locations being sync'd:
 +
<source lang="C#">
 
foreach (GameLocation location in this.Helper.Multiplayer.GetActiveLocations())
 
foreach (GameLocation location in this.Helper.Multiplayer.GetActiveLocations())
 +
{
 +
  // do stuff
 +
}
 
</source>
 
</source>

Revision as of 04:50, 28 May 2018

Creating SMAPI mods SMAPI mascot.png


Modding:Index

The multiplayer API provides methods to support modding in a multiplayer context. This API is still minimal, but much more will be added in later versions of SMAPI.

Methods

GetNewID

In some cases the game expects a 'multiplayer ID' value, which is a unique 64-bit number. This is mainly intended for cases where the game expects a multiplayer ID for data sync, such as when creating farm animals:

int animalID = this.Helper.Multiplayer.GetNewID();
var animal = new FarmAnimal("Cow", animalID, ownerID);

GetActiveLocations

In multiplayer mode, the game doesn't sync all locations to other players. Each farmhand will receive data for their current location, the farm, farmhouse, and farm buildings. You can get a list of the locations being sync'd:

foreach (GameLocation location in this.Helper.Multiplayer.GetActiveLocations())
{
   // do stuff
}