Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Put this in your scriptInit
- //Replace 4 digit number with a unique number
- //Replace MethodName with the name of a void Method (example below)
- MyAPIGateway.Multiplayer.RegisterMessageHandler(4123, MethodName);
- ///////////////////////////////////////////////////////////////
- void MethodName(byte[] data){
- string receivedData = MyAPIGateway.Utilities.SerializeFromBinary<string>(data);
- //Do Stuff For Client or Server (split string like you would customdata if needed)
- }
- ///////////////////////////////////////////////////////////////
- //This serializes the string data you want to send
- var sendData = MyAPIGateway.Utilities.SerializeToBinary<string>("Some String You Want To Send");
- //This sends the data to a specific player using their SteamId
- bool sendPlayer = MyAPIGateway.Multiplayer.SendMessageTo(4123, sendData, factionPlayer.SteamUserId);
- //This sends to the server only
- bool sendServer = MyAPIGateway.Multiplayer.SendMessageToServer(4123, sendData);
- ///////////////////////////////////////////////////////////////
- //Must unregister your network message handler, otherwise they will stack between game loads
- protected override void UnloadData(){
- MyAPIGateway.Multiplayer.UnregisterMessageHandler(4123, MethodName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement