Modding:SaveGame ModData: Difference between revisions

From Vintage Story Wiki
Marked this version for translation
mNo edit summary
(Marked this version for translation)
Line 2: Line 2:
{{GameVersion|1.15}}
{{GameVersion|1.15}}
<languages/><translate>
<languages/><translate>
<!--T:1-->
Before starting, you should have a development environment set up. If you don't have one already you should read the tutorial [[Setting up your Development Environment]]. Furthermore, we assume that you have a basic understanding of the C# language and Object Oriented Programming. Let's get started!
Before starting, you should have a development environment set up. If you don't have one already you should read the tutorial [[Setting up your Development Environment]]. Furthermore, we assume that you have a basic understanding of the C# language and Object Oriented Programming. Let's get started!


== Introduction ==
== Introduction == <!--T:2-->


<!--T:3-->
VintageStory allows you to set and retrieve custom data to the world's game save as well as individual chunks. The way it works is actually quite simple!
VintageStory allows you to set and retrieve custom data to the world's game save as well as individual chunks. The way it works is actually quite simple!


<!--T:4-->
Custom data is stored as an array of bytes to save space, but we can easily convert any valid C# type to <code>byte[]</code> with a very convenient class in the VintageStory API: [http://apidocs.vintagestory.at/api/Vintagestory.API.Util.SerializerUtil.html <code>SerializerUtil</code>]. This class provides us with two static methods that allow us to quickly <code>Serialize</code> into byte arrays, and <code>Deserialize<T></code> them into other types.
Custom data is stored as an array of bytes to save space, but we can easily convert any valid C# type to <code>byte[]</code> with a very convenient class in the VintageStory API: [http://apidocs.vintagestory.at/api/Vintagestory.API.Util.SerializerUtil.html <code>SerializerUtil</code>]. This class provides us with two static methods that allow us to quickly <code>Serialize</code> into byte arrays, and <code>Deserialize<T></code> them into other types.


<!--T:5-->
You can check out the methods for storing and retrieving these arrays of bytes for [http://apidocs.vintagestory.at/api/Vintagestory.API.Server.IServerChunk.html Chunks] and for [http://apidocs.vintagestory.at/api/Vintagestory.API.Server.ISaveGame.html#methods SaveGame]
You can check out the methods for storing and retrieving these arrays of bytes for [http://apidocs.vintagestory.at/api/Vintagestory.API.Server.IServerChunk.html Chunks] and for [http://apidocs.vintagestory.at/api/Vintagestory.API.Server.ISaveGame.html#methods SaveGame]


== Custom Data in SaveGame ==
== Custom Data in SaveGame == <!--T:6-->


<!--T:7-->
Let us show you this powerful set of tools by making an example mod in which we implement an open list of players currently looking for a group to play with ingame.
Let us show you this powerful set of tools by making an example mod in which we implement an open list of players currently looking for a group to play with ingame.


<!--T:8-->
This list will be a <code>List<string></code> of players which will be stored to the world's <code>SaveGame</code>. Anyone can join it, leave it, or see who needs a group. We'll store this list as an array of bytes, and it can be accessed by the key "lfg".
This list will be a <code>List<string></code> of players which will be stored to the world's <code>SaveGame</code>. Anyone can join it, leave it, or see who needs a group. We'll store this list as an array of bytes, and it can be accessed by the key "lfg".


== Preparation ==
== Preparation == <!--T:9-->


<!--T:10-->
Let's start by creating a new .cs file for this mod, and adding our imports and the <code>VintageStory.ServerMods</code> namespace to wrap our class in. Additionally, we'll declare the class <code>LookingForGroup</code> that will inherit from <code>ModSystem</code> which is the base class for mod systems. You can read more about this [http://apidocs.vintagestory.at/api/Vintagestory.API.Common.ModSystem.html here].
Let's start by creating a new .cs file for this mod, and adding our imports and the <code>VintageStory.ServerMods</code> namespace to wrap our class in. Additionally, we'll declare the class <code>LookingForGroup</code> that will inherit from <code>ModSystem</code> which is the base class for mod systems. You can read more about this [http://apidocs.vintagestory.at/api/Vintagestory.API.Common.ModSystem.html here].
</translate>
</translate>
Confirmedusers
13,514

edits