//Someone add a brief description of the MAPI and links to it here. -Swept
Precompiled 0MultiplayerAPI.dll
In this section, we're going to focus on the basics of the api. Specifically, we're going to enable a mod for Multiplayer.
By the time RimWorld reaches your mod the API is ready to use, you can call it wherever you see fit. See basic C# mod tutorials. The easiest place is [StaticConstructorOnStartup]
The following is the most basic boilerplate code.
That's all! You are done.
The Multiplayer Compatibility Project
Well… sometimes you aren't that lucky. Sometimes you want to change a specific Field. For those scenarios there is the MP.Watch* methods. Basically, at the beginning of the operation you take a snapshot of the Field value and then compare it later. MPAPI checks them if they need to broadcast it and then spreads the change accordingly.
That's all! So easy! Is it?
Oh dear! Oh deity no no–- NO- Pray you aren't dealing with them with Reflection. See the Examples for dark magic. But if it's your own code, just move the Action delegate to a method anywhere and tag it with [SyncMethod].
Sometimes, when you use [SyncMethod], you will encounter… Error writing type: MyType, ... Multiplayer.Client.SerializationException: No writer for type MyType
MPAPI needs to know how to reference your type to send it to the other clients. Basically if you have…
You need to teach MPApi to handle your types, so they can send them over the wire to the other players. For our example, we will need to write a SyncWorker for MyReturnType, MyArgumentType and MyArgumentType2, most of RimWorld types are already handled so don't be afraid to use them.
Assuming MyReturnType is made of aString, anInt and aFloat, here is how you write a SyncWorker for it:
Bind does the writing and reading for you, shouldConstruct makes it so type is constructed before being passed to the SyncWorker (not needed for structs). But if you need more complex situations, you can use Write and Read.
Assuming MyArgumentType requires an argument Pawn to construct, you'd write it this way:
*Todo migrate the rest of the API doc
https://github.com/Parexy/Multiplayer/wiki/API#mp