Difference between revisions of "Modding:Modder Guide/APIs/Multiplayer"
< Modding:Modder Guide | APIs
Jump to navigation
Jump to search
Pathoschild (talk | contribs) (move content from Modding:Modder Guide/APIs (only author is Pathoschild)) |
Pathoschild (talk | contribs) (expand) |
||
Line 1: | Line 1: | ||
{{../../header}} | {{../../header}} | ||
− | + | 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#"> | ||
− | + | int animalID = this.Helper.Multiplayer.GetNewID(); | |
− | int | + | var animal = new FarmAnimal("Cow", animalID, ownerID); |
+ | </source> | ||
− | + | ===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
- Get started
- Game fundamentals
- Test & troubleshoot
- Release
- API reference
- Basic SMAPI APIs:
- Advanced SMAPI APIs:
- Specific guides
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
}