Rocket Networking Docs🚀
  • About this Documentation
  • Basics of Rocket Networking
    • Room based multiplayer (Auto State Sharing)
      • Clients and clientId
      • Entities
      • Smart Entities
    • Single Message Sharing
    • Persistent Objects on the Server
    • Easy Matchmaking
    • Discord Server Integration
    • Database for your Account
    • Server Side Scripting
    • Global Multiplayer(Cross play)
  • Rocket Networking Code
    • Connecting and Disconnecting
      • ConnectToServer()
      • callback_ConnectToServer()
      • DisconnectFromServer()
      • callback_DisconnectFromServer()
    • Rooms
      • ChangeRoom( new_room_name )
      • callback_ChangeRoom()
      • LeaveRoom()
      • callback_LeaveRoom()
      • ShowAllClientsInRoom(room_name ) and callback_ShowAllClientsInRoom()
      • ShowAllRooms() and callback_ShowAllRooms()
    • Private Messaging
      • SendEventToClient
      • callback_ReceivedEvent
      • SendMessageToClient
      • callback_ReceivedMessage
    • Persistent Objects
      • CreatePersistentObject(roomId , persistentObjectStruct)
      • callback_CreatedPersistentObject()
      • EditPersistentObject(persistentObjectId , new_persistentObjectStruct)
      • DestroyPersistentObject(persistentObjectId)
      • ShowPersistentObjectsInRoom(room_name)
      • callback_ShowAllPersistentObjectsInRoom(array_of_persistent_objects)
    • Database Functions
      • SetSimpleData()
      • callback_SetSimpleData()
      • ReadSimpleData()
      • callback_ReadSimpleData()
      • AddToSimpleData()
      • callback_AddToSimpleData()
      • DeleteSimpleData()
    • Discord Integration
      • SendDiscordMessage()
      • callback_DiscordMessageReceived()
    • AI Functions
      • CallSimpleAI
      • callback_CallSimpleAI
      • CallGeneralAI
      • callback_CallGeneralAI
  • KickPlayer(client_id)
  • ViewServerActivity()
    • callback_ViewServerActivity()
  • oBrain - ping and pseudoHost
  • Admin Callbacks
  • API
    • Database
    • AI
  • Server Side Scripting
    • Basics
    • Understand the heirarchy on the server
    • Create a Persistent Object from Server
    • Important Scripts
      • "step" Script format
      • "client_sent_event" Script format
      • "game_server_created" Script format
    • Send Event to a Client from Server
    • Database Functions on Server
    • AI Functions on the Server
Powered by GitBook
On this page
  • Example Implementation of callback
  • More Complex Systems
  1. Rocket Networking Code
  2. Private Messaging

callback_ReceivedMessage

PreviousSendMessageToClientNextPersistent Objects

Last updated 1 year ago

After a successful message send on your server, the callback function callback_ReceivedMessage() is called. So under Scripts/Rocket Networking/Callback Functions , you can edit this to do whatever you want…

Example Implementation of callback

  • In a shooter game, if you hit another player, you want to inform them that their health reduced right?

  • You can send a message called "damage"

  • The receiver can see the message and use the switch statement to reude their player's health by 10 if the message is "damage"


function callback_ReceivedMessage(theMessage , senderClientId){
	switch(theMessage){
		case "damage":
		oPlayer.myHealth -= 10
		if(oPlayer.myHealth <= 0){
			show_message("YOU DIED")
		}
		break;
	}

}

More Complex Systems

As I talked about a switch statement here, you can make a full event based system encoded in the message.

To do that, you can make a struct and stringify it and send it over to the reciever.

var structToSend = {
    eventName : "damage",
    value : 10
}
SendMessageToClient(5 , json_stringify(structToSend))
//this sends a strigified version of that struct to client id 5

On any reciever's screen, you have to reduce the health right? So you can do this in the calback_ReceivedMessage() script


function callback_ReceivedMessage(theMessage , senderClientId){
	var realData = json_parse(theMessage)
	switch(realData.eventName){
		case "damage":
		oPlayer.myHealth -= realData.value
		if(oPlayer.myHealth <= 0){
			show_message("YOU DIED")
		}
		break;
	}

}