6. Send your first Private Message {{ currentPage ? currentPage.title : "" }}

Receive private Messages

1. We will open the Chat Widget from the 2nd Tutorial and Bind the Event PrivateMessageReceived from the Chat Component inside the Function onStart.

Of course we create inside the Create Event Delegate the Function like we did it for MessageReceived, which i call PrivateMessageReceived.

2. Inside this Function we need to do following:

  • First we need to check if this Message was send by the owning Player or if it was send to the owning Player.

    • If it was send by the owning Player we will set the Name Text like this: TO <PlayerName>

    • If it was send to the owning Player we will set the Name Text like this: FROM <PlayerName>

  • Then we can create like in the 2nd Tutorial the Message Widget.

The Colors can be changed however you want.

I put green to see the difference to a normal Message.

Now if we receive a Private Message we will display the Message like this:

  • If the owning Player send it: <Time> TO <PlayerName> <Message>

  • If the owning Player got it: <Time> FROM <PlayerName> <Message>

Send Private Messages

In this Tutorial we will send a Private Message with the Command:

/msg <PlayerName> <Message>

1. First we create a new Command, which can be used by everyone and is replicated to the Client.

2. With PlayerTemplate: Go to your Function SP8_Override_CommandEntered.

Without PlayerTemplate: Go to your Interface Function SP8_CommandEntered.

Add to the switch the Command msg, like we did in the Use Commands Tutorial and do following inside there:

  • First we need to check if the Length of the Input is longer then 1.

    • /msg <Input Index 0 = PlayerName> <Input Index 1 and higher = Message>

  • Then we should save the PlayerName to a Variable and remove it from the Input (The Input should be a seperate Variable)

  • Inside the Input Array should be only the Message left, which we need to change to the Message Text.

    • First we need to call on it the Join String Array to make it to a String and set as Seperator a Space.

    • Then we need to convert it to a text.

  • Now we can call SendPrivateMessage on the Chat Component and set as Player Name our saved String. And of course make our Message Structure.

  • At the end we can call Succeded.

Now you should be able to send a Message to a other Player.

Customize the Message

If you need other Variables, which should be send to other Players on send as well, you can edit the Structure SP8_S_PrivateMessage inside the Directory RPG_Essentials / Chat / Structures.

You can add whatever you want. Just do not delete the Message Variable.

{{{ content }}}