Changes

Jump to navigation Jump to search
Line 152: Line 152:     
== Networking ==
 
== Networking ==
To send data to players in multiplayer you first need to call '''ParentMod.RegisterNetworkID'''(id) in a ModBehaviour. The id should be a value between 1-255, it will be used to identify messages to and from your mod, so you should pick a unique number that is unlikely to clash with other mods. When your mod is deactivated, the id will automatically be de-registered and will have to be re-registered to work.
+
To send data to players in multiplayer you first need to call '''ParentMod.RegisterNetworkID'''(id) in a ModBehaviour. The id should be a value between 1-255, it will be used to identify messages to and from your mod, so you should pick a unique number that is unlikely to clash with other mods. When your mod is deactivated, the id will automatically be de-registered and will have to be re-registered to work. Please note that if players don't enable code mods when they host a game, all code mods will be deactivated immediately.
    
To send messages you have to call '''ParentMod.SendNetworkMessage'''(byte[] data, ModBehaviour.MessageTarget target, byte targetID) in your ModBehaviour, where target can be everyone(default), everyone but me(so avoid sending message to self), everyone except(everyone player with targetID), specifically (only player with targetID) and host. For performance reasons, I recommend instantiating a MemoryStream when your mod loads and when you want to send data, call MemoryStream.SetLength(0) to reset its data and then use the extension methods that Software Inc. comes with to write arbitrary data to the stream, finally call MemoryStream.ToArray() to send the data. Please be careful about how much data you send, you should keep the packages as small as possible.
 
To send messages you have to call '''ParentMod.SendNetworkMessage'''(byte[] data, ModBehaviour.MessageTarget target, byte targetID) in your ModBehaviour, where target can be everyone(default), everyone but me(so avoid sending message to self), everyone except(everyone player with targetID), specifically (only player with targetID) and host. For performance reasons, I recommend instantiating a MemoryStream when your mod loads and when you want to send data, call MemoryStream.SetLength(0) to reset its data and then use the extension methods that Software Inc. comes with to write arbitrary data to the stream, finally call MemoryStream.ToArray() to send the data. Please be careful about how much data you send, you should keep the packages as small as possible.

Navigation menu